Added server diagnostics

This patch add get server diagnostics method.

Change-Id: I1f79db9faab4694b251465b456365a18ed94dfa7
This commit is contained in:
Yuval Shalev 2019-02-04 00:01:12 +02:00
parent 1d90876b58
commit dc092757d1
3 changed files with 159 additions and 0 deletions

View File

@ -19,6 +19,7 @@ from openstack.compute.v2 import image as _image
from openstack.compute.v2 import keypair as _keypair
from openstack.compute.v2 import limits
from openstack.compute.v2 import server as _server
from openstack.compute.v2 import server_diagnostics as _server_diagnostics
from openstack.compute.v2 import server_group as _server_group
from openstack.compute.v2 import server_interface as _server_interface
from openstack.compute.v2 import server_ip
@ -1466,3 +1467,20 @@ class Proxy(proxy.Proxy):
to delete failed to occur in the specified seconds.
"""
return resource.wait_for_delete(self, res, interval, wait)
def get_server_diagnostics(self, server):
"""Get a single server diagnostics
:param server: This parameter need to be specified when ServerInterface
ID is given as value. It can be either the ID of a
server or a :class:`~openstack.compute.v2.server.Server`
instance that the interface belongs to.
:returns: One
:class:`~openstack.compute.v2.server_diagnostics.ServerDiagnostics`
:raises: :class:`~openstack.exceptions.ResourceNotFound`
when no resource can be found.
"""
server_id = self._get_resource(_server.Server, server).id
return self._get(_server_diagnostics.ServerDiagnostics,
server_id=server_id, requires_id=False)

View File

@ -0,0 +1,52 @@
# 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 openstack import resource
class ServerDiagnostics(resource.Resource):
resource_key = 'diagnostics'
base_path = '/servers/%(server_id)s/diagnostics'
# capabilities
allow_fetch = True
requires_id = False
#: Indicates whether or not a config drive was used for this server.
has_config_drive = resource.Body('config_drive')
#: The current state of the VM.
state = resource.Body('state')
#: The driver on which the VM is running.
driver = resource.Body('driver')
#: The hypervisor on which the VM is running.
hypervisor = resource.Body('hypervisor')
#: The hypervisor OS.
hypervisor_os = resource.Body('hypervisor_os')
#: The amount of time in seconds that the VM has been running.
uptime = resource.URI('uptime')
#: The number of vCPUs.
num_cpus = resource.URI('num_cpus')
#: The number of disks.
num_disks = resource.URI('num_disks')
#: The number of vNICs.
num_nics = resource.URI('num_nics')
#: The dictionary with information about VM memory usage.
memory_details = resource.URI('memory_details')
#: The list of dictionaries with detailed information about VM CPUs.
cpu_details = resource.URI('cpu_details')
#: The list of dictionaries with detailed information about VM disks.
disk_details = resource.URI('disk_details')
#: The list of dictionaries with detailed information about VM NICs.
nic_details = resource.URI('nic_details')
#: The ID for the server.
server_id = resource.URI('server_id')

View File

@ -0,0 +1,89 @@
# 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 openstack.tests.unit import base
from openstack.compute.v2 import server_diagnostics
IDENTIFIER = 'IDENTIFIER'
EXAMPLE = {
"config_drive": True,
"cpu_details": [
{
"id": 0,
"time": 17300000000,
"utilisation": 15
}
],
"disk_details": [
{
"errors_count": 1,
"read_bytes": 262144,
"read_requests": 112,
"write_bytes": 5778432,
"write_requests": 488
}
],
"driver": "libvirt",
"hypervisor": "kvm",
"hypervisor_os": "ubuntu",
"memory_details": {
"maximum": 524288,
"used": 0
},
"nic_details": [
{
"mac_address": "01:23:45:67:89:ab",
"rx_drop": 200,
"rx_errors": 100,
"rx_octets": 2070139,
"rx_packets": 26701,
"rx_rate": 300,
"tx_drop": 500,
"tx_errors": 400,
"tx_octets": 140208,
"tx_packets": 662,
"tx_rate": 600
}
],
"num_cpus": 1,
"num_disks": 1,
"num_nics": 1,
"state": "running",
"uptime": 46664
}
class TestServerInterface(base.TestCase):
def test_basic(self):
sot = server_diagnostics.ServerDiagnostics()
self.assertEqual('diagnostics', sot.resource_key)
self.assertEqual('/servers/%(server_id)s/diagnostics', sot.base_path)
self.assertTrue(sot.allow_fetch)
self.assertFalse(sot.requires_id)
def test_make_it(self):
sot = server_diagnostics.ServerDiagnostics(**EXAMPLE)
self.assertEqual(EXAMPLE['config_drive'], sot.has_config_drive)
self.assertEqual(EXAMPLE['cpu_details'], sot.cpu_details)
self.assertEqual(EXAMPLE['disk_details'], sot.disk_details)
self.assertEqual(EXAMPLE['driver'], sot.driver)
self.assertEqual(EXAMPLE['hypervisor'], sot.hypervisor)
self.assertEqual(EXAMPLE['hypervisor_os'], sot.hypervisor_os)
self.assertEqual(EXAMPLE['memory_details'], sot.memory_details)
self.assertEqual(EXAMPLE['nic_details'], sot.nic_details)
self.assertEqual(EXAMPLE['num_cpus'], sot.num_cpus)
self.assertEqual(EXAMPLE['num_disks'], sot.num_disks)
self.assertEqual(EXAMPLE['num_nics'], sot.num_nics)
self.assertEqual(EXAMPLE['state'], sot.state)
self.assertEqual(EXAMPLE['uptime'], sot.uptime)