</para>
</listitem>
</varlistentry>
+
+ <varlistentry>
+ <term>
+ <command><replaceable>ZONE</replaceable> rename <replaceable>NAME</replaceable></command>
+ </term>
+
+ <listitem>
+ <para>
+ Renames the zone to <replaceable>NAME</replaceable>.
+ </para>
+ <para>
+ The command will shut down the zone if it is up and
+ start it again with the new name. If the zone is not
+ up it won't be started.
+ </para>
+ <para>
+ Zones that are marked to be destroyed cannot be renamed.
+ </para>
+ </listitem>
+ </varlistentry>
</variablelist>
</refsect1>
local words=( $@ )
- local commands="config disable down edit enable port status up"
+ local commands="config disable down edit enable port rename status up"
local cmd="$(_network_find_on_cmdline "${commands}")"
if [[ -z "${cmd}" ]]; then
COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
return ${ret}
}
+# This function executes the given command and inverses the return code
+not() {
+ local command="$@"
+
+ ${command} && return ${EXIT_FALSE} || return ${EXIT_TRUE}
+}
+
exec_cmd() {
local cmd=$@
hook_zone_exec ${hook} edit ${zone} $@
}
+zone_rename() {
+ assert [ $# -eq 2 ]
+
+ local zone="${1}"
+ 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
+ # potentially brought up again
+
+ # Save if the zone is running right now
+ zone_is_active "${zone}"
+ local zone_was_active="${?}"
+
+ # Save if the zone is enabled (i.e. auto-start)
+ zone_is_enabled "${zone}"
+ local zone_was_enabled="${?}"
+
+ # Stop the zone
+ zone_stop "${zone}"
+
+ # Disable the zone
+ zone_disable "${zone}"
+
+ # Rename the configuration files
+ mv -f "$(zone_dir "${zone}")" "$(zone_dir "${name}")"
+
+ # Enable the zone if it was enabled before
+ [ ${zone_was_enabled} -eq ${EXIT_TRUE} ] && zone_enable "${name}"
+
+ # Start the zone if it was up before
+ [ ${zone_was_active} -eq ${EXIT_TRUE} ] && zone_start "${name}"
+
+ log INFO "Zone ${zone} was renamed to ${name}"
+ return ${EXIT_OK}
+}
+
zone_destroy() {
local zone="${1}"
port)
cli_zone_port "${zone}" $@
;;
+ rename)
+ cli_zone_rename "${zone}" $@
+ ;;
config|disable|down|edit|enable|status|up)
zone_${action} ${zone} $@
;;
exit ${EXIT_OK}
}
+cli_zone_rename() {
+ if cli_help_requested $@; then
+ cli_show_man network-zone
+ exit ${EXIT_OK}
+ fi
+
+ local zone="${1}"
+ local name="${2}"
+ shift 2
+
+ if ! isset name; then
+ error "You need to pass a new name"
+ exit ${EXIT_ERROR}
+ fi
+
+ if ! zone_name_is_valid "${name}"; then
+ error "Invalid new zone name: ${name}"
+ exit ${EXIT_ERROR}
+ fi
+
+ # Check if the zone exists
+ if ! zone_exists "${zone}"; then
+ error "Zone ${zone} does not exist"
+ exit ${EXIT_ERROR}
+ fi
+
+ # Destroyed zones cannot be renamed
+ if zone_has_destroy_tag "${zone}"; then
+ error "Zone ${zone} is about to be destroyed and cannot be renamed"
+ exit ${EXIT_ERROR}
+ fi
+
+ # Check if a zone with the new name already exists
+ if zone_exists "${name}"; then
+ error "Zone ${name} already exists"
+ exit ${EXIT_ERROR}
+ fi
+
+ # Rename
+ if ! zone_rename "${zone}" "${name}"; then
+ error "Could not rename zone ${zone} to ${name}"
+ exit ${EXIT_ERROR}
+ fi
+
+ exit ${EXIT_OK}
+}
+
cli_list_hooks() {
local type=${1}
shift