]> git.ipfire.org Git - people/stevee/network.git/blobdiff - src/header-zone
zone: Allow creating configs which do not require arguments
[people/stevee/network.git] / src / header-zone
index eaebd1b684f512daabaffce5e06c4e107cdf9dcc..9a25c0ebab4a854cb16b58d70a74b9da7b2f3fe8 100644 (file)
@@ -23,22 +23,28 @@ function hook_info() {
        echo "HOOK=\"${HOOK}\""
 }
 
-function hook_create() {
+function hook_hotplug() {
+       # If the hook does not handle the hotplug event, it
+       # must return EXIT_NOT_HANDLED.
+       exit ${EXIT_NOT_HANDLED}
+}
+
+function hook_new() {
        local zone="${1}"
        assert isset zone
        shift
 
-       config_read $(zone_dir ${zone})/settings
+       zone_settings_read "${zone}"
 
        hook_parse_cmdline $@
 
-       config_write $(zone_dir ${zone})/settings ${HOOK_SETTINGS}
+       zone_settings_write "${zone}"
 
        exit ${EXIT_OK}
 }
 
 function hook_edit() {
-       hook_create $@
+       hook_new $@
 }
 
 function hook_remove() {
@@ -69,17 +75,6 @@ function hook_discover() {
        exit ${DISCOVER_NOT_SUPPORTED}
 }
 
-# The default help function.
-function hook_help() {
-       # If no man page has been configured, we print an error message.
-       if [ -z "${HOOK_MANPAGE}" ]; then
-               error "There is no help available for hook '${HOOK}'. Exiting."
-               exit ${EXIT_ERROR}
-       fi
-
-       cli_show_man ${HOOK_MANPAGE}
-}
-
 # Do nothing
 function hook_parse_cmdline() {
        return ${EXIT_OK}
@@ -107,7 +102,11 @@ function hook_port() {
        exit ${ret}
 }
 
-function hook_port_add() {
+function hook_port_attach() {
+       return ${EXIT_NOT_SUPPORTED}
+}
+
+function hook_port_detach() {
        return ${EXIT_NOT_SUPPORTED}
 }
 
@@ -115,16 +114,34 @@ function hook_port_edit() {
        return ${EXIT_NOT_SUPPORTED}
 }
 
-function hook_port_remove() {
+function hook_port_status() {
        return ${EXIT_NOT_SUPPORTED}
 }
 
-function hook_port_show() {
-       cmd_not_implemented
+function hook_default_port_create() {
+       assert [ $# -ge 2 ]
+
+       local zone="${1}"
+       local port="${2}"
+
+       port_create "${port}"
 }
 
-function hook_port_status() {
-       return ${EXIT_NOT_SUPPORTED}
+function hook_port_create() {
+       hook_default_port_create $@
+}
+
+function hook_default_port_remove() {
+       assert [ $# -ge 2 ]
+
+       local zone="${1}"
+       local port="${2}"
+
+       port_remove "${port}"
+}
+
+function hook_port_remove() {
+       hook_default_port_remove $@
 }
 
 function hook_port_up() {
@@ -174,41 +191,26 @@ function hook_config_cmd() {
                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
-
-       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
+       assert [ $# -ge 2 ]
 
-       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() {