Device::Power::ACME.pm - example for remote power control devices
base
$obj = Device::Power::ACME->new();
Another Cluster Module Example.
Full class name Device::Power::ACME
This module can be used as an example of how to develop modules for new Power
type devices in conjunction with the actual device modules that can be found in
this distribution.
The Methods in this module generally override methods that appear in the parent
classes. When developing a class for a Power type device be sure to use
parent methods whenever possible to exploit code shareing at the highest level
in the hierarchy. The methods in this class will function normally with the
exception of when they require the actual device to interact with in which case
they will just print out informative messages of what they would do if a
device was present.
The vast majority of the code in the ACME modules found in each class
path (Node Power and TermSrvr) is identical. Small additions
and omissions are present (or absent) where they are meaninful to describe
functionality that may be unique to a class.
Please see the code source for detailed information and implementation details.
- power - get/set power attribute, or initiate power control action
-
If passed no arguments, simply returns the object's power attribute, which is
an array ref. If passed an array reference, sets the object's power attribute.
-
If passed a scalar (on, off, cycle, inter, etc.), then the appropriate action
is taken to control the power of the device.
-
This method is largely the same as a power method that would be found in any
functional module. It is included here as an example of a typical
implementation. Most actual device interaction is done in methods called by
the power method which are also found in this module.
-
This method should be almost identical to the power method found in the
Device.pm module. When developing modules please consider using your
parents class methods whenenver appropriate.
- _perform - A ``private'' method used by the methods
off and on to execute the appropriate operation.
-
This method would normally accomplish the actual device interaction
but for the purposes of this class will only print out information to
the user about the operation that would be performed.
- off - Power off method.
-
This method is called by the power method when an argument
of ``off'' is passed. This method calls the _perform method to accomplish its
function. This method is inluded to illustrate a device type that has its own
power control capabilities. Alternatively a different object could be
specified in the power attribute, and that objects off method would be used.
For example if an object of type Device::Power::ACME was specified in the
power attribute, the off method from that class would be executed instead of
this off method.
- on - Power on method.
-
This method is called by the power method when an argument
of ``on'' is passed. This method calls the _perform method to accomplish its
function. This method is inluded to illustrate a device type that has its own
power control capabilities. Alternatively a different object could be
specified in the power attribute, and that objects on method would be used.
For example if an object of type Device::Power::ACME was specified in the
power attribute, the on method from that class would be executed instead of
this on method.
- connect - connect method.
-
This method is used to establish a connection to the device. The
method will determine how to establish a connection based on the
console attribute of the object. If the object itself is listed
in the console attribute of the object, the connect method of
this class will be used to directly connect to the device that
the object describes. Alternatively another device like a terminal
server may be used to establish a connection with the device
described by this class. If this is the case the connect method
of this class will call the connect method of the class that
describes the terminal server device. For these example modules
that class will be Device::TermSrvr::ACME.
- status - Status method
-
This method is used to status a device of this class.
What status actually means is device specific but in
general status should return what state the device is
in. Other methods like discover may need the device to be
in a specific state to perform the required funcitonality.
The status method commonly uses other class methods like
connect.
- discover - Discover method.
-
This method is used to discover a device of this type.
What discovering a device means is very device specific but
generally includes obtaining MAC addresses for one to all
of the interfaces defined in the database for the specific
device. The discover method typically uses other class
methods like status and connect.
- config - config method.
-
This method will accomplish whatever it means to config a
device of this type. Configure in this sense generally means
the basic configuration necessary to allow this device to
act as expected as a member of the cluster.
For a Power device this could mean configuring outlet
information. For specific examples please see device
specific modules in this class path.
- cycle_time - cycle_time method.
-
This method is used as an example of how other class methods can be
used to alter the functionality of methods that appear in the local
module or methods that are inherited from parent classes. In real
implementations the power method can appear in a parent class of
a range of specific device classes. If each of the classes that
inherit the parent power method have different delay times between
a power off and a power on, a method like this can be used
to modify the functionality without replicating entire methods
in each class that have little difference. This practice should
be employed wherever possible.
- outlet - outlet method
-
This method is used to check the outlet passed to the power subroutine.
Checking can mean different things for different devices. Checking
the outlet can be as simple as makeing sure that a valid outlet number
was passed for this type of device.
-
Note: This method is not included in the ACME module in the Node class
path since it is generally not meaningful to check the outlet number
when accessing the Node device directly.