Merge "Adds MonitorMetric object"
This commit is contained in:
commit
ab5d3387bf
@ -48,6 +48,7 @@ def register_all():
|
||||
__import__('nova.objects.instance_pci_requests')
|
||||
__import__('nova.objects.keypair')
|
||||
__import__('nova.objects.migration')
|
||||
__import__('nova.objects.monitor_metric')
|
||||
__import__('nova.objects.network')
|
||||
__import__('nova.objects.network_request')
|
||||
__import__('nova.objects.numa')
|
||||
|
62
nova/objects/monitor_metric.py
Normal file
62
nova/objects/monitor_metric.py
Normal file
@ -0,0 +1,62 @@
|
||||
# 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 oslo_utils import timeutils
|
||||
|
||||
from nova.objects import base
|
||||
from nova.objects import fields
|
||||
|
||||
|
||||
@base.NovaObjectRegistry.register
|
||||
class MonitorMetric(base.NovaObject):
|
||||
# Version 1.0: Initial version
|
||||
VERSION = '1.0'
|
||||
|
||||
fields = {
|
||||
'name': fields.MonitorMetricTypeField(nullable=False),
|
||||
'value': fields.IntegerField(nullable=False),
|
||||
'timestamp': fields.DateTimeField(nullable=False),
|
||||
# This will be the stevedore extension full class name
|
||||
# for the plugin from which the metric originates.
|
||||
'source': fields.StringField(nullable=False),
|
||||
}
|
||||
|
||||
# NOTE(jaypipes): This method exists to convert the object to the
|
||||
# format expected by the RPC notifier for metrics events.
|
||||
def to_dict(self):
|
||||
return {
|
||||
'name': self.name,
|
||||
'value': self.value,
|
||||
# NOTE(jaypipes): This is what jsonutils.dumps() does to
|
||||
# datetime.datetime objects, which is what timestamp is in
|
||||
# this object as well as the original simple dict metrics
|
||||
'timestamp': timeutils.strtime(self.timestamp),
|
||||
'source': self.source
|
||||
}
|
||||
|
||||
|
||||
@base.NovaObjectRegistry.register
|
||||
class MonitorMetricList(base.ObjectListBase, base.NovaObject):
|
||||
# Version 1.0: Initial version
|
||||
VERSION = '1.0'
|
||||
|
||||
fields = {
|
||||
'objects': fields.ListOfObjectsField('MonitorMetric'),
|
||||
}
|
||||
child_versions = {
|
||||
'1.0': '1.0',
|
||||
}
|
||||
|
||||
# NOTE(jaypipes): This method exists to convert the object to the
|
||||
# format expected by the RPC notifier for metrics events.
|
||||
def to_list(self):
|
||||
return [m.to_dict() for m in self.objects]
|
55
nova/tests/unit/objects/test_monitor_metric.py
Normal file
55
nova/tests/unit/objects/test_monitor_metric.py
Normal file
@ -0,0 +1,55 @@
|
||||
# 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 oslo_utils import timeutils
|
||||
|
||||
from nova import objects
|
||||
from nova.objects import fields
|
||||
from nova.tests.unit.objects import test_objects
|
||||
|
||||
_ts_now = timeutils.utcnow()
|
||||
|
||||
_monitor_metric_spec = {
|
||||
'name': fields.MonitorMetricType.CPU_FREQUENCY,
|
||||
'value': 1000,
|
||||
'timestamp': timeutils.strtime(_ts_now),
|
||||
'source': 'nova.virt.libvirt.driver'
|
||||
}
|
||||
|
||||
_monitor_metric_list_spec = [_monitor_metric_spec]
|
||||
|
||||
|
||||
class _TestMonitorMetricObject(object):
|
||||
def test_monitor_metric_to_dict(self):
|
||||
obj = objects.MonitorMetric(name='cpu.frequency',
|
||||
value=1000,
|
||||
timestamp=_ts_now,
|
||||
source='nova.virt.libvirt.driver')
|
||||
self.assertEqual(_monitor_metric_spec, obj.to_dict())
|
||||
|
||||
def test_monitor_metric_list_to_list(self):
|
||||
obj = objects.MonitorMetric(name='cpu.frequency',
|
||||
value=1000,
|
||||
timestamp=_ts_now,
|
||||
source='nova.virt.libvirt.driver')
|
||||
list_obj = objects.MonitorMetricList(objects=[obj])
|
||||
self.assertEqual(_monitor_metric_list_spec, list_obj.to_list())
|
||||
|
||||
|
||||
class TestMonitorMetricObject(test_objects._LocalTest,
|
||||
_TestMonitorMetricObject):
|
||||
pass
|
||||
|
||||
|
||||
class TestRemoteMonitorMetricObject(test_objects._RemoteTest,
|
||||
_TestMonitorMetricObject):
|
||||
pass
|
@ -1101,6 +1101,8 @@ object_data = {
|
||||
'KeyPairList': '1.2-60f984184dc5a8eba6e34e20cbabef04',
|
||||
'Migration': '1.2-331b1f37d0b20b932614181b9832c860',
|
||||
'MigrationList': '1.2-5e79c0693d7ebe4e9ac03b5db11ab243',
|
||||
'MonitorMetric': '1.0-4fe7f3fb1777567883ac842120ec5800',
|
||||
'MonitorMetricList': '1.0-1b54e51ad0fc1f3a8878f5010e7e16dc',
|
||||
'NUMACell': '1.2-74fc993ac5c83005e76e34e8487f1c05',
|
||||
'NUMAPagesTopology': '1.0-c71d86317283266dc8364c149155e48e',
|
||||
'NUMATopology': '1.2-c63fad38be73b6afd04715c9c1b29220',
|
||||
@ -1173,6 +1175,7 @@ object_relationships = {
|
||||
'InstancePCIRequests': {'InstancePCIRequest': '1.1'},
|
||||
'KeyPairList': {'KeyPair': '1.3'},
|
||||
'MigrationList': {'Migration': '1.2'},
|
||||
'MonitorMetricList': {'MonitorMetric': '1.0'},
|
||||
'NetworkList': {'Network': '1.2'},
|
||||
'NetworkRequestList': {'NetworkRequest': '1.1'},
|
||||
'NUMACell': {'NUMAPagesTopology': '1.0'},
|
||||
|
Loading…
x
Reference in New Issue
Block a user