exit ${EXIT_OK}
}
+function cli_hotplug() {
+ if cli_help_requested $@; then
+ cli_usage root-hotplug
+ exit ${EXIT_OK}
+ fi
+
+ local command=${1}
+ shift
+
+ case "${command}" in
+ device)
+ device_hotplug $@
+ exit $?
+ ;;
+ *)
+ cli_usage root-hotplug
+ exit ${EXIT_OK}
+ ;;
+ esac
+}
+
function cli_port() {
if cli_help_requested $@; then
cli_usage root-port
__device_get_file ${device} statistics/tx_errors
}
+
+function device_hotplug() {
+ local device=${1}
+ shift
+
+ assert isset device
+ #assert device_exists ${device}
+
+ if ! device_is_free ${device}; then
+ log ERROR "The device '${device}' does not look to be unused."
+ log ERROR "Don't proceed."
+ # return ${EXIT_ERROR}
+ fi
+
+ for port in $(ports_get_all); do
+ port_cmd hotplug ${port} ${device}
+ if [ $? -eq ${EXIT_OK} ]; then
+ echo "${port}"
+ exit ${EXIT_OK}
+ fi
+ done
+
+ exit ${EXIT_ERROR}
+}
echo "${CONFIG_DIR}/ports"
}
+function ports_get_all() {
+ local port
+
+ for port in $(port_dir)/*; do
+ [ -f "${port}" ] || continue
+
+ basename ${port}
+ done
+}
+
function port_file() {
local port=${1}
function run() {
case "${action}" in
- edit|add|create|rem|up|down|status|info)
+ edit|add|create|rem|up|down|status|info|hotplug)
_${action} $@
;;
esac
exit ${EXIT_ERROR}
}
+function _hotplug() {
+ exit ${EXIT_ERROR}
+}
+
function _info() {
local port=${1}
shift
exit ${EXIT_OK}
}
+function _hotplug() {
+ local port=${1}
+ local device=${2}
+
+ assert isset port
+ assert isset device
+
+ config_read $(port_file ${port})
+
+ if [ "${DEVICE_MAC}" = "$(device_get_address ${device})" ]; then
+ exit ${EXIT_OK}
+ fi
+
+ exit ${EXIT_ERROR}
+}
+
function _status() {
local port=${1}
shift
init_run
;;
- config|hostname|port|device|zone|start|stop|restart|status|reset)
+ config|hostname|hotplug|port|device|zone|start|stop|restart|status|reset)
cli_${action} $@
;;