</listitem>
</varlistentry>
+ <varlistentry>
+ <term>
+ <command><replaceable>DEVICE</replaceable> identify</command>
+ </term>
+
+ <listitem>
+ <para>
+ This command only works for Ethernet adapters and will
+ make those that support this feature flash for a few
+ seconds.
+ It is handy to find the right device to put the cable in.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term>
<command><replaceable>DEVICE</replaceable> discover</command>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term>
+ <command><replaceable>ZONE</replaceable> identify</command>
+ </term>
+
+ <listitem>
+ <para>
+ This command will make all ports of the zone flash for
+ a few seconds so that you can identify the correct network
+ adapters in the system.
+ </para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term>
<command><replaceable>ZONE</replaceable> rename <replaceable>NAME</replaceable></command>
_network_device_subcommand() {
local words=( $@ )
- local commands="discover monitor status unlock ussd"
+ local commands="discover identify monitor status unlock ussd"
local cmd="$(_network_find_on_cmdline "${commands}")"
if [[ -z "${cmd}" ]]; then
COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
_network_port_subcommand() {
local words=( $@ )
- local commands="create down edit remove status up"
+ local commands="create down edit identify remove status up"
local cmd="$(_network_find_on_cmdline "${commands}")"
if [[ -z "${cmd}" ]]; then
COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
local words=( $@ )
- local commands="config disable down edit enable port rename status up"
+ local commands="config disable down edit enable identify port rename status up"
local cmd="$(_network_find_on_cmdline "${commands}")"
if [[ -z "${cmd}" ]]; then
COMPREPLY=( $(compgen -W "${commands}" -- "${cur}") )
done
}
+device_identify() {
+ assert [ $# -ge 1 ]
+
+ local device="${1}"
+
+ # Flash for ten seconds by default
+ local seconds="10"
+
+ # Run in background?
+ local background="false"
+
+ local arg
+ while read arg; do
+ case "${arg}" in
+ --background)
+ background="true"
+ ;;
+ --seconds=*)
+ seconds="$(cli_get_val "${arg}")"
+ ;;
+ esac
+ done <<< "$(args $@)"
+
+ assert isinteger seconds
+
+ if ! device_exists "${device}"; then
+ log ERROR "Cannot identify device ${device}: Does not exist"
+ return ${EXIT_ERROR}
+ fi
+
+ if ! device_is_ethernet "${device}"; then
+ log DEBUG "Cannot identify device ${device}: Not an ethernet device"
+ return ${EXIT_NOT_SUPPORTED}
+ fi
+
+ log DEBUG "Identifying device ${device}"
+
+ local command="ethtool --identify ${device} ${seconds}"
+ local ret=0
+
+ if enabled background; then
+ cmd_background "${command}"
+ else
+ cmd_quiet "${command}"
+ ret=$?
+ fi
+
+ return ${ret}
+}
+
device_has_ip() {
local device=${1}
local addr=${2}
# Get the first element which is the lowest MAC address
list_head ${addresses}
}
+
+port_identify() {
+ device_identify $@
+}
return ${ret}
}
+# Executes the given command in background
+cmd_background() {
+ cmd_quiet $@ &
+}
+
+# Prints the PID of the process that was started last
+cmd_background_get_pid() {
+ print "${!}"
+}
+
+cmd_background_result() {
+ local pids=$@
+
+ wait ${pids}
+}
+
# Increase security of the read command
read() {
builtin read -r $@
fi
}
+zone_identify() {
+ assert [ $# -ge 1 ]
+
+ local zone="${1}"
+ shift
+
+ assert zone_exists "${zone}"
+
+ log INFO "Identifying zone ${zone}"
+ local pids
+
+ local pid
+ local port
+ for port in $(zone_get_ports "${zone}"); do
+ # Identify all the ports
+ port_identify "${port}" --background $@
+
+ # Save the PIDs of the subprocesses
+ list_append pids "$(cmd_background_get_pid)"
+ done
+
+ # Wait until all port_identfy processes have finished
+ for pid in ${pids}; do
+ cmd_background_result "${pid}"
+ done
+
+ return ${EXIT_OK}
+}
+
zone_get_ports() {
local zone=${1}
local hook="$(zone_get_hook "${zone}")"
assert isset hook
+ # Make the port briefly flash if supported
+ port_identify "${port}" --background
+
hook_zone_exec "${hook}" "port_attach" "${zone}" "${port}" "$@"
local ret="${?}"
local hook=$(zone_get_hook "${zone}")
assert isset hook
+ # Make the port briefly flash if supported
+ port_identify "${port}" --background
+
hook_zone_exec "${hook}" "port_detach" "${zone}" "${port}" "$@"
local ret="${?}"
discover)
cli_device_discover ${device} $@
;;
+ identify)
+ device_identify "${device}" $@
+ ;;
monitor)
cli_device_monitor "${device}" $@
;;
shift 2
case "${action}" in
- edit|create|remove|up|down|status)
+ edit|create|remove|up|down|status|identify)
port_${action} "${port}" $@
;;
*)
rename)
cli_zone_rename "${zone}" $@
;;
- config|disable|down|edit|enable|status|up)
+ config|disable|down|edit|enable|identify|status|up)
zone_${action} ${zone} $@
;;
*)