Merge "rt: Implement XenAPI get_inventory() method"

This commit is contained in:
Zuul
2017-10-27 22:12:37 +00:00
committed by Gerrit Code Review
2 changed files with 64 additions and 0 deletions

View File

@@ -24,6 +24,7 @@ from nova.virt import driver
from nova.virt import fake
from nova.virt import xenapi
from nova.virt.xenapi import driver as xenapi_driver
from nova.virt.xenapi import host
class XenAPIDriverTestCase(stubs.XenAPITestBaseNoDB):
@@ -235,3 +236,33 @@ class XenAPIDriverTestCase(stubs.XenAPITestBaseNoDB):
mock_rollback.assert_called_once_with('fake_instance',
'fake_network_info',
'fake_block_device')
@mock.patch.object(host.HostState, 'get_host_stats')
def test_get_inventory(self, mock_get_stats):
expected_inv = {
obj_fields.ResourceClass.VCPU: {
'total': 50,
'min_unit': 1,
'max_unit': 50,
'step_size': 1,
},
obj_fields.ResourceClass.MEMORY_MB: {
'total': 3,
'min_unit': 1,
'max_unit': 3,
'step_size': 1,
},
obj_fields.ResourceClass.DISK_GB: {
'total': 5,
'min_unit': 1,
'max_unit': 5,
'step_size': 1,
},
}
mock_get_stats.side_effect = self.host_stats
drv = self._get_driver()
inv = drv.get_inventory(mock.sentinel.nodename)
mock_get_stats.assert_called_once_with(refresh=True)
self.assertEqual(expected_inv, inv)

View File

@@ -36,6 +36,7 @@ import six.moves.urllib.parse as urlparse
import nova.conf
from nova import exception
from nova.i18n import _
from nova.objects import fields
from nova.virt import driver
from nova.virt.xenapi import host
from nova.virt.xenapi import pool
@@ -403,6 +404,38 @@ class XenAPIDriver(driver.ComputeDriver):
'username': CONF.xenserver.connection_username,
'password': CONF.xenserver.connection_password}
def get_inventory(self, nodename):
"""Return a dict, keyed by resource class, of inventory information for
the supplied node.
"""
host_stats = self.host_state.get_host_stats(refresh=True)
vcpus = host_stats['host_cpu_info']['cpu_count']
memory_mb = int(host_stats['host_memory_total'] / units.Mi)
disk_gb = int(host_stats['disk_total'] / units.Gi)
result = {
fields.ResourceClass.VCPU: {
'total': vcpus,
'min_unit': 1,
'max_unit': vcpus,
'step_size': 1,
},
fields.ResourceClass.MEMORY_MB: {
'total': memory_mb,
'min_unit': 1,
'max_unit': memory_mb,
'step_size': 1,
},
fields.ResourceClass.DISK_GB: {
'total': disk_gb,
'min_unit': 1,
'max_unit': disk_gb,
'step_size': 1,
},
}
return result
def get_available_resource(self, nodename):
"""Retrieve resource information.