X-Git-Url: http://git.ipfire.org/?p=people%2Farne_f%2Fnetwork.git;a=blobdiff_plain;f=functions.ports;fp=functions.ports;h=9cda5641e4fd618f0a11d918c1848c62b7684d36;hp=feecaa241b02e33c8790ed6c6f64305530d64d78;hb=98f4dae6942efb34c7b3183deefee1dd514ee72e;hpb=1578dae929cd6e4fe51418e2180cd478fda938dc diff --git a/functions.ports b/functions.ports index feecaa24..9cda5641 100644 --- a/functions.ports +++ b/functions.ports @@ -99,10 +99,34 @@ function port_destroy() { port_exists ${port} || return ${EXIT_OK} - local attached_zone=$(port_is_attached ${port}) + # Check if the port is attached to any zone and don't delete it. + local ok=${EXIT_OK} + local attached_zone=$(port_is_attached ${port}) if [ -n "${attached_zone}" ]; then - error "Cannot destroy port '${port}' which is attached to zone '${attached_zone}'." + error_log "Cannot destroy port '${port}' which is attached to zone '${attached_zone}'." + ok=${EXIT_ERROR} + fi + + # Check if the port is linked to any other port and don't allow the user + # to delete it. + local other_port + for other_port in $(ports_get); do + [ "${other_port}" = "${port}" ] && continue + + if listmatch ${port} $(port_get_parents ${other_port}); then + error_log "Cannot destroy port '${port}' which is a parent port to '${other_port}'." + ok=${EXIT_ERROR} + fi + + if listmatch ${port} $(port_get_children ${other_port}); then + error_log "Cannot destroy port '${port}' which is child of port '${other_port}'." + ok=${EXIT_ERROR} + fi + done + + # If ok says we are not okay --> exit + if [ ${ok} -ne ${EXIT_OK} ]; then return ${EXIT_ERROR} fi @@ -136,6 +160,10 @@ function port_status() { port_cmd status $@ } +function port_info() { + port_cmd info $@ +} + function port_cmd() { local cmd=${1} local port=${2} @@ -194,3 +222,29 @@ function port_find_free() { i=$(( ${i} + 1 )) done } + +function port_get_info() { + local port=${1} + local key=${2} + + assert isset port + assert port_exists ${port} + assert isset key + + ( + eval $(port_info ${port}) + echo "${!key}" + ) +} + +function port_get_parents() { + local port=${1} + + port_get_info ${port} PORT_PARENTS +} + +function port_get_children() { + local port=${1} + + port_get_info ${port} PORT_CHILDREN +}