Merge "Migrate Fabric to enums"
This commit is contained in:
@@ -22,6 +22,7 @@ from sushy.resources.chassis.constants import * # noqa
|
||||
from sushy.resources.constants import * # noqa
|
||||
from sushy.resources.eventservice.constants import * # noqa
|
||||
from sushy.resources.fabric.constants import * # noqa
|
||||
from sushy.resources.ipaddresses import * # noqa
|
||||
from sushy.resources.manager.constants import * # noqa
|
||||
from sushy.resources.registry.constants import * # noqa
|
||||
from sushy.resources.system.constants import * # noqa
|
||||
|
||||
@@ -10,52 +10,98 @@
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
# Values come from the Redfish Fabric json-schema 1.0.4:
|
||||
# http://redfish.dmtf.org/schemas/v1/Fabric.v1_0_4.json#/definitions/Fabric
|
||||
# Values come from the Redfish Fabric json-schema:
|
||||
# https://redfish.dmtf.org/schemas/v1/Fabric.v1_2_2.json
|
||||
# https://redfish.dmtf.org/schemas/v1/Endpoint.v1_6_1.json
|
||||
|
||||
# Address origin IPv4 constants
|
||||
import enum
|
||||
|
||||
ADDRESS_ORIGIN_IPv4_BOOTP = 'Address is provided by a BOOTP service'
|
||||
ADDRESS_ORIGIN_IPv4_DHCP = 'Address is provided by a DHCPv4 service'
|
||||
ADDRESS_ORIGIN_IPv4_IPv4LINKLOCAL = 'Address valid only for this segment'
|
||||
ADDRESS_ORIGIN_IPv4_STATIC = 'A static address as configured by the user'
|
||||
|
||||
# Address origin IPv6 constants
|
||||
class EntityRole(enum.Enum):
|
||||
"""Entity role constants"""
|
||||
|
||||
ADDRESS_ORIGIN_IPv6_DHCPv6 = 'Address is provided by a DHCPv6 service'
|
||||
ADDRESS_ORIGIN_IPv6_LINKLOCAL = 'Address valid only for this network segment'
|
||||
ADDRESS_ORIGIN_IPv6_SLAAC = 'Stateless Address Auto Configuration service'
|
||||
ADDRESS_ORIGIN_IPv6_STATIC = 'A static address as configured by the user'
|
||||
INITIATOR = 'Initiator'
|
||||
"""The entity sends commands, messages, or other types of requests to
|
||||
other entities on the fabric, but cannot receive commands from other
|
||||
entities."""
|
||||
|
||||
# Address state constants
|
||||
TARGET = 'Target'
|
||||
"""The entity receives commands, messages, or other types of requests
|
||||
from other entities on the fabric, but cannot send commands to other
|
||||
entities."""
|
||||
|
||||
ADDRESS_STATE_DEPRECATED = 'Deprecated'
|
||||
"""This address is currently within it's valid lifetime, but is now outside of
|
||||
it's preferred lifetime as defined in RFC 4862."""
|
||||
ADDRESS_STATE_FAILED = 'Failed'
|
||||
"""This address has failed Duplicate Address Detection testing as defined in
|
||||
RFC 4862 section 5.4 and is not currently in use."""
|
||||
ADDRESS_STATE_PREFERRED = 'Preferred'
|
||||
"""This address is currently within both it's valid and preferred lifetimes as
|
||||
defined in RFC 4862."""
|
||||
ADDRESS_STATE_TENTATIVE = 'Tentative'
|
||||
"""This address is currently undergoing Duplicate Address Detection testing as
|
||||
defined in RFC 4862 section 5.4."""
|
||||
BOTH = 'Both'
|
||||
"""The entity can both send and receive commands, messages, and other
|
||||
requests to or from other entities on the fabric."""
|
||||
|
||||
# Entity role constants
|
||||
|
||||
ENTITY_ROLE_BOTH = 'The entity is acting as both an initiator and a target'
|
||||
ENTITY_ROLE_INITIATOR = 'The entity is acting as an initiator'
|
||||
ENTITY_ROLE_TARGET = 'The entity is acting as a target'
|
||||
# Backward compatibility
|
||||
ENTITY_ROLE_INITIATOR = EntityRole.INITIATOR
|
||||
ENTITY_ROLE_TARGET = EntityRole.TARGET
|
||||
ENTITY_ROLE_BOTH = EntityRole.BOTH
|
||||
|
||||
# Entity type constants
|
||||
|
||||
ENTITY_TYPE_PCI_BRIDGE = 'PCI(e) Bridge'
|
||||
ENTITY_TYPE_DISPLAY_CONTROLLER = 'Display Controller'
|
||||
ENTITY_TYPE_DRIVE = 'Disk Drive'
|
||||
ENTITY_TYPE_NETWORK_CONTROLLER = 'Network Controller'
|
||||
ENTITY_TYPE_PROCESSOR = 'Processor Device'
|
||||
ENTITY_TYPE_ROOT_COMPLEX = 'Root Complex'
|
||||
ENTITY_TYPE_STORAGE_EXPANDER = 'Storage Expander'
|
||||
ENTITY_TYPE_STORAGE_INITIATOR = 'Storage Initiator'
|
||||
ENTITY_TYPE_VOLUME = 'Volume'
|
||||
class EntityType(enum.Enum):
|
||||
"""Entity type constants"""
|
||||
|
||||
STORAGE_INITIATOR = 'StorageInitiator'
|
||||
"""The entity is a storage initiator."""
|
||||
|
||||
ROOT_COMPLEX = 'RootComplex'
|
||||
"""The entity is a PCI(e) root complex."""
|
||||
|
||||
NETWORK_CONTROLLER = 'NetworkController'
|
||||
"""The entity is a network controller."""
|
||||
|
||||
DRIVE = 'Drive'
|
||||
"""The entity is a drive."""
|
||||
|
||||
STORAGE_EXPANDER = 'StorageExpander'
|
||||
"""The entity is a storage expander."""
|
||||
|
||||
DISPLAY_CONTROLLER = 'DisplayController'
|
||||
"""The entity is a display controller."""
|
||||
|
||||
BRIDGE = 'Bridge'
|
||||
"""The entity is a PCI(e) bridge."""
|
||||
|
||||
PROCESSOR = 'Processor'
|
||||
"""The entity is a processor."""
|
||||
|
||||
VOLUME = 'Volume'
|
||||
"""The entity is a volume."""
|
||||
|
||||
ACCELERATION_FUNCTION = 'AccelerationFunction'
|
||||
"""The entity is an acceleration function realized through a device,
|
||||
such as an FPGA."""
|
||||
|
||||
MEDIA_CONTROLLER = 'MediaController'
|
||||
"""The entity is a media controller."""
|
||||
|
||||
MEMORY_CHUNK = 'MemoryChunk'
|
||||
"""The entity is a memory chunk."""
|
||||
|
||||
SWITCH = 'Switch'
|
||||
"""The entity is a switch, not an expander. Use `Expander` for
|
||||
expanders."""
|
||||
|
||||
FABRIC_BRIDGE = 'FabricBridge'
|
||||
"""The entity is a fabric bridge."""
|
||||
|
||||
MANAGER = 'Manager'
|
||||
"""The entity is a manager."""
|
||||
|
||||
STORAGE_SUBSYSTEM = 'StorageSubsystem'
|
||||
"""The entity is a storage subsystem."""
|
||||
|
||||
|
||||
# Backward compatibility
|
||||
ENTITY_TYPE_STORAGE_INITIATOR = EntityType.STORAGE_INITIATOR
|
||||
ENTITY_TYPE_ROOT_COMPLEX = EntityType.ROOT_COMPLEX
|
||||
ENTITY_TYPE_NETWORK_CONTROLLER = EntityType.NETWORK_CONTROLLER
|
||||
ENTITY_TYPE_DRIVE = EntityType.DRIVE
|
||||
ENTITY_TYPE_STORAGE_EXPANDER = EntityType.STORAGE_EXPANDER
|
||||
ENTITY_TYPE_DISPLAY_CONTROLLER = EntityType.DISPLAY_CONTROLLER
|
||||
ENTITY_TYPE_PCI_BRIDGE = EntityType.BRIDGE
|
||||
ENTITY_TYPE_PROCESSOR = EntityType.PROCESSOR
|
||||
ENTITY_TYPE_VOLUME = EntityType.VOLUME
|
||||
|
||||
@@ -18,7 +18,8 @@ import logging
|
||||
from sushy.resources import base
|
||||
from sushy.resources import common
|
||||
from sushy.resources import constants as res_cons
|
||||
from sushy.resources.fabric import mappings as fab_maps
|
||||
from sushy.resources.fabric import constants as fab_cons
|
||||
from sushy.resources import ipaddresses
|
||||
from sushy import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
@@ -36,7 +37,7 @@ class IPv4AddressField(base.CompositeField):
|
||||
"""This is the IPv4 Subnet mask."""
|
||||
|
||||
address_origin = base.MappedField('AddressOrigin',
|
||||
fab_maps.ADDRESS_ORIGIN_IPv4_VALUE_MAP)
|
||||
ipaddresses.IPv4AddressOrigin)
|
||||
"""This indicates how the address was determined."""
|
||||
|
||||
|
||||
@@ -49,11 +50,10 @@ class IPv6AddressField(base.CompositeField):
|
||||
"""This is the IPv6 Address Prefix Length."""
|
||||
|
||||
address_origin = base.MappedField('AddressOrigin',
|
||||
fab_maps.ADDRESS_ORIGIN_IPv6_VALUE_MAP)
|
||||
ipaddresses.IPv6AddressOrigin)
|
||||
"""This indicates how the address was determined."""
|
||||
|
||||
address_state = base.MappedField('AddressState',
|
||||
fab_maps.ADDRESS_STATE_VALUE_MAP)
|
||||
address_state = base.MappedField('AddressState', ipaddresses.AddressState)
|
||||
"""The current state of this address as defined in RFC 4862."""
|
||||
|
||||
|
||||
@@ -111,12 +111,10 @@ class ConnectedEntitiesListField(base.ListField):
|
||||
identifiers = common.IdentifiersListField('Identifiers', default=[])
|
||||
"""Identifiers for the remote entity."""
|
||||
|
||||
entity_role = base.MappedField('EntityRole',
|
||||
fab_maps.ENTITY_ROLE_VALUE_MAP)
|
||||
entity_role = base.MappedField('EntityRole', fab_cons.EntityRole)
|
||||
"""The role of the connected entity."""
|
||||
|
||||
entity_type = base.MappedField('EntityType',
|
||||
fab_maps.ENTITY_TYPE_VALUE_MAP)
|
||||
entity_type = base.MappedField('EntityType', fab_cons.EntityType)
|
||||
"""The type of the connected entity."""
|
||||
|
||||
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
# Copyright 2017 Red Hat, 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.
|
||||
|
||||
from sushy.resources.fabric import constants as fab_cons
|
||||
from sushy import utils
|
||||
|
||||
ADDRESS_ORIGIN_IPv4_VALUE_MAP = {
|
||||
'BOOTP': fab_cons.ADDRESS_ORIGIN_IPv4_BOOTP,
|
||||
'DHCP': fab_cons.ADDRESS_ORIGIN_IPv4_DHCP,
|
||||
'IPv4LinkLocal': fab_cons.ADDRESS_ORIGIN_IPv4_IPv4LINKLOCAL,
|
||||
'Static': fab_cons.ADDRESS_ORIGIN_IPv4_STATIC,
|
||||
}
|
||||
|
||||
|
||||
ADDRESS_ORIGIN_IPv6_VALUE_MAP = {
|
||||
'DHCPv6': fab_cons.ADDRESS_ORIGIN_IPv6_DHCPv6,
|
||||
'LinkLocal': fab_cons.ADDRESS_ORIGIN_IPv6_LINKLOCAL,
|
||||
'SLAAC': fab_cons.ADDRESS_ORIGIN_IPv6_SLAAC,
|
||||
'Static': fab_cons.ADDRESS_ORIGIN_IPv6_STATIC,
|
||||
}
|
||||
|
||||
|
||||
ADDRESS_STATE_VALUE_MAP = {
|
||||
'Deprecated': fab_cons.ADDRESS_STATE_DEPRECATED,
|
||||
'Failed': fab_cons.ADDRESS_STATE_FAILED,
|
||||
'Preferred': fab_cons.ADDRESS_STATE_PREFERRED,
|
||||
'Tentative': fab_cons.ADDRESS_STATE_TENTATIVE,
|
||||
}
|
||||
|
||||
|
||||
ENTITY_ROLE_VALUE_MAP = {
|
||||
'Both': fab_cons.ENTITY_ROLE_BOTH,
|
||||
'Initiator': fab_cons.ENTITY_ROLE_INITIATOR,
|
||||
'Target': fab_cons.ENTITY_ROLE_TARGET,
|
||||
}
|
||||
|
||||
ENTITY_ROLE_VALUE_MAP_REV = utils.revert_dictionary(ENTITY_ROLE_VALUE_MAP)
|
||||
|
||||
|
||||
ENTITY_TYPE_VALUE_MAP = {
|
||||
'Bridge': fab_cons.ENTITY_TYPE_PCI_BRIDGE,
|
||||
'DisplayController': fab_cons.ENTITY_TYPE_DISPLAY_CONTROLLER,
|
||||
'Drive': fab_cons.ENTITY_TYPE_DRIVE,
|
||||
'NetworkController': fab_cons.ENTITY_TYPE_NETWORK_CONTROLLER,
|
||||
'Processor': fab_cons.ENTITY_TYPE_PROCESSOR,
|
||||
'RootComplex': fab_cons.ENTITY_TYPE_ROOT_COMPLEX,
|
||||
'StorageExpander': fab_cons.ENTITY_TYPE_STORAGE_EXPANDER,
|
||||
'StorageInitiator': fab_cons.ENTITY_TYPE_STORAGE_INITIATOR,
|
||||
'Volume': fab_cons.ENTITY_TYPE_VOLUME,
|
||||
}
|
||||
|
||||
ENTITY_TYPE_VALUE_MAP_REV = utils.revert_dictionary(ENTITY_TYPE_VALUE_MAP)
|
||||
83
sushy/resources/ipaddresses.py
Normal file
83
sushy/resources/ipaddresses.py
Normal file
@@ -0,0 +1,83 @@
|
||||
# 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.
|
||||
|
||||
# Values come from the Redfish json-schema:
|
||||
# https://redfish.dmtf.org/schemas/v1/IPAddresses.v1_1_3.json
|
||||
|
||||
import enum
|
||||
|
||||
|
||||
class AddressState(enum.Enum):
|
||||
PREFERRED = 'Preferred'
|
||||
"""This address is currently within both its RFC4862-defined valid and
|
||||
preferred lifetimes."""
|
||||
|
||||
DEPRECATED = 'Deprecated'
|
||||
"""This address is currently within its valid lifetime but is now
|
||||
outside its RFC4862-defined preferred lifetime."""
|
||||
|
||||
TENTATIVE = 'Tentative'
|
||||
"""This address is currently undergoing Duplicate Address Detection
|
||||
(DAD) testing, as defined in RFC4862, section 5.4."""
|
||||
|
||||
FAILED = 'Failed'
|
||||
"""This address has failed Duplicate Address Detection (DAD) testing, as
|
||||
defined in RFC4862, section 5.4, and is not currently in use."""
|
||||
|
||||
|
||||
# Backward compatibility
|
||||
ADDRESS_STATE_PREFERRED = AddressState.PREFERRED
|
||||
ADDRESS_STATE_DEPRECATED = AddressState.DEPRECATED
|
||||
ADDRESS_STATE_TENTATIVE = AddressState.TENTATIVE
|
||||
ADDRESS_STATE_FAILED = AddressState.FAILED
|
||||
|
||||
|
||||
class IPv4AddressOrigin(enum.Enum):
|
||||
STATIC = 'Static'
|
||||
"""A user-configured static address."""
|
||||
|
||||
DHCP = 'DHCP'
|
||||
"""A DHCPv4 service-provided address."""
|
||||
|
||||
BOOTP = 'BOOTP'
|
||||
"""A BOOTP service-provided address."""
|
||||
|
||||
LINK_LOCAL = 'IPv4LinkLocal'
|
||||
"""The address is valid for only this network segment, or link."""
|
||||
|
||||
|
||||
# Backward compatibility
|
||||
ADDRESS_ORIGIN_IPv4_BOOTP = IPv4AddressOrigin.BOOTP
|
||||
ADDRESS_ORIGIN_IPv4_DHCP = IPv4AddressOrigin.DHCP
|
||||
ADDRESS_ORIGIN_IPv4_IPv4LINKLOCAL = IPv4AddressOrigin.LINK_LOCAL
|
||||
ADDRESS_ORIGIN_IPv4_STATIC = IPv4AddressOrigin.STATIC
|
||||
|
||||
|
||||
class IPv6AddressOrigin(enum.Enum):
|
||||
STATIC = 'Static'
|
||||
"""A static user-configured address."""
|
||||
|
||||
DHCP = 'DHCPv6'
|
||||
"""A DHCPv6 service-provided address."""
|
||||
|
||||
LINK_LOCAL = 'LinkLocal'
|
||||
"""The address is valid for only this network segment, or link."""
|
||||
|
||||
SLAAC = 'SLAAC'
|
||||
"""A stateless autoconfiguration (SLAAC) service-provided address."""
|
||||
|
||||
|
||||
# Backward compatibility
|
||||
ADDRESS_ORIGIN_IPv6_DHCPv6 = IPv6AddressOrigin.DHCP
|
||||
ADDRESS_ORIGIN_IPv6_LINKLOCAL = IPv6AddressOrigin.LINK_LOCAL
|
||||
ADDRESS_ORIGIN_IPv6_SLAAC = IPv6AddressOrigin.SLAAC
|
||||
ADDRESS_ORIGIN_IPv6_STATIC = IPv6AddressOrigin.STATIC
|
||||
@@ -40,12 +40,12 @@ class EndpointTestCase(base.TestCase):
|
||||
self.assertEqual('SAS Drive', self.fab_endpoint.name)
|
||||
self.assertEqual(sushy.Protocol.SAS,
|
||||
self.fab_endpoint.endpoint_protocol)
|
||||
self.assertEqual(sushy.ENTITY_TYPE_DRIVE,
|
||||
self.assertEqual(sushy.EntityType.DRIVE,
|
||||
self.fab_endpoint.connected_entities[0].entity_type)
|
||||
self.assertEqual(sushy.ENTITY_ROLE_TARGET,
|
||||
self.assertEqual(sushy.EntityRole.TARGET,
|
||||
self.fab_endpoint.connected_entities[0].entity_role)
|
||||
con_entity = self.fab_endpoint.connected_entities[0]
|
||||
self.assertEqual(sushy.DURABLE_NAME_FORMAT_NAA,
|
||||
self.assertEqual(sushy.DurableNameFormat.NAA,
|
||||
con_entity.identifiers[0].durable_name_format)
|
||||
self.assertEqual('32ADF365C6C1B7C3',
|
||||
con_entity.identifiers[0].durable_name)
|
||||
|
||||
Reference in New Issue
Block a user