Add new adapter for int field
Add new adapter int_or_none, which allow the int field to be None. Change-Id: I200108aac951fb9e52f6977340a4870cee7f887b
This commit is contained in:
parent
45fc6a5074
commit
dda4c86b70
rsd_lib
@ -17,6 +17,8 @@ import logging
|
||||
|
||||
from sushy.resources import base
|
||||
|
||||
from rsd_lib import utils as rsd_lib_utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@ -71,7 +73,8 @@ class Switch(base.ResourceBase):
|
||||
is_managed = base.Field('IsManaged')
|
||||
"""The switch managed state"""
|
||||
|
||||
total_switch_width = base.Field('TotalSwitchWidth', adapter=int)
|
||||
total_switch_width = base.Field('TotalSwitchWidth',
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
"""The switch total switch width"""
|
||||
|
||||
indicator_led = base.Field('IndicatorLED')
|
||||
|
@ -27,19 +27,22 @@ class StatusField(base.CompositeField):
|
||||
|
||||
class GraphicalConsoleField(base.CompositeField):
|
||||
service_enabled = base.Field('ServiceEnabled')
|
||||
max_concurrent_sessions = base.Field('MaxConcurrentSessions', adapter=int)
|
||||
max_concurrent_sessions = base.Field('MaxConcurrentSessions',
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
connect_types_supported = base.Field('ConnectTypesSupported', adapter=list)
|
||||
|
||||
|
||||
class SerialConsoleField(base.CompositeField):
|
||||
service_enabled = base.Field('ServiceEnabled')
|
||||
max_concurrent_sessions = base.Field('MaxConcurrentSessions', adapter=int)
|
||||
max_concurrent_sessions = base.Field('MaxConcurrentSessions',
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
connect_types_supported = base.Field('ConnectTypesSupported', adapter=list)
|
||||
|
||||
|
||||
class CommandShellField(base.CompositeField):
|
||||
service_enabled = base.Field('ServiceEnabled')
|
||||
max_concurrent_sessions = base.Field('MaxConcurrentSessions', adapter=int)
|
||||
max_concurrent_sessions = base.Field('MaxConcurrentSessions',
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
connect_types_supported = base.Field('ConnectTypesSupported', adapter=list)
|
||||
|
||||
|
||||
|
@ -91,7 +91,8 @@ class MemorySummaryField(base.CompositeField):
|
||||
status = StatusField('Status')
|
||||
"""The memory status"""
|
||||
|
||||
size_gib = base.Field('TotalSystemMemoryGiB', adapter=int)
|
||||
size_gib = base.Field('TotalSystemMemoryGiB',
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
"""The size of memory of the node in GiB.
|
||||
|
||||
This signifies the total installed, operating system-accessible memory
|
||||
@ -103,7 +104,7 @@ class ProcessorSummaryField(base.CompositeField):
|
||||
status = StatusField('Status')
|
||||
"""The processor status"""
|
||||
|
||||
count = base.Field('Count', adapter=int)
|
||||
count = base.Field('Count', adapter=rsd_lib_utils.int_or_none)
|
||||
"""The number of CPUs in the node."""
|
||||
|
||||
model = base.Field('Model')
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
from sushy.resources import base
|
||||
|
||||
from rsd_lib import utils as rsd_lib_utils
|
||||
|
||||
|
||||
class MemoryLocationField(base.CompositeField):
|
||||
socket = base.Field('Socket', required=int)
|
||||
@ -49,13 +51,15 @@ class Memory(base.ResourceBase):
|
||||
memory_media = base.Field('MemoryMedia', adapter=list)
|
||||
"""The memory media"""
|
||||
|
||||
capacity_mib = base.Field('CapacityMiB', adapter=int)
|
||||
capacity_mib = base.Field('CapacityMiB', adapter=rsd_lib_utils.int_or_none)
|
||||
"""The capacity of this memory in MiB"""
|
||||
|
||||
data_width_bits = base.Field('DataWidthBits', adapter=int)
|
||||
data_width_bits = base.Field('DataWidthBits',
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
"""The data width bits of this memory."""
|
||||
|
||||
bus_width_bits = base.Field('BusWidthBits', adapter=int)
|
||||
bus_width_bits = base.Field('BusWidthBits',
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
"""The bus width bits of this memory."""
|
||||
|
||||
manufacturer = base.Field('Manufacturer')
|
||||
@ -85,7 +89,8 @@ class Memory(base.ResourceBase):
|
||||
device_id = base.Field('DeviceID')
|
||||
"""The device identity"""
|
||||
|
||||
rank_count = base.Field('RankCount', adapter=int)
|
||||
rank_count = base.Field('RankCount',
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
"""The rank count of this memory"""
|
||||
|
||||
device_locator = base.Field('DeviceLocator')
|
||||
@ -94,7 +99,8 @@ class Memory(base.ResourceBase):
|
||||
error_correction = base.Field('ErrorCorrection')
|
||||
"""The error correction"""
|
||||
|
||||
operating_speed_mhz = base.Field('OperatingSpeedMhz', adapter=int)
|
||||
operating_speed_mhz = base.Field('OperatingSpeedMhz',
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
"""The operating speed of this memory in MHz"""
|
||||
|
||||
operating_memory_modes = base.Field('OperatingMemoryModes', adapter=list)
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
from sushy.resources import base
|
||||
|
||||
from rsd_lib import utils as rsd_lib_utils
|
||||
|
||||
|
||||
class MemoryMetrics(base.ResourceBase):
|
||||
|
||||
@ -28,7 +30,8 @@ class MemoryMetrics(base.ResourceBase):
|
||||
"""The metrics identity"""
|
||||
|
||||
temperature_celsius = base.Field(
|
||||
['Oem', 'Intel_RackScale', 'TemperatureCelsius'], adapter=int)
|
||||
['Oem', 'Intel_RackScale', 'TemperatureCelsius'],
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
"""The memory temperature celsius"""
|
||||
|
||||
health = base.Field(['Oem', 'Intel_RackScale', 'Health'], adapter=list)
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
from sushy.resources import base
|
||||
|
||||
from rsd_lib import utils as rsd_lib_utils
|
||||
|
||||
|
||||
class Metrics(base.ResourceBase):
|
||||
name = base.Field('Name')
|
||||
@ -27,24 +29,27 @@ class Metrics(base.ResourceBase):
|
||||
"""The metrics identity"""
|
||||
|
||||
processor_bandwidth_percent = base.Field('ProcessorBandwidthPercent',
|
||||
adapter=int)
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
"""The processor bandwidth percent"""
|
||||
|
||||
memory_bandwidth_percent = base.Field('MemoryBandwidthPercent',
|
||||
adapter=int)
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
"""The memory bandwidth percent"""
|
||||
|
||||
memory_throttled_cycles_percent = base.Field(
|
||||
'MemoryThrottledCyclesPercent', adapter=int)
|
||||
'MemoryThrottledCyclesPercent', adapter=rsd_lib_utils.int_or_none)
|
||||
"""The memory throttled cycles percent"""
|
||||
|
||||
processor_power_watt = base.Field('ProcessorPowerWatt', adapter=int)
|
||||
processor_power_watt = base.Field('ProcessorPowerWatt',
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
"""The processor power watt"""
|
||||
|
||||
memory_power_watt = base.Field('MemoryPowerWatt', adapter=int)
|
||||
memory_power_watt = base.Field('MemoryPowerWatt',
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
"""The memory power watt"""
|
||||
|
||||
io_bandwidth_gbps = base.Field('IOBandwidthGBps', adapter=int)
|
||||
io_bandwidth_gbps = base.Field('IOBandwidthGBps',
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
"""The io bandwidth GBps"""
|
||||
|
||||
health = base.Field('Health', adapter=list)
|
||||
|
@ -15,6 +15,8 @@
|
||||
|
||||
from sushy.resources import base
|
||||
|
||||
from rsd_lib import utils as rsd_lib_utils
|
||||
|
||||
|
||||
class ProcessorMetrics(base.ResourceBase):
|
||||
name = base.Field('Name')
|
||||
@ -26,16 +28,20 @@ class ProcessorMetrics(base.ResourceBase):
|
||||
identity = base.Field('Id')
|
||||
"""The metrics identity"""
|
||||
|
||||
average_frequency_mhz = base.Field('AverageFrequencyMHz', adapter=int)
|
||||
average_frequency_mhz = base.Field('AverageFrequencyMHz',
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
"""The processor average frequency mhz"""
|
||||
|
||||
throttling_celsius = base.Field('ThrottlingCelsius', adapter=int)
|
||||
throttling_celsius = base.Field('ThrottlingCelsius',
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
"""The processor throttling celsius"""
|
||||
|
||||
temperature_celsius = base.Field('TemperatureCelsius', adapter=int)
|
||||
temperature_celsius = base.Field('TemperatureCelsius',
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
"""The processor temperature celsius"""
|
||||
|
||||
consumed_power_watt = base.Field('ConsumedPowerWatt', adapter=int)
|
||||
consumed_power_watt = base.Field('ConsumedPowerWatt',
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
"""The processor consumed power watt"""
|
||||
|
||||
health = base.Field('Health', adapter=list)
|
||||
|
@ -57,7 +57,7 @@ class IPTransportDetailsField(base.ListField):
|
||||
transport_protocol = base.Field('TransportProtocol')
|
||||
ipv4_address = base.Field(['IPv4Address', 'Address'])
|
||||
ipv6_address = base.Field(['IPv6Address', 'Address'])
|
||||
port = base.Field('Port', adapter=int)
|
||||
port = base.Field('Port', adapter=rsd_lib_utils.int_or_none)
|
||||
|
||||
|
||||
class AuthenticationField(base.CompositeField):
|
||||
|
@ -80,7 +80,8 @@ class Drive(base.ResourceBase):
|
||||
media_type = base.Field('MediaType')
|
||||
"""The media type of this drive"""
|
||||
|
||||
capacity_bytes = base.Field('CapacityBytes')
|
||||
capacity_bytes = base.Field('CapacityBytes',
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
"""The capacity in Bytes of this drive"""
|
||||
|
||||
manufacturer = base.Field('Manufacturer')
|
||||
|
@ -33,10 +33,14 @@ class StatusField(base.CompositeField):
|
||||
|
||||
|
||||
class CapacityField(base.CompositeField):
|
||||
allocated_bytes = base.Field(['Data', 'AllocatedBytes'], adapter=int)
|
||||
consumed_bytes = base.Field(['Data', 'ConsumedBytes'], adapter=int)
|
||||
guaranteed_bytes = base.Field(['Data', 'GuaranteedBytes'], adapter=int)
|
||||
provisioned_bytes = base.Field(['Data', 'ProvisionedBytes'], adapter=int)
|
||||
allocated_bytes = base.Field(['Data', 'AllocatedBytes'],
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
consumed_bytes = base.Field(['Data', 'ConsumedBytes'],
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
guaranteed_bytes = base.Field(['Data', 'GuaranteedBytes'],
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
provisioned_bytes = base.Field(['Data', 'ProvisionedBytes'],
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
|
||||
|
||||
class CapacitySourcesField(base.ListField):
|
||||
|
@ -36,7 +36,8 @@ class CapacitySourcesField(base.ListField):
|
||||
providing_pools = base.Field('ProvidingPools',
|
||||
adapter=utils.get_members_identities)
|
||||
allocated_Bytes = base.Field(
|
||||
['ProvidedCapacity', 'Data', 'AllocatedBytes'], adapter=int)
|
||||
['ProvidedCapacity', 'Data', 'AllocatedBytes'],
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
|
||||
|
||||
class LinksField(base.CompositeField):
|
||||
@ -90,11 +91,12 @@ class Volume(base.ResourceBase):
|
||||
access_capabilities = base.Field('AccessCapabilities', adapter=list)
|
||||
"""The access capabilities of volume"""
|
||||
|
||||
capacity_bytes = base.Field('CapacityBytes', adapter=int)
|
||||
capacity_bytes = base.Field('CapacityBytes',
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
"""The capacity of volume in bytes"""
|
||||
|
||||
allocated_Bytes = base.Field(['Capacity', 'Data', 'AllocatedBytes'],
|
||||
adapter=int)
|
||||
adapter=rsd_lib_utils.int_or_none)
|
||||
"""The allocated capacity of volume in bytes"""
|
||||
|
||||
capacity_sources = CapacitySourcesField('CapacitySources')
|
||||
|
34
rsd_lib/tests/unit/test_utils.py
Normal file
34
rsd_lib/tests/unit/test_utils.py
Normal file
@ -0,0 +1,34 @@
|
||||
# Copyright 2018 Intel, 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 testtools
|
||||
|
||||
from rsd_lib import utils as rsd_lib_utils
|
||||
|
||||
|
||||
class UtilsTestCase(testtools.TestCase):
|
||||
|
||||
def test_get_resource_identity(self):
|
||||
self.assertIsNone(rsd_lib_utils.get_resource_identity(None))
|
||||
self.assertIsNone(rsd_lib_utils.get_resource_identity({}))
|
||||
self.assertEqual(
|
||||
'/redfish/v1/Systems/437XR1138R2/BIOS',
|
||||
rsd_lib_utils.get_resource_identity({
|
||||
"@odata.id": "/redfish/v1/Systems/437XR1138R2/BIOS"}))
|
||||
|
||||
def test_int_or_none(self):
|
||||
self.assertIsNone(rsd_lib_utils.int_or_none(None))
|
||||
self.assertEqual(0, rsd_lib_utils.int_or_none('0'))
|
||||
self.assertEqual(1, rsd_lib_utils.int_or_none('1'))
|
@ -18,4 +18,16 @@ def get_resource_identity(resource):
|
||||
if resource is None:
|
||||
return None
|
||||
else:
|
||||
return resource.get('@odata.id')
|
||||
return resource.get('@odata.id', None)
|
||||
|
||||
|
||||
def int_or_none(x):
|
||||
"""Given a value x it cast as int or None
|
||||
|
||||
:param x: The value to transform and return
|
||||
:returns: Either None or x cast to an int
|
||||
|
||||
"""
|
||||
if x is None:
|
||||
return None
|
||||
return int(x)
|
||||
|
Loading…
x
Reference in New Issue
Block a user