View Source VintageNet.PowerManager.PMControl (vintage_net v0.13.5)

Power management control GenServer

This GenServer runs a PowerManager implementation for a network device. It provides the API for powering on and off a device and for signally that it's working well.

Internally, it runs a state machine that translates power on and off requests into actions sent to the PowerManager implementation. The state machine handles the timing of actions so that hardware gets a chance to initialize and isn't reset to quickly. PowerManager implementations specify times.

Since networking devices can sometimes hang or fail in unexpected ways, this module can power them off and on to try to get them back in a good state. This is implemented in terms of a watchdog. Code that can detect the network device being in a good state should call pet_watchdog/1. For example, code that checks internet connectivity could call pet_watchdog/1 since that's a pretty good sign that the device works. Other checks are possible. If pet_watchdog/1 isn't called, this module will restart the network device.

Summary

Functions

Returns a specification to start this module under a supervisor.

Force reset

Return information about the specified power manager

Pet watchdog

Power off

Power on

Send an arbitrary message to the power manager for an interface

Start up a server

Functions

Returns a specification to start this module under a supervisor.

See Supervisor.

@spec force_reset(VintageNet.ifname()) :: :ok

Force reset

This is intended to be called based on human interaction. For example, by a UI button or by a developer who knows or strongly suspects that something is wrong with the network device it needs a reboot.

Resetting devices that have been powered off will NOT power them on.

Calling this automatically is not recommended especially if it is used as an alternative to the watchdog mechanism. The reason is that it is easier to identify where the device is working than it is to identify every way it can fail. Also, force reset ignores minimum on times since assumption is that if someone wants to reset, they're ready to reset now.

@spec info(VintageNet.ifname()) :: {:ok, map()} | :error

Return information about the specified power manager

NOTE: the map returned may change in the future

@spec pet_watchdog(VintageNet.ifname()) :: :ok

Pet watchdog

Call this whenever the network connection is in a good state. If it has not been called by the watchdog timeout, the device will be rebooted.

@spec power_off(VintageNet.ifname()) :: :ok

Power off

This is called when VintageNet stops using an interface. The current state in the power management state machine determines how this is handled. For example, the power could already be off.

@spec power_on(VintageNet.ifname()) :: :ok

Power on

This should be called whenever an interface should be powered on. It can be called more than once. If you want the network interface to be on, it is always safe to call this. An internal state machine will ignore redundant calls.

Link to this function

send_message(ifname, message)

View Source
@spec send_message(VintageNet.ifname(), any()) :: any()

Send an arbitrary message to the power manager for an interface

This will be received by the PowerManager's handle_info/2 callback.

@spec start_link(keyword()) :: GenServer.on_start()

Start up a server

This is intended to be called via VintageNet.PowerManager.Supervisor

Arguments:

  • :impl - the module that implements PowerManager
  • :impl_args - arguments to pass to the PowerManager's init/1 call