Refactor telemetry definition

Merged all kinds of telemetry definition variables into one single
class instead of separate files.

Change-Id: Id772b370019af958413390484e1a0166c34ebfef
This commit is contained in:
Lin Yang
2018-03-01 16:10:54 -08:00
parent ee5fd7db53
commit 3a1ba6be7a
10 changed files with 285 additions and 426 deletions

View File

@@ -1,46 +0,0 @@
# 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.
from sushy.resources import base
class CPUBandwidth(base.ResourceBase):
name = base.Field('Name')
"""The CPUHealth metric definition name"""
identity = base.Field('Id', required=True)
"""The CPUHealth metric definition identity string"""
metric_type = base.Field('MetricType')
"""The type of metric"""
implementation = base.Field('Implementation')
"""The implementation type of sensor"""
sensing_interval = base.Field('SensingInterval')
"""The sensing interval"""
physical_context = base.Field('PhysicalContext')
"""The physical context of this metric definition"""
units = base.Field('Units')
"""The units of the sensor"""
min_reading_range = base.Field('MinReadingRange')
"""The min reading range of this sensor"""
max_reading_range = base.Field('MaxReadingRange')
"""The max reading range of this sensor"""

View File

@@ -1,43 +0,0 @@
# 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.
from sushy.resources import base
class CPUHealth(base.ResourceBase):
name = base.Field('Name')
"""The CPUHealth metric definition name"""
identity = base.Field('Id', required=True)
"""The CPUHealth metric definition identity string"""
metric_type = base.Field('MetricType')
"""The type of metric"""
sensor_type = base.Field('SensorType')
"""The type of sensor"""
implementation = base.Field('Implementation')
"""The implementation type of sensor"""
sensing_interval = base.Field('SensingInterval')
"""The sensing interval"""
physical_context = base.Field('PhysicalContext')
"""The physical context of this metric definition"""
discrete_values = base.Field('DiscreteValues', adapter=list)
"""The allowed discrete values"""

View File

@@ -1,55 +0,0 @@
# 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.
from sushy.resources import base
class CPUTemperature(base.ResourceBase):
name = base.Field('Name')
"""The CPUHealth metric definition name"""
identity = base.Field('Id', required=True)
"""The CPUHealth metric definition identity string"""
metric_type = base.Field('MetricType')
"""The type of metric"""
sensor_type = base.Field('SensorType')
"""The type of sensor"""
implementation = base.Field('Implementation')
"""The implementation type of sensor"""
sensing_interval = base.Field('SensingInterval')
"""The sensing interval"""
physical_context = base.Field('PhysicalContext')
"""The physical context of this metric definition"""
units = base.Field('Units')
"""The units of the sensor"""
min_reading_range = base.Field('MinReadingRange', adapter=int)
"""The min reading range of this sensor"""
max_reading_range = base.Field('MaxReadingRange', adapter=int)
"""The max reading range of this sensor"""
precision = base.Field('Precision', adapter=int)
"""The precision of this sensor"""
calibration = base.Field('Calibration', adapter=int)
"""The calibration of this sensor"""

View File

@@ -13,61 +13,80 @@
# License for the specific language governing permissions and limitations
# under the License.
import os
from sushy.resources import base
from rsd_lib.resources.v2_2.telemetry.metric_definitions import cpu_bandwidth
from rsd_lib.resources.v2_2.telemetry.metric_definitions import cpu_health
from rsd_lib.resources.v2_2.telemetry.metric_definitions import cpu_temperature
class MetricDefinition(base.ResourceBase):
name = base.Field('Name')
"""The CPUHealth metric definition name"""
identity = base.Field('Id', required=True)
"""The CPUHealth metric definition identity string"""
sensor_type = base.Field('SensorType')
"""The type of sensor"""
metric_type = base.Field('MetricType')
"""The type of metric"""
implementation = base.Field('Implementation')
"""The implementation type of sensor"""
sensing_interval = base.Field('SensingInterval')
"""The sensing interval"""
physical_context = base.Field('PhysicalContext')
"""The physical context of this metric definition"""
units = base.Field('Units')
"""The units of the sensor"""
min_reading_range = base.Field('MinReadingRange')
"""The min reading range of this sensor"""
max_reading_range = base.Field('MaxReadingRange')
"""The max reading range of this sensor"""
discrete_values = base.Field('DiscreteValues', adapter=list)
"""The allowed discrete values"""
precision = base.Field('Precision')
"""The precision of the sensor"""
calibration = base.Field('Calibration')
"""The calibration of the sensor"""
isLinear = base.Field('IsLinear', adapter=bool)
"""The boolean indicate this sensor is linear or not"""
calculable = base.Field('Calculable', adapter=bool)
"""The variable indicate this sensor is calculable or not"""
data_type = base.Field('DataType')
"""The type of the sensor data"""
accuracy = base.Field('Accuracy')
"""The accuracy of the sensor"""
time_stamp_accuracy = base.Field('TimeStampAccuracy')
"""The time stamp accuracy of the sensor"""
calculation_time_interval = base.Field('CalculationTimeInterval')
"""The calculation time interval of the sensor"""
calculation_algorithm = base.Field('CalculationAlgorithm')
"""The calculation algorithm of the sensor"""
calculation_parameters = base.Field('CalculationParameters', adapter=list)
"""The calculation parameters of the sensor"""
wildcards = base.Field('Wildcards', adapter=list)
"""The wildcards of the sensor"""
class MetricDefinitionsCollection(base.ResourceCollectionBase):
def __init__(self, connector, path, redfish_version=None):
"""A class representing a MetricDefinitionsCollection
:param connector: A Connector instance
:param path: The canonical path to the MetricDefinitions
collection resource
:param redfish_version: The version of RedFish. Used to construct
the object according to schema of the given version.
"""
super(MetricDefinitionsCollection, self).__init__(
connector, path, redfish_version)
def _get_metric_definition_type(self, identity):
"""Get metric definition class
:param identity: The identity of the metric definition
:returns: The corresponding metric definition class
"""
metric_def_name = os.path.basename(identity)
if metric_def_name == 'CPUTemperature':
return cpu_temperature.CPUTemperature
elif metric_def_name == 'CPUHealth':
return cpu_health.CPUHealth
elif metric_def_name == 'CPUBandwidth':
return cpu_bandwidth.CPUBandwidth
else:
raise NotImplementedError(
'Metric definition {0} is not supported yet.'
.format(metric_def_name))
def get_member(self, identity):
"""Given the identity return a metric definition object
:param identity: The identity of the metric definition
:returns: The metric definition object
:raises: ResourceNotFoundError
"""
# return cpu_temperature.CPUTemperature(
# self._conn, identity, redfish_version=self.redfish_version)
metric_definition_type = self._get_metric_definition_type(identity)
return metric_definition_type(self._conn, identity,
redfish_version=self.redfish_version)
@property
def _resource_type(self):
pass
return MetricDefinition