]> git.ipfire.org Git - people/ms/network.git/blobdiff - src/functions/functions.zone
Always destroy zones immediately
[people/ms/network.git] / src / functions / functions.zone
index 3e48cb6d91cbe184a483edc1b1bc75d105bced66..b79127a2106e78ca8e57d412877f77604fab3b54 100644 (file)
@@ -244,7 +244,7 @@ zone_new() {
        # Maybe the zone new hook did not exit correctly.
        # If this is the case we remove the created zone immediately.
        if [ "${ret}" != "${EXIT_OK}" ]; then
-               zone_destroy_now "${zone}"
+               zone_destroy "${zone}"
                return ${EXIT_ERROR}
        fi
 
@@ -264,12 +264,6 @@ zone_edit() {
                return ${EXIT_ERROR}
        fi
 
-       # Check if the zone is tagged for removal.
-       if zone_has_destroy_tag ${zone}; then
-               error "You cannot edit a zone that is tagged for removal."
-               return ${EXIT_ERROR}
-       fi
-
        local hook="$(zone_get_hook "${zone}")"
        if [ -z "${hook}" ]; then
                error "Config file did not provide any hook."
@@ -291,7 +285,6 @@ zone_rename() {
        local name="${2}"
 
        assert zone_exists "${zone}"
-       assert not zone_has_destroy_tag "${zone}"
        assert not zone_exists "${name}"
 
        # The zone must be shut down before, is then renamed and
@@ -327,34 +320,19 @@ zone_rename() {
 
 zone_destroy() {
        local zone="${1}"
-       assert zone_exists "${zone}"
-
-       # Make the zone for removal.
-       touch "$(zone_dir "${zone}")/.destroy"
-
-       log INFO "Zone '${zone}' has been tagged for removal."
-}
-
-zone_has_destroy_tag() {
-       local zone="${1}"
-       assert zone_exists "${zone}"
 
-       [ -e "$(zone_dir "${zone}")/.destroy" ]
-}
-
-# This function will remove the given zone
-# RIGHT NOW. Use zone_destroy to remove it
-# at the next status change.
-zone_destroy_now() {
-       local zone="${1}"
-       assert zone_exists "${zone}"
+       # Cannot delete a zone that does not exist
+       if ! zone_exists "${zone}"; then
+               log ERROR "Zone ${zone} does not exist"
+               return ${EXIT_ERROR}
+       fi
 
-       log INFO "Removing zone '${zone}' right now."
+       log INFO "Destroying zone ${zone}"
 
        # Force the zone down.
        zone_is_active "${zone}" && zone_stop "${zone}"
 
-       # Disable zone.
+       # Disable zone auto-start
        zone_disable "${zone}"
 
        rm -rf "$(zone_dir "${zone}")"
@@ -369,12 +347,6 @@ zone_up() {
                return ${EXIT_ERROR}
        fi
 
-       # Check if a zone has got the remove tag.
-       if zone_has_destroy_tag ${zone}; then
-               error "Cannot bring up any zone which is to be removed."
-               return ${EXIT_ERROR}
-       fi
-
        local hook="$(zone_get_hook "${zone}")"
        if [ -z "${hook}" ]; then
                error "Config file did not provide any hook."
@@ -424,11 +396,6 @@ zone_down() {
 
        # Execute all triggers after the zone went down
        triggers_execute_all "down" ZONE="${zone}"
-
-       # Remove the zone, if it has got a remove tag.
-       if zone_has_destroy_tag "${zone}"; then
-               zone_destroy_now "${zone}"
-       fi
 }
 
 zone_status() {
@@ -453,11 +420,6 @@ zone_status() {
        fi
 
        hook_zone_exec "${hook}" "status" "${zone}" "$@"
-
-       # Show that the zone it to be removed soon.
-       if zone_has_destroy_tag ${zone}; then
-               warning "This zone is tagged for removal."
-       fi
 }
 
 zone_identify() {
@@ -643,21 +605,22 @@ zone_config_list() {
        assert isset zone
 
        # Print a nice header
-       local format="%-3s %-20s"
-       print "${format}" "ID" "HOOK"
+       local format="%-3s %-20s %-20s"
+       print "${format}" "ID" "HOOK" "HID"
 
        local config
        local hook
        local id
+       local hid
 
        # Print for all config:
        # id and hook
-       # TODO: Add hids here
        for config in $(zone_configs_list "${zone}"); do
                id=${config##*.}
                hook=$(zone_config_get_hook "${zone}" "${config}")
+               hid=$(zone_config_get_hid "${zone}" "${config}")
                assert isset hook
-               print "${format}" "${id}" "${hook}"
+               print "${format}" "${id}" "${hook}" "${hid}"
        done
 }
 
@@ -1149,6 +1112,39 @@ zone_config_get_new_id() {
        done
 }
 
+zone_config_check_same_setting() {
+       # This functions checks if a config hook
+       # with the same setting is already configured for this zone.
+       # Returns True when yes and False when no.
+
+       assert [ $# -eq 4 ]
+
+       local zone=${1}
+       local hook=${2}
+       local key=${3}
+       local value=${4}
+
+       # The key should be local for this function
+       local ${key}
+       local config
+
+       for config in $(zone_configs_list ${zone}); do
+               # Check if the config is from the given hook, when not continue
+               if  [[ $(zone_config_get_hook "${zone}" "${config}") != ${hook} ]]; then
+                       continue
+               fi
+               # Get the value of the key for a given function
+               zone_config_settings_read "${zone}" "${config}" \
+                --ignore-superfluous-settings "${key}"
+               # Check if the value of the config and the passed value are eqal
+               if [[ "${value}" == "${!key}" ]]; then
+                       return ${EXIT_TRUE}
+               fi
+       done
+
+       return ${EXIT_FALSE}
+}
+
 zone_config_get_hook() {
        assert [ $# -eq 2 ]