The following project directories may be useful when creating a handler:
/common — common helper classes and functions;
/ups_common — helper classes and functions for working with UPS;
/ups_common/handlers — UPS handlers.
You can see the required Python libraries and their versions in the requirements.txt project file. To install the necessary libraries, run the command:
pip3 install -r requirements.txt
To check data types in the project, we recommend using the mypy analyzer.
Creating a handler
Class for working with UPS
The UPS class inherits from the class:
BaseSnmpUps — for devices operating via SNMP;
BaseUps — for other devices.
The BaseSnmpUps class contains methods for interacting with the UPS via SNMP:
snmp_get — perform a read request by a specific OID;
snmp_set — perform a modifying request by a specific OID;
snmp_walk — perform a request that returns a list.
Example of class description
class ExampleHandlerSnmp(BaseSnmpUps):
"""Example handler class."""
def __init__(self, ups_data: UpsSnmpData):
"""__init__.
Args:
ups_data (UpsSnmpData): ups connection data
"""
super().__init__(ups_data)
Methods for working with UPS
For DCImanager 6 to interact with the UPS, override the methods of the BaseUps class:
status — UPS polling;
port_up — enable port;
port_down — disable port;
statistic — collect statistics.
The equipment service uses not raw json data, but their object representation.Instances of the UpsView class are the UPS representation. It has the following parameters:
load_percentage — load, %;
charge_time — charge time, min;
input_power — output power, kW;
output_power — power consumption, kW.
The UpsData class inherits from the base class ConnectionParams and defines the data for accessing the UPS.
Each handler file must contain the function make_handler. This function creates the handler object:
example.com — domain name of the DCImanager 6 server
<token> — authorization token
<device> — device type. Possible values:
switch — switch;
ups — UPS;
pdu — PDU;
vpu — VPU
<internal_handler_name> — unique internal handler name
<handler_name> — handler name to display in the platform interface
<handler_protocol> — protocol for working with the handler. For example, snmp
features — parameters for displaying information in the user interface. For UPS, no additional parameters are provided, so the only possible value is an empty array.
The response will contain the id of the created handler. Save this value.
Example response
{"id": 1}
Upload the archive with the handler to the platform:
example.com — domain name of the DCImanager 6 server
<handler_id> — handler id
<token> — authorization token
custom_handler.tar.gz — name of the archive with the handler
<import_path> — relative import path. For example, if the handler file my_handler.py is in the handler_dir directory, the relative path would be handler_dir.my_handler
You can also use this command to upload new versions of the handler to the platform.