Coverage for nova/notifications/objects/metrics.py: 62%
32 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-04-17 15:08 +0000
« prev ^ index » next coverage.py v7.6.12, created at 2025-04-17 15:08 +0000
1# Copyright 2018 NTT Corporation
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
15from nova.notifications.objects import base
16from nova.objects import base as nova_base
17from nova.objects import fields
20@base.notification_sample('metrics-update.json')
21@nova_base.NovaObjectRegistry.register_notification
22class MetricsNotification(base.NotificationBase):
23 # Version 1.0: Initial version
24 VERSION = '1.0'
26 fields = {
27 'payload': fields.ObjectField('MetricsPayload')
28 }
31@nova_base.NovaObjectRegistry.register_notification
32class MetricPayload(base.NotificationPayloadBase):
33 # Version 1.0: Initial version
34 VERSION = '1.0'
36 SCHEMA = {
37 'name': ('monitor_metric', 'name'),
38 'value': ('monitor_metric', 'value'),
39 'numa_membw_values': ('monitor_metric', 'numa_membw_values'),
40 'timestamp': ('monitor_metric', 'timestamp'),
41 'source': ('monitor_metric', 'source'),
42 }
44 fields = {
45 'name': fields.MonitorMetricTypeField(),
46 'value': fields.IntegerField(),
47 'numa_membw_values': fields.DictOfIntegersField(nullable=True),
48 'timestamp': fields.DateTimeField(),
49 'source': fields.StringField(),
50 }
52 def __init__(self, monitor_metric):
53 super(MetricPayload, self).__init__()
54 self.populate_schema(monitor_metric=monitor_metric)
56 @classmethod
57 def from_monitor_metric_list_obj(cls, monitor_metric_list):
58 """Returns a list of MetricPayload objects based on the passed
59 MonitorMetricList object.
60 """
61 payloads = []
62 for monitor_metric in monitor_metric_list:
63 payloads.append(cls(monitor_metric))
64 return payloads
67@nova_base.NovaObjectRegistry.register_notification
68class MetricsPayload(base.NotificationPayloadBase):
69 # Version 1.0: Initial version
70 VERSION = '1.0'
72 fields = {
73 'host': fields.StringField(),
74 'host_ip': fields.StringField(),
75 'nodename': fields.StringField(),
76 'metrics': fields.ListOfObjectsField('MetricPayload'),
77 }
79 def __init__(self, host, host_ip, nodename, monitor_metric_list):
80 super(MetricsPayload, self).__init__()
81 self.host = host
82 self.host_ip = host_ip
83 self.nodename = nodename
84 self.metrics = MetricPayload.from_monitor_metric_list_obj(
85 monitor_metric_list)