# #
###############################################################################
-HOOK_COMMANDS_CONFIG="hook_create hook_down hook_status hook_up"
+HOOK_COMMANDS_CONFIG="hook_create hook_down hook_status hook_remove hook_up"
HOOK_COMMANDS_PORT="hook_create hook_down hook_edit hook_hotplug \
hook_hotplug_rename hook_info hook_status hook_up"
return ${ret}
}
+function hook_list() {
+ local type="${1}"
+
+ local dir="$(hook_dir "${type}")"
+ assert isset dir
+
+ local hook
+ for hook in ${dir}/*; do
+ hook="$(basename "${hook}")"
+
+ if hook_exists "${type}" "${hook}"; then
+ echo "${hook}"
+ fi
+ done
+}
+
function config_get_hook() {
local config=${1}
hook_exists zone $@
}
-function hook_zone_config_exists() {
- local hook_zone=${1}
- local hook_config=${2}
-
- hook_exists zone "${hook_zone}.configs/${hook_config}"
-}
-
-function hook_zone_has_configs() {
- local hook=${1}
-
- [ -d "${NETWORK_HOOKS_DIR_ZONES}/${hook}.configs" ]
-}
-
function hook_zone_exec() {
hook_exec zone $@
}
-function hook_zone_config_exec() {
- local hook_zone=${1}
- local hook_port=${2}
- shift 2
-
- hook_zone_exec "${hook_zone}.configs/${hook_port}" $@
-}
-
function hook_zone_get_all() {
- local type=${1}
-
- local hook
- for hook in $(hook_dir zone)/*; do
- hook=$(basename ${hook})
- hook_zone_exists ${hook} && echo "${hook}"
- done
+ hook_list zone
}
-function hook_zone_configs_get_all() {
- local hook=${1}
-
- if ! hook_exists zone ${hook}; then
- error "Hook '${hook}' does not exist."
- return ${EXIT_ERROR}
- fi
-
- # If the zone hook has got no configurations we exit silently
- if ! hook_zone_has_configs ${hook}; then
- return ${EXIT_OK}
- fi
+function hook_config_exists() {
+ hook_exists config $@
+}
- local h
- for h in $(hook_dir zone)/${hook}.configs/*; do
- h=$(basename ${h})
- if hook_zone_config_exists ${hook} ${h}; then
- echo "${h}"
- fi
- done
+function hook_config_exec() {
+ hook_exec config $@
+}
- return ${EXIT_OK}
+function hook_config_get_all() {
+ hook_list config
}
[ -e "$(zone_dir ${zone})/ports/${port}" ]
}
-# XXX overwritten some lines below
function zone_config() {
- local zone=${1}
- shift
-
- if ! zone_exists ${zone}; then
- error "Zone '${zone}' does not exist."
- return ${EXIT_ERROR}
- fi
-
- local hook=$(config_get_hook $(zone_dir ${zone})/settings)
-
- if [ -z "${hook}" ]; then
- error "Config file did not provide any hook."
- return ${EXIT_ERROR}
- fi
-
- if ! hook_zone_exists ${hook}; then
- error "Hook '${hook}' does not exist."
- return ${EXIT_ERROR}
- fi
-
- hook_zone_exec ${hook} config ${zone} $@
-}
-
-function zone_config() {
- local zone=${1}
- local action=${2}
+ local zone="${1}"
+ local cmd="${2}"
shift 2
assert isset zone
- assert isset action
- assert zone_exists ${zone}
+ assert isset cmd
+ assert zone_exists "${zone}"
- # Aliases
- case "${action}" in
- del|delete|remove)
- action="rem"
+ case "${cmd}" in
+ create)
+ zone_config_create "${zone}" "$@"
;;
- esac
-
- case "${action}" in
- create|edit|rem)
- zone_config_${action} ${zone} $@
+ edit)
+ zone_config_edit "${zone}" "$@"
+ ;;
+ remove)
+ zone_config_remove "${zone}" "$@"
;;
*)
- error "Unrecognized argument: ${action}"
+ error "Unrecognized argument: ${cmd}"
cli_usage root-zone-config-subcommands
exit ${EXIT_ERROR}
;;
esac
}
-function zone_config_create() {
- local zone="${1}"
- assert isset zone
- shift
+function zone_config_cmd() {
+ assert [ $# -gt 2 ]
- local hook=$(zone_get_hook "${zone}")
+ local cmd="${1}"
+ local zone="${2}"
+ shift 2
+
+ local hook="$(zone_get_hook "${zone}")"
assert isset hook
- hook_zone_exec "${hook}" "config_create" "${zone}" "$@"
+ hook_zone_exec "${hook}" "config_${cmd}" "${zone}" "$@"
+}
+
+function zone_config_create() {
+ zone_config_cmd "create" "$@"
+}
+
+function zone_config_edit() {
+ zone_config_cmd "edit" "$@"
+}
+
+function zone_config_remove() {
+ zone_config_cmd "remove" "$@"
+}
+
+function zone_config_show() {
+ zone_config_cmd "show" "$@"
}
function zone_show() {
zone_ports_cmd port_status $@
}
-function zone_configs_list() {
- local zone=${1}
-
- local config
- for config in $(zone_dir ${zone})/configs/*; do
- [ -e "${config}" ] || continue
-
- basename ${config}
- done
-}
-
function zone_configs_cmd() {
- local cmd=${1}
- local zone=${2}
+ assert [ $# -gt 2 ]
+
+ local cmd="${1}"
+ local zone="${2}"
shift 2
- local hook_zone=$(config_get_hook $(zone_dir ${zone})/settings)
+ assert zone_exists "${zone}"
- local hook_config
local config
- for config in $(zone_configs_list ${zone}); do
- hook_config=$(config_get_hook $(zone_dir ${zone})/configs/${config})
-
- hook_zone_config_exec ${hook_zone} ${hook_config} ${cmd} ${zone} ${config} $@
+ for config in $(zone_get_configs "${zone}"); do
+ hook_config_exec "${config}" "${cmd}" "${zone}" $@
done
}
function zone_configs_up() {
- zone_configs_cmd up $@
+ zone_configs_cmd "up" $@
}
function zone_configs_down() {
- zone_configs_cmd down $@
+ zone_configs_cmd "down" $@
}
function zone_configs_status() {
- zone_configs_cmd config_status $@
+ zone_configs_cmd "status" $@
+}
+
+function zone_configs_list() {
+ local zone=${1}
+
+ local config
+ for config in $(zone_dir ${zone})/configs/*; do
+ [ -e "${config}" ] || continue
+
+ basename ${config}
+ done
}
function zone_has_ip() {
}
function zone_get_supported_config_hooks() {
- local zone=${1}
-
- local hook=$(zone_get_hook ${zone})
-
- hook_zone_configs_get_all ${hook}
+ hook_config_get_all
}
function zone_file() {
exit ${EXIT_ERROR}
fi
- if ! hook_config_exists "${hook_zone}" "${hook_config}"; then
- log ERROR "Hook '${hook_config}' is not supported for zone '${zone}'."
- exit ${EXIT_ERROR}
- fi
+ #if ! hook_config_exists "${hook_zone}" "${hook_config}"; then
+ # log ERROR "Hook '${hook_config}' is not supported for zone '${zone}'."
+ # exit ${EXIT_ERROR}
+ #fi
- hook_zone_config_exec "${hook_zone}" "${hook_config}" "${cmd}" "${zone}" "$@"
+ hook_config_exec "${hook_config}" "${cmd}" "${zone}" "$@"
}
function hook_config_create() {
- local zone="${1}"
- assert isset zone
-
- local hook_config="${2}"
- assert isset hook_config
-
- shift 2
+ assert [ $# -gt 2 ]
- if ! listmatch "${hook_config}" $(zone_get_supported_config_hooks ${zone}); then
- log ERROR "Zone '${zone}' does not support configuration of type '${hook_config}'."
- exit ${EXIT_ERROR}
- fi
-
- local hook_zone="$(zone_get_hook "${zone}")"
- assert isset hook_zone
-
- hook_zone_config_exec "${hook_zone}" "${hook_config}" create "${zone}" "$@"
- exit $?
+ hook_config_cmd "create" "$@"
}
function hook_config_edit() {
- hook_config_cmd edit "$@"
+ hook_config_cmd "edit" "$@"
}
function hook_config_remove() {
- cmd_not_implemented
+ hook_config_cmd "remove" "$@"
}
function hook_config_show() {