assert isset zone
shift
- zone_settings_read "${zone}"
+ local ${HOOK_SETTINGS[*]}
- hook_parse_cmdline $@
+ # Import all default variables
+ hook_set_defaults
- zone_settings_write "${zone}"
+ if ! hook_parse_cmdline "$@"; then
+ return ${EXIT_ERROR}
+ fi
+
+ if ! zone_settings_write "${zone}"; then
+ log ERROR "Could not write settings for zone ${zone}"
+ return ${EXIT_ERROR}
+ fi
exit ${EXIT_OK}
}
hook_edit() {
- hook_new $@
+ local zone="${1}"
+ assert isset zone
+ shift
+
+ if ! zone_settings_read "${zone}"; then
+ log ERROR "Could not read settings for zone ${zone}"
+ return ${EXIT_ERROR}
+ fi
+
+ if ! hook_parse_cmdline "$@"; then
+ return ${EXIT_ERROR}
+ fi
+
+ if ! zone_settings_write "${zone}"; then
+ log ERROR "Could not write settings for zone ${zone}"
+ return ${EXIT_ERROR}
+ fi
+
+ exit ${EXIT_OK}
+
}
hook_remove() {
local ret
case "${action}" in
add|create|edit|rem|show)
- hook_port_${action} "${zone}" $@
+ hook_port_${action} "${zone}" "$@"
ret=$?
;;
*)
}
hook_port_create() {
- hook_default_port_create $@
+ hook_default_port_create "$@"
}
hook_default_port_remove() {
}
hook_port_remove() {
- hook_default_port_remove $@
+ hook_default_port_remove "$@"
}
hook_port_up() {
local ret
case "${action}" in
- create|edit|rem|show)
+ new|destroy|edit|show)
hook_config_${action} "${zone}" "$@"
exit $?
;;
hook_config_exec "${hook_config}" "${cmd}" "${zone}" "$@"
}
-hook_config_create() {
+hook_config_new() {
assert [ $# -ge 2 ]
- hook_config_cmd "create" "$@"
+ hook_config_cmd "new" "$@"
}
-hook_config_edit() {
- hook_config_cmd "edit" "$@"
+hook_config_destroy() {
+ assert [ $# -eq 2 ]
+ local zone=${1}
+ # The id must be the id and not the hid.
+ local id=${2}
+
+ shift 2
+
+ # Check if we get a valid id
+ if ! zone_config_id_is_valid ${zone} ${id}; then
+ log ERROR "ID: ${id} is not a valid id for zone ${zone}"
+ fi
+
+ local hook=$(zone_config_get_hook_from_id ${zone} ${id})
+ assert isset hook
+
+ # First we bring the hook down
+ hook_config_cmd "down" "${zone}" "${hook}" "${hook}.${id}"
+
+ # If a hook_destroy function is implemented in the hook this function will be executed.
+ # If not a empty defined in header-config is executed.
+ if ! hook_config_cmd "destroy" "${zone}" "${hook}" "${hook}.${id}" "$@"; then
+
+ # A better error message should printed inside the hook.
+ # We will not bring the config up because we do not know if it is safe or if some parts are already destroyed.
+ log ERROR "Could not destroy config with the follwoing id: ${id}"
+ return ${EXIT_ERROR}
+ fi
+
+ # Now we delete the config of the zone
+ zone_config_settings_destroy "${zone}" "${hook}.${id}"
}
-hook_config_remove() {
- hook_config_cmd "remove" "$@"
+hook_config_edit() {
+ assert [ $# -ge 2 ]
+ local zone=${1}
+ # The id must be the id and not the hid.
+ local id=${2}
+
+ shift 2
+
+ # Check if we get a valid id
+ if ! zone_config_id_is_valid ${zone} ${id}; then
+ log ERROR "ID: ${id} is not a valid id for zone ${zone}"
+ fi
+
+ local hook=$(zone_config_get_hook_from_id ${zone} ${id})
+ assert isset hook
+
+ hook_config_cmd "edit" "${zone}" "${hook}" "${hook}.${id}" "$@"
}
hook_config_show() {