]> git.ipfire.org Git - people/stevee/network.git/commitdiff
Rectify config creation
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 28 Sep 2014 15:12:47 +0000 (17:12 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 28 Sep 2014 15:12:47 +0000 (17:12 +0200)
src/functions/functions.hook
src/functions/functions.settings
src/functions/functions.zone
src/header-zone
src/hooks/configs/ipv4-static

index 20a713231053e5f1566072e8a43bff5fe963b58d..0434f9fa9764824af146a4539a97e657dc918437 100644 (file)
@@ -19,7 +19,7 @@
 #                                                                             #
 ###############################################################################
 
-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"
@@ -125,6 +125,22 @@ function hook_exec() {
        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}
 
@@ -141,61 +157,22 @@ function hook_zone_exists() {
        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
 }
index 52e519b9649aa2cc85ac700cd4432580ce4512e7..ff1e9ebff1d799f79a2aa8cb0907a7035a22a35b 100644 (file)
@@ -155,8 +155,8 @@ function settings_print() {
 function settings_check() {
        # If there is a function defined that is called __check
        # we call that function
-       if [ -n "$(type -t _check)" ]; then
-               _check || return $?
+       if [ -n "$(type -t hook_check)" ]; then
+               hook_check || return $?
        fi
 
        return ${EXIT_OK}
index 491949829925751c3fbea9e318d3bad913a26504..65296acf26237f8eb16f53cadaa4c76ff263733c 100644 (file)
@@ -530,68 +530,60 @@ function zone_has_port() {
        [ -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() {
@@ -723,43 +715,42 @@ function zone_ports_status() {
        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() {
@@ -797,11 +788,7 @@ function zone_get_supported_port_hooks() {
 }
 
 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() {
index b5ab3704b070c98829468341d65d98c63f5a0aa0..2120377d5aa23f9049d8426846de830ba3c26e3d 100644 (file)
@@ -174,41 +174,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
+       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() {
index 9f9b3de38ca75c5ad0fca306425a2f25c939447a..ceec9fe72f314a2ea9b4fc484fdd9b1f412644d0 100644 (file)
@@ -34,7 +34,8 @@ function hook_check() {
 }
 
 function hook_create() {
-       local zone=${1}
+       local zone="${1}"
+       assert isset zone
        shift
 
        while [ $# -gt 0 ]; do