assert isset action
assert zone_exists ${zone}
- # Aliases
- case "${action}" in
- del|delete|remove)
- action="rem"
- ;;
- esac
-
case "${action}" in
- add|edit|rem)
+ add|edit|remove)
zone_port_${action} ${zone} $@
;;
*)
}
function zone_port_add() {
- local zone=${1}
- shift
-
+ local zone="${1}"
assert isset zone
- local hook=$(zone_get_hook ${zone})
+ local port="${2}"
+ assert isset port
+
+ shift 2
+
+ # Check if the port actually exists.
+ if ! port_exists "${port}"; then
+ error "Cannot add port '${port}' which does not exist"
+ return ${EXIT_ERROR}
+ fi
+ # Check if the port is already connected to this or any other zone.
+ local z
+ for z in $(zones_get_all); do
+ if zone_has_port "${z}" "${port}"; then
+ error "Port '${port}' is already assigned to zone '${z}'"
+ return ${EXIT_ERROR}
+ fi
+ done
+
+ local hook=$(zone_get_hook "${zone}")
assert isset hook
- hook_zone_exec ${hook} port_add ${zone} $@
+ hook_zone_exec "${hook}" "port_add" "${zone}" "${port}" "$@"
}
function zone_port_edit() {
- zone_port_cmd edit $@
-}
+ local zone="${1}"
+ assert isset zone
-function zone_port_rem() {
- zone_port_cmd rem $@
-}
+ local port="${2}"
+ assert isset port
-function zone_port_cmd() {
- local cmd=${1}
- local zone=${2}
- local port=${3}
- shift 3
+ shift 2
- assert isset zone
- assert isset port
+ # Check if the port actually exists.
+ if ! port_exists "${port}"; then
+ error "Port '${port}' does not exist"
+ return ${EXIT_ERROR}
+ fi
- local hook_zone=$(zone_get_hook ${zone})
- local hook_port=$(port_get_hook ${port})
+ # Check if the zone actually has this port.
+ if ! zone_has_port "${zone}" "${port}"; then
+ error "Port '${port}' is not attached to zone '${zone}'"
+ return ${EXIT_ERROR}
+ fi
- assert isset hook_zone
- assert isset hook_port
+ local hook=$(zone_get_hook "${zone}")
+ assert isset hook
- hook_zone_port_exec ${hook_zone} ${hook_port} ${cmd} ${zone} ${port} $@
+ hook_zone_exec "${hook}" "port_edit" "${zone}" "${port}" "$@"
}
-function zone_port_up() {
- zone_port_cmd up $@
-}
+function zone_port_remove() {
+ local zone="${1}"
+ assert isset zone
+
+ local port="${2}"
+ assert isset port
+
+ shift 2
+
+ # Check if the zone actually has this port.
+ if ! zone_has_port "${zone}" "${port}"; then
+ error "Port '${port}' is not attached to zone '${zone}'"
+ return ${EXIT_ERROR}
+ fi
+
+ local hook=$(zone_get_hook "${zone}")
+ assert isset hook
-function zone_port_down() {
- zone_port_cmd down $@
+ hook_zone_exec "${hook}" "port_remove" "${zone}" "${port}" "$@"
}
function zone_get_ports() {