monokai 81cb4f20a1 Complete the fabrics switch resource
Change-Id: I216daedd80911cb2aade55e251a8d6219c760b64
2019-01-22 10:14:06 +08:00

150 lines
4.3 KiB
Python

# Copyright 2018 99cloud, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import logging
from sushy.resources import base
from sushy import utils
from rsd_lib import utils as rsd_lib_utils
LOG = logging.getLogger(__name__)
class StatusField(base.CompositeField):
state = base.Field('State')
health = base.Field('Health')
health_rollup = base.Field('HealthRollUp')
class PortsField(base.CompositeField):
identity = base.Field('@odata.id')
class LinksField(base.CompositeField):
chassis = base.Field("Chassis", adapter=utils.get_members_identities)
class SwitchResetField(base.CompositeField):
target = base.Field("target")
"""The switch reset target"""
reset_type_allowable_values = base.Field("ResetType@Redfish."
"AllowableValues")
"""The switch reset reset type reset allowable values"""
class ActionsField(base.CompositeField):
switch_reset = SwitchResetField("#Switch.Reset")
"""The actions switch reset"""
class Switch(base.ResourceBase):
identity = base.Field('Id')
"""The switch identity"""
name = base.Field('Name')
"""The switch name"""
description = base.Field('Description')
"""The switch description"""
switch_type = base.Field('SwitchType')
"""The switch type"""
status = StatusField('Status')
"""The switch status"""
manufacturer = base.Field('Manufacturer')
"""The switch manufacturer name"""
model = base.Field('Model')
"""The switch model"""
sku = base.Field("SKU")
"""The switch SKU"""
serial_number = base.Field('SerialNumber')
"""The switch serial number"""
part_number = base.Field('PartNumber')
"""The switch part number"""
asset_tag = base.Field('AssetTag')
"""The switch custom asset tag"""
domain_id = base.Field('DomainID')
"""The switch domain id"""
is_managed = base.Field('IsManaged')
"""The switch managed state"""
total_switch_width = base.Field('TotalSwitchWidth',
adapter=rsd_lib_utils.num_or_none)
"""The switch total switch width"""
indicator_led = base.Field('IndicatorLED')
"""The switch indicator led"""
power_state = base.Field('PowerState')
"""The switch power state"""
ports = PortsField('Ports')
"""The switch ports"""
links = LinksField("Links")
"""The switch links"""
actions = ActionsField("Actions")
"""The switch actions"""
def __init__(self, connector, identity, redfish_version=None):
"""A class representing a Switch
:param connector: A Connector instance
:param identity: The identity of the Switch resource
:param redfish_version: The version of RedFish. Used to construct
the object according to schema of the given version.
"""
super(Switch, self).__init__(connector, identity,
redfish_version)
def reset_switch(self):
"""A post method to reset switch
:returns: The uri of the acl rule
"""
data = {"ResetType": "GracefulRestart"}
target_uri = self.actions.switch_reset.target
self._conn.post(target_uri, data=data)
class SwitchCollection(base.ResourceCollectionBase):
@property
def _resource_type(self):
return Switch
def __init__(self, connector, path, redfish_version=None):
"""A class representing an Endpoint
:param connector: A Connector instance
:param path: The canonical path to the Switch collection resource
:param redfish_version: The version of RedFish. Used to construct
the object according to schema of the given version.
"""
super(SwitchCollection, self).__init__(connector, path,
redfish_version)