Coverage for nova/objects/diagnostics.py: 100%
36 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 (c) 2014 VMware, Inc.
2# All Rights Reserved.
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
16from nova.objects import base
17from nova.objects import fields
20@base.NovaObjectRegistry.register
21class CpuDiagnostics(base.NovaObject):
23 # Version 1.0: Initial version
24 VERSION = '1.0'
26 fields = {
27 'id': fields.IntegerField(nullable=True),
28 'time': fields.IntegerField(nullable=True),
29 'utilisation': fields.IntegerField(nullable=True),
30 }
33@base.NovaObjectRegistry.register
34class NicDiagnostics(base.NovaObject):
36 # Version 1.0: Initial version
37 VERSION = '1.0'
39 fields = {
40 'mac_address': fields.MACAddressField(nullable=True),
41 'rx_octets': fields.IntegerField(nullable=True),
42 'rx_errors': fields.IntegerField(nullable=True),
43 'rx_drop': fields.IntegerField(nullable=True),
44 'rx_packets': fields.IntegerField(nullable=True),
45 'rx_rate': fields.IntegerField(nullable=True),
46 'tx_octets': fields.IntegerField(nullable=True),
47 'tx_errors': fields.IntegerField(nullable=True),
48 'tx_drop': fields.IntegerField(nullable=True),
49 'tx_packets': fields.IntegerField(nullable=True),
50 'tx_rate': fields.IntegerField(nullable=True)
51 }
54@base.NovaObjectRegistry.register
55class DiskDiagnostics(base.NovaObject):
57 # Version 1.0: Initial version
58 VERSION = '1.0'
60 fields = {
61 'read_bytes': fields.IntegerField(nullable=True),
62 'read_requests': fields.IntegerField(nullable=True),
63 'write_bytes': fields.IntegerField(nullable=True),
64 'write_requests': fields.IntegerField(nullable=True),
65 'errors_count': fields.IntegerField(nullable=True)
66 }
69@base.NovaObjectRegistry.register
70class MemoryDiagnostics(base.NovaObject):
72 # Version 1.0: Initial version
73 VERSION = '1.0'
75 fields = {
76 'maximum': fields.IntegerField(nullable=True),
77 'used': fields.IntegerField(nullable=True)
78 }
81@base.NovaObjectRegistry.register
82class Diagnostics(base.NovaEphemeralObject):
84 # Version 1.0: Initial version
85 VERSION = '1.0'
87 fields = {
88 'state': fields.InstancePowerStateField(),
89 'driver': fields.HypervisorDriverField(),
90 'hypervisor': fields.StringField(nullable=True),
91 'hypervisor_os': fields.StringField(nullable=True),
92 'uptime': fields.IntegerField(nullable=True),
93 'config_drive': fields.BooleanField(),
94 'memory_details': fields.ObjectField('MemoryDiagnostics',
95 default=MemoryDiagnostics()),
96 'cpu_details': fields.ListOfObjectsField('CpuDiagnostics', default=[]),
97 'nic_details': fields.ListOfObjectsField('NicDiagnostics', default=[]),
98 'disk_details': fields.ListOfObjectsField('DiskDiagnostics',
99 default=[]),
100 'num_cpus': fields.IntegerField(),
101 'num_nics': fields.IntegerField(),
102 'num_disks': fields.IntegerField()
103 }
105 def __init__(self, *args, **kwargs):
106 super(Diagnostics, self).__init__(*args, **kwargs)
108 self.num_cpus = len(self.cpu_details)
109 self.num_nics = len(self.nic_details)
110 self.num_disks = len(self.disk_details)
112 def add_cpu(self, id=None, time=None, utilisation=None):
113 """Add a new CpuDiagnostics object
115 :param id: The virtual cpu number (Integer)
116 :param time: CPU Time in nano seconds (Integer)
117 :param utilisation: CPU utilisation in percentages (Integer)
118 """
120 self.num_cpus += 1
121 self.cpu_details.append(
122 CpuDiagnostics(id=id, time=time, utilisation=utilisation))
124 def add_nic(self, mac_address=None, rx_octets=None, rx_errors=None,
125 rx_drop=None, rx_packets=None, rx_rate=None, tx_octets=None,
126 tx_errors=None, tx_drop=None, tx_packets=None, tx_rate=None):
127 """Add a new NicDiagnostics object
129 :param mac_address: Mac address of the interface (String)
130 :param rx_octets: Received octets (Integer)
131 :param rx_errors: Received errors (Integer)
132 :param rx_drop: Received packets dropped (Integer)
133 :param rx_packets: Received packets (Integer)
134 :param rx_rate: Receive rate (Integer)
135 :param tx_octets: Transmitted Octets (Integer)
136 :param tx_errors: Transmit errors (Integer)
137 :param tx_drop: Transmit dropped packets (Integer)
138 :param tx_packets: Transmit packets (Integer)
139 :param tx_rate: Transmit rate (Integer)
140 """
142 self.num_nics += 1
143 self.nic_details.append(NicDiagnostics(mac_address=mac_address,
144 rx_octets=rx_octets,
145 rx_errors=rx_errors,
146 rx_drop=rx_drop,
147 rx_packets=rx_packets,
148 rx_rate=rx_rate,
149 tx_octets=tx_octets,
150 tx_errors=tx_errors,
151 tx_drop=tx_drop,
152 tx_packets=tx_packets,
153 tx_rate=tx_rate))
155 def add_disk(self, read_bytes=None, read_requests=None, write_bytes=None,
156 write_requests=None, errors_count=None):
157 """Create a new DiskDiagnostics object
159 :param read_bytes: Disk reads in bytes(Integer)
160 :param read_requests: Read requests (Integer)
161 :param write_bytes: Disk writes in bytes (Integer)
162 :param write_requests: Write requests (Integer)
163 :param errors_count: Disk errors (Integer)
164 """
166 self.num_disks += 1
167 self.disk_details.append(DiskDiagnostics(read_bytes=read_bytes,
168 read_requests=read_requests,
169 write_bytes=write_bytes,
170 write_requests=write_requests,
171 errors_count=errors_count))