]> git.ipfire.org Git - people/ms/network.git/commitdiff
Cleanup code that deletes ports/zones
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Sep 2018 17:30:11 +0000 (19:30 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 23 Sep 2018 17:30:11 +0000 (19:30 +0200)
This is used for network reset and it wasn't clear
before if the command were successful

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/functions/functions.ports
src/functions/functions.zone
src/hooks/zones/bridge
src/network

index ae619ababaa155729aeba28a3dc4676ad55a4020..f70adf638f24732697c9180224298c662a169fa0 100644 (file)
 #                                                                             #
 ###############################################################################
 
+ports_get_all() {
+       local port
+       for port in $(list_directory "${NETWORK_PORTS_DIR}"); do
+               if port_exists "${port}"; then
+                       print "${port}"
+               fi
+       done
+}
+
+# XXX TO BE REMOVED
 port_list() {
-       list_directory "${NETWORK_PORTS_DIR}"
+       ports_get_all "$@"
 }
 
 port_list_in_use() {
@@ -95,10 +105,6 @@ port_settings_write() {
        settings_write "$(port_file "${port}")" ${args}
 }
 
-ports_get_all() {
-       port_list
-}
-
 port_file() {
        local port="${1}"
        assert isset port
@@ -188,7 +194,13 @@ port_destroy() {
                return ${EXIT_ERROR}
        fi
 
-       rm -rf "${NETWORK_PORTS_DIR}/${port}"
+       if ! rm -rf "${NETWORK_PORTS_DIR}/${port}"; then
+               log ERROR "Could not destroy port ${port}"
+               return ${EXIT_ERROR}
+       fi
+
+       log INFO "Destroyed port ${port}"
+       return ${EXIT_OK}
 }
 
 port_create() {
index 3483d4e76f312a79f67a956118d7cebd62c13838..b9d475f71745e7cbadd97bbff92bef3eb19a4228 100644 (file)
@@ -322,15 +322,19 @@ zone_destroy() {
                return ${EXIT_ERROR}
        fi
 
-       log INFO "Destroying zone ${zone}"
-
        # Force the zone down.
        zone_is_active "${zone}" && zone_stop "${zone}"
 
        # Disable zone auto-start
        zone_disable "${zone}"
 
-       rm -rf "${NETWORK_ZONES_DIR}/${zone}"
+       if ! rm -rf "${NETWORK_ZONES_DIR}/${zone}"; then
+               log ERROR "Could not destroy zone ${zone}"
+               return ${EXIT_ERROR}
+       fi
+
+       log INFO "Destroyed zone ${zone}"
+       return ${EXIT_OK}
 }
 
 zone_up() {
index 9226374110edf362a4298d489e0d60622651ef1c..38b2b5f885c8aff7f50b0f28841624bf563cf02e 100644 (file)
@@ -329,6 +329,9 @@ hook_port_up() {
        # Read configuration values
        zone_port_settings_read "${zone}" "${port}" ${HOOK_PORT_SETTINGS}
 
+       # Make sure that the port is up
+       port_up "${port}"
+
        # Attach the port to the bridge
        bridge_attach_device "${zone}" "${port}"
 
@@ -341,9 +344,6 @@ hook_port_up() {
                stp_port_set_priority "${zone}" "${port}" "${PRIORITY}"
        fi
 
-       # Make sure that the port is up
-       port_up "${port}"
-
        return ${EXIT_OK}
 }
 
index 506b1e0422d1ce1184aa42ec0117c4e053b95e17..69d77d58ce021b079da01291a93387375bbdf762 100644 (file)
@@ -1209,12 +1209,12 @@ cli_reset() {
        done
 
        local zone
-       for zone in $(zones_get --all); do
+       for zone in $(zones_get_all); do
                zone_destroy "${zone}"
        done
 
        local port
-       for port in $(ports_get --all); do
+       for port in $(ports_get_all); do
                port_destroy "${port}"
        done