-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d53284c
commit 1306526
Showing
10 changed files
with
357 additions
and
440 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from cloudshell.shell.core.context_utils import get_attribute_by_name | ||
import inject | ||
|
||
|
||
class FactoryContext: | ||
def __init__(self, context): | ||
api = inject.instance('api') | ||
password = get_attribute_by_name('Password', context) | ||
self._password = api.DecryptPassword(password).Value | ||
self._user = get_attribute_by_name('User', context) | ||
self._host = context.resource.address | ||
|
||
@property | ||
def user(self): | ||
return self._user | ||
|
||
@property | ||
def password(self): | ||
return self._password | ||
|
||
@property | ||
def host(self): | ||
return self._host |
31 changes: 31 additions & 0 deletions
31
cloudshell/power/pdu/raritan/device/raritan_rpcapi_pdu_factory.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from raritan import rpc | ||
from raritan.rpc import pdumodel | ||
|
||
from cloudshell.shell.core.driver_context import AutoLoadDetails, AutoLoadResource, AutoLoadAttribute | ||
from cloudshell.power.pdu.raritan.device.rpcapi_outlet import RPCAPIOutlet | ||
from cloudshell.power.pdu.device.pdu_factory import PDUFactory | ||
|
||
|
||
class RaritanRpcApiPduFactory(PDUFactory): | ||
def __init__(self, context): | ||
self._agent = rpc.Agent("https", context.host, context.user, context.password) | ||
self._pdu_handler = pdumodel.Pdu('model/pdu/0', self._agent) | ||
|
||
def get_outlets(self): | ||
return [RPCAPIOutlet(x) for x in self._pdu_handler.getOutlets()] | ||
|
||
def get_inventory(self): | ||
metadata = self._pdu_handler.getMetaData() | ||
resources = self._autoload_resources_by_rpc() | ||
attributes = [AutoLoadAttribute('', 'Firmware Version', metadata.fwRevision), | ||
AutoLoadAttribute('', 'Vendor', metadata.nameplate.manufacturer), | ||
AutoLoadAttribute('', 'Model', metadata.nameplate.model)] | ||
result = AutoLoadDetails(resources, attributes) | ||
return result | ||
|
||
def _autoload_resources_by_rpc(self): | ||
resources = [AutoLoadResource('Generic Power Socket', | ||
'Socket ' + str(x+1), | ||
str(x+1)) | ||
for x, val in enumerate(self.get_outlets())] | ||
return resources |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from raritan.rpc import pdumodel | ||
from cloudshell.power.pdu.device.outlet import Outlet | ||
|
||
|
||
class RPCAPIOutlet(Outlet): | ||
def __init__(self, outlet_handler): | ||
self._handler = outlet_handler | ||
|
||
def power_on(self): | ||
self._handler.setPowerState(POWERED_ON) | ||
if self._handler.getState().powerState != POWERED_ON: | ||
Exception('Ports were not powered on') | ||
|
||
def power_off(self): | ||
self._handler.setPowerState(POWERED_OFF) | ||
if self._handler.getState().powerState != POWERED_OFF: | ||
Exception('Ports were not powered off') | ||
|
||
POWERED_ON = pdumodel.Outlet.PowerState.PS_ON | ||
POWERED_OFF = pdumodel.Outlet.PowerState.PS_OFF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
|
||
|
||
def get_outlets_by_address(outlets, ports): | ||
# ports: ['192.168.30.128/4', '192.168.30.128/6'] | ||
|
||
def socket(port): | ||
n = int(port.split('/')[-1]) | ||
return outlets[n-1] | ||
|
||
return [socket(x) for x in ports] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.