]> git.ipfire.org Git - people/ms/network.git/commitdiff
Make a better removal of zones possible.
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 31 May 2012 23:12:40 +0000 (23:12 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 31 May 2012 23:12:40 +0000 (23:12 +0000)
Zones that are up are tagged to be removed later to have
the opportunity to reconfigure things without losing the
network connection.

functions.cli
functions.zone
man/network-zone.8.in

index 2c46bd7bead2af1cb2153b2308b4a75e2ac2845e..e2148d6d54752816b6bd0dbbd6bd7049bf7d215e 100644 (file)
@@ -246,9 +246,12 @@ function cli_zone() {
                shift
 
                case "${action}" in
-                       create|remove)
+                       create)
                                zone_${action} $@
                                ;;
+                       remove)
+                               cli_zone_remove $@
+                               ;;
                        ""|*)
                                if [ -n "${action}" ]; then
                                        error "Unrecognized argument: '${action}'"
@@ -262,6 +265,29 @@ function cli_zone() {
        fi
 }
 
+# Removes a zone either immediately, if it is currently down,
+# or adds a tag that the removal will be done when the zone
+# is brought down the next time.
+function cli_zone_remove() {
+       if cli_help_requested $@; then
+               cli_show_man network-zone
+               exit ${EXIT_OK}
+       fi
+
+       local zone=${1}
+       assert zone_exists ${zone}
+
+       if zone_is_up ${zone}; then
+               echo "Zone '${zone}' is up and will be removed when it goes down the next time."
+               zone_remove ${zone}
+       else
+               echo "Removing zone '${zone}' now..."
+               zone_remove_now ${zone}
+       fi
+
+       exit ${EXIT_OK}
+}
+
 function cli_start() {
        if cli_help_requested $@; then
                cli_show_man network
index 3cac124b83175c0e735394fafee768f2122c96d6..50dd9ccc22a23da6b3f5b998c3f39c81756f86df 100644 (file)
@@ -125,7 +125,7 @@ function zone_create() {
        # Maybe the zone create hook did not exit correctly.
        # If this is the case we remove the created zone immediately.
        if [ "${ret}" = "${EXIT_ERROR}" ]; then
-               zone_remove ${zone}
+               zone_remove_now ${zone}
        fi
 }
 
@@ -138,6 +138,12 @@ function zone_edit() {
                return ${EXIT_ERROR}
        fi
 
+       # Check if the zone is tagged for removal.
+       if zone_has_remove_tag ${zone}; then
+               error "You cannot edit a zone that is tagged for removal."
+               return ${EXIT_ERROR}
+       fi
+
        local hook=$(config_get_hook $(zone_dir ${zone})/settings)
 
        if [ -z "${hook}" ]; then
@@ -153,16 +159,35 @@ function zone_edit() {
        hook_zone_exec ${hook} edit ${zone} $@
 }
 
+
 function zone_remove() {
        local zone=${1}
-       shift
+       assert zone_exists ${zone}
 
-       if ! zone_exists ${zone}; then
-               error "Zone '${zone}' does not exist."
-               return ${EXIT_ERROR}
-       fi
+       # Make the zone for removal.
+       touch $(zone_dir ${zone})/.remove
+
+       log INFO "Zone '${zone}' has been tagged for removal."
+}
+
+function zone_has_remove_tag() {
+       local zone=${1}
+       assert zone_exists ${zone}
+
+       [ -e "$(zone_dir ${zone})/.remove" ]
+}
+
+# This function will remove the given zone
+# RIGHT NOW. Use zone_remove to remove it
+# at the next status change.
+function zone_remove_now() {
+       local zone=${1}
+       assert zone_exists ${zone}
+
+       log INFO "Removing zone '${zone}' right now."
 
-       # XXX Tear this down here?
+       # Force the zone down.
+       zone_is_up ${zone} && zone_set_down ${zone}
 
        rm -rf $(zone_dir ${zone})
 }
@@ -176,6 +201,12 @@ function zone_up() {
                return ${EXIT_ERROR}
        fi
 
+       # Check if a zone has got the remove tag.
+       if zone_has_remove_tag ${zone}; then
+               error "Cannot bring up any zone which is to be removed."
+               return ${EXIT_ERROR}
+       fi
+
        local hook=$(config_get_hook $(zone_dir ${zone})/settings)
 
        if [ -z "${hook}" ]; then
@@ -221,6 +252,11 @@ function zone_down() {
        hook_zone_exec ${hook} down ${zone} $@
 
        zone_db ${zone} stopped
+
+       # Remove the zone, if it has got a remove tag.
+       if zone_has_remove_tag ${zone}; then
+               zone_remove_now ${zone}
+       fi
 }
 
 function zone_status() {
@@ -245,6 +281,11 @@ function zone_status() {
        fi
 
        hook_zone_exec ${hook} status ${zone} $@
+
+       # Show that the zone it to be removed soon.
+       if zone_has_remove_tag ${zone}; then
+               warning "This zone is tagged for removal."
+       fi
 }
 
 function zone_port() {
index 23d2b6b6fade29288debf5cd319fecf7d70bc739..4703386f7785a3e72e7ae0cc1471d05ced205fbf 100644 (file)
@@ -30,7 +30,11 @@ required.
 
 \fBremove <zone>\fR
 .RS 4
-XXX TODO What will happen here?
+A zone can be simple removed with this command.
+.PP
+There are two possible ways to remove a zone. The case is when the zone is not up. Then,
+it will be removed immediately. When the zone is current up and used, it will tagged
+to be remove later, after it has been brought down.
 .RE
 .PP