###############################################################################
function settings_read() {
- local file=${1}
+ local file="${1}"
assert isset file
shift
- local valid_keys=$@
+ local valid_keys
+ local ignore_superfluous_settings="false"
+
+ local arg
+ while read -r arg; do
+ case "${arg}" in
+ --ignore-superfluous-settings)
+ ignore_superfluous_settings="true"
+ ;;
+ *)
+ list_append valid_keys "${arg}"
+ ;;
+ esac
+ done <<< "$(args $@)"
+
+ if [ -d "${file}" ]; then
+ error "Not a configuration file: '${file}'"
+ return ${EXIT_ERROR}
+ fi
# Exit if the file cannot be read.
[ -r "${file}" ] || return ${EXIT_ERROR}
# If valid keys is set, key must be in the list.
if [ -n "${valid_keys}" ]; then
if ! listmatch ${key} ${valid_keys}; then
- log DEBUG "Ignoring configuration setting: ${key}"
+ if ! enabled ignore_superfluous_settings; then
+ log DEBUG "Ignoring configuration setting: ${key}"
+ fi
+
continue
fi
fi
return ${EXIT_ERROR}
fi
- local hook=$(config_get_hook $(zone_dir ${zone})/settings)
-
+ local hook="$(zone_get_hook "${zone}")"
if [ -z "${hook}" ]; then
error "Config file did not provide any hook."
return ${EXIT_ERROR}
return ${EXIT_ERROR}
fi
- local hook=$(config_get_hook $(zone_dir ${zone})/settings)
-
+ local hook="$(zone_get_hook "${zone}")"
if [ -z "${hook}" ]; then
error "Config file did not provide any hook."
return ${EXIT_ERROR}
return ${EXIT_ERROR}
fi
- local hook=$(config_get_hook $(zone_dir ${zone})/settings)
-
+ local hook="$(zone_get_hook "${zone}")"
if [ -z "${hook}" ]; then
error "Config file did not provide any hook."
return ${EXIT_ERROR}
}
function zone_status() {
- local zone=${1}
+ local zone="${1}"
+ assert isset zone
shift
- if ! zone_exists ${zone}; then
+ if ! zone_exists "${zone}"; then
error "Zone '${zone}' does not exist."
return ${EXIT_ERROR}
fi
- local hook=$(config_get_hook $(zone_dir ${zone})/settings)
-
+ local hook="$(zone_get_hook "${zone}")"
if [ -z "${hook}" ]; then
error "Config file did not provide any hook."
return ${EXIT_ERROR}
fi
- if ! hook_zone_exists ${hook}; then
+ if ! hook_zone_exists "${hook}"; then
error "Hook '${hook}' does not exist."
return ${EXIT_ERROR}
fi
- hook_zone_exec ${hook} status ${zone} $@
+ hook_zone_exec "${hook}" "status" "${zone}" "$@"
# Show that the zone it to be removed soon.
if zone_has_remove_tag ${zone}; then
}
function zone_configs_cmd() {
- assert [ $# -gt 2 ]
+ assert [ $# -ge 2 ]
local cmd="${1}"
local zone="${2}"
assert zone_exists "${zone}"
local config
- for config in $(zone_get_configs "${zone}"); do
- hook_config_exec "${config}" "${cmd}" "${zone}" $@
+ for config in $(zone_configs_list "${zone}"); do
+ local config_hook="$(zone_config_get_hook "${zone}" "${config}")"
+ assert isset config_hook
+
+ hook_config_exec "${config_hook}" "${cmd}" "${zone}" "${config}" $@
done
}
done
}
+function zone_config_get_hook() {
+ assert [ $# -eq 2 ]
+
+ local zone="${1}"
+ assert isset zone
+
+ local config="${2}"
+ assert isset config
+
+ local HOOK
+ zone_config_settings_read "${zone}" "${config}" \
+ --ignore-superfluous-settings HOOK
+
+ print "${HOOK}"
+}
+
function zone_has_ip() {
device_has_ip $@
}