Move resource class fields

Move the ResourceClass field to its own package, and move that package
to the top of the nova hierarchy since it is used by both nova tooling
and placement tooling but we don't want the placement version to have to
incorporate the nova code. Eventually we'd like to see an
os-resource-classes library, similar to os-traits, which will serve this
functionality. This is a step in that direction.

Changes in this patch are quite widespread, but are mostly only changes
of imports.

Change-Id: Iea182341f9419cb514a044f76864d6bec60a3683
This commit is contained in:
Chris Dent 2018-03-10 12:44:14 +00:00
parent 9a49767134
commit f346913594
26 changed files with 141 additions and 111 deletions

View File

@ -39,7 +39,7 @@ from nova import context as nova_context
from nova.db.sqlalchemy import api as db_session
from nova.i18n import _
from nova.objects import cell_mapping as cell_mapping_obj
from nova.objects import fields
from nova import rc_fields as fields
from nova import utils
from nova import version

View File

@ -35,10 +35,10 @@ from nova import exception
from nova.i18n import _
from nova import objects
from nova.objects import base as obj_base
from nova.objects import fields
from nova.objects import migration as migration_obj
from nova.pci import manager as pci_manager
from nova.pci import request as pci_request
from nova import rc_fields as fields
from nova import rpc
from nova.scheduler import client as scheduler_client
from nova.scheduler import utils as scheduler_utils

View File

@ -17,7 +17,7 @@ import sqlalchemy as sa
from nova.db.sqlalchemy import api as db_api
from nova.db.sqlalchemy import api_models as models
from nova import exception
from nova.objects import fields
from nova import rc_fields as fields
_RC_TBL = models.ResourceClass.__table__
_LOCKNAME = 'rc_cache'

View File

@ -459,49 +459,6 @@ class OSType(BaseNovaEnum):
return super(OSType, self).coerce(obj, attr, value)
class ResourceClass(StringField):
"""Classes of resources provided to consumers."""
CUSTOM_NAMESPACE = 'CUSTOM_'
"""All non-standard resource classes must begin with this string."""
VCPU = 'VCPU'
MEMORY_MB = 'MEMORY_MB'
DISK_GB = 'DISK_GB'
PCI_DEVICE = 'PCI_DEVICE'
SRIOV_NET_VF = 'SRIOV_NET_VF'
NUMA_SOCKET = 'NUMA_SOCKET'
NUMA_CORE = 'NUMA_CORE'
NUMA_THREAD = 'NUMA_THREAD'
NUMA_MEMORY_MB = 'NUMA_MEMORY_MB'
IPV4_ADDRESS = 'IPV4_ADDRESS'
VGPU = 'VGPU'
VGPU_DISPLAY_HEAD = 'VGPU_DISPLAY_HEAD'
# The ordering here is relevant. If you must add a value, only
# append.
STANDARD = (VCPU, MEMORY_MB, DISK_GB, PCI_DEVICE, SRIOV_NET_VF,
NUMA_SOCKET, NUMA_CORE, NUMA_THREAD, NUMA_MEMORY_MB,
IPV4_ADDRESS, VGPU, VGPU_DISPLAY_HEAD)
# This is the set of standard resource classes that existed before
# we opened up for custom resource classes in version 1.1 of various
# objects in nova/objects/resource_provider.py
V1_0 = (VCPU, MEMORY_MB, DISK_GB, PCI_DEVICE, SRIOV_NET_VF, NUMA_SOCKET,
NUMA_CORE, NUMA_THREAD, NUMA_MEMORY_MB, IPV4_ADDRESS)
@classmethod
def normalize_name(cls, rc_name):
if rc_name is None:
return None
norm_name = rc_name.upper()
cust_prefix = cls.CUSTOM_NAMESPACE
norm_name = cust_prefix + norm_name
# Replace some punctuation characters with underscores
norm_name = re.sub('[^0-9A-Z]+', '_', norm_name)
return norm_name
class RNGModel(BaseNovaEnum):
VIRTIO = "virtio"
@ -1167,10 +1124,6 @@ class OSTypeField(BaseEnumField):
AUTO_TYPE = OSType()
class ResourceClassField(AutoTypedField):
AUTO_TYPE = ResourceClass()
class RNGModelField(BaseEnumField):
AUTO_TYPE = RNGModel()

View File

@ -41,6 +41,7 @@ from nova import exception
from nova.i18n import _
from nova.objects import base
from nova.objects import fields
from nova import rc_fields
_TRAIT_TBL = models.Trait.__table__
_ALLOC_TBL = models.Allocation.__table__
@ -1602,7 +1603,7 @@ class Inventory(base.NovaObject, base.NovaTimestampObject):
fields = {
'id': fields.IntegerField(read_only=True),
'resource_provider': fields.ObjectField('ResourceProvider'),
'resource_class': fields.ResourceClassField(read_only=True),
'resource_class': rc_fields.ResourceClassField(read_only=True),
'total': fields.NonNegativeIntegerField(),
'reserved': fields.NonNegativeIntegerField(default=0),
'min_unit': fields.NonNegativeIntegerField(default=1),
@ -1688,7 +1689,7 @@ class Allocation(base.NovaObject, base.NovaTimestampObject):
'id': fields.IntegerField(),
'resource_provider': fields.ObjectField('ResourceProvider'),
'consumer_id': fields.UUIDField(),
'resource_class': fields.ResourceClassField(),
'resource_class': rc_fields.ResourceClassField(),
'used': fields.IntegerField(),
# The following two fields are allowed to be set to None to
# support Allocations that were created before the fields were
@ -2174,7 +2175,7 @@ class AllocationList(base.ObjectListBase, base.NovaObject):
class Usage(base.NovaObject):
fields = {
'resource_class': fields.ResourceClassField(read_only=True),
'resource_class': rc_fields.ResourceClassField(read_only=True),
'usage': fields.NonNegativeIntegerField(),
}
@ -2270,7 +2271,7 @@ class ResourceClass(base.NovaObject, base.NovaTimestampObject):
fields = {
'id': fields.IntegerField(read_only=True),
'name': fields.ResourceClassField(nullable=False),
'name': rc_fields.ResourceClassField(nullable=False),
}
@staticmethod
@ -2317,14 +2318,14 @@ class ResourceClass(base.NovaObject, base.NovaTimestampObject):
if 'name' not in self:
raise exception.ObjectActionError(action='create',
reason='name is required')
if self.name in fields.ResourceClass.STANDARD:
if self.name in rc_fields.ResourceClass.STANDARD:
raise exception.ResourceClassExists(resource_class=self.name)
if not self.name.startswith(fields.ResourceClass.CUSTOM_NAMESPACE):
if not self.name.startswith(rc_fields.ResourceClass.CUSTOM_NAMESPACE):
raise exception.ObjectActionError(
action='create',
reason='name must start with ' +
fields.ResourceClass.CUSTOM_NAMESPACE)
rc_fields.ResourceClass.CUSTOM_NAMESPACE)
updates = self.obj_get_changes()
# There is the possibility of a race when adding resource classes, as
@ -2586,7 +2587,7 @@ class AllocationRequestResource(base.NovaObject):
fields = {
'resource_provider': fields.ObjectField('ResourceProvider'),
'resource_class': fields.ResourceClassField(read_only=True),
'resource_class': rc_fields.ResourceClassField(read_only=True),
'amount': fields.NonNegativeIntegerField(),
}
@ -2605,7 +2606,7 @@ class AllocationRequest(base.NovaObject):
class ProviderSummaryResource(base.NovaObject):
fields = {
'resource_class': fields.ResourceClassField(read_only=True),
'resource_class': rc_fields.ResourceClassField(read_only=True),
'capacity': fields.NonNegativeIntegerField(),
'used': fields.NonNegativeIntegerField(),
}

70
nova/rc_fields.py Normal file
View File

@ -0,0 +1,70 @@
#
# 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.
"""Standard Resource Class Fields."""
# NOTE(cdent): This is kept as its own independent file as it is used by
# both the placement and nova sides of the placement interaction. On the
# placement side we don't want to import all the nova fields, nor all the
# nova objects (which are automatically loaded and registered if the
# nova.objects package is imported).
import re
from oslo_versionedobjects import fields
class ResourceClass(fields.StringField):
"""Classes of resources provided to consumers."""
CUSTOM_NAMESPACE = 'CUSTOM_'
"""All non-standard resource classes must begin with this string."""
VCPU = 'VCPU'
MEMORY_MB = 'MEMORY_MB'
DISK_GB = 'DISK_GB'
PCI_DEVICE = 'PCI_DEVICE'
SRIOV_NET_VF = 'SRIOV_NET_VF'
NUMA_SOCKET = 'NUMA_SOCKET'
NUMA_CORE = 'NUMA_CORE'
NUMA_THREAD = 'NUMA_THREAD'
NUMA_MEMORY_MB = 'NUMA_MEMORY_MB'
IPV4_ADDRESS = 'IPV4_ADDRESS'
VGPU = 'VGPU'
VGPU_DISPLAY_HEAD = 'VGPU_DISPLAY_HEAD'
# The ordering here is relevant. If you must add a value, only
# append.
STANDARD = (VCPU, MEMORY_MB, DISK_GB, PCI_DEVICE, SRIOV_NET_VF,
NUMA_SOCKET, NUMA_CORE, NUMA_THREAD, NUMA_MEMORY_MB,
IPV4_ADDRESS, VGPU, VGPU_DISPLAY_HEAD)
# This is the set of standard resource classes that existed before
# we opened up for custom resource classes in version 1.1 of various
# objects in nova/objects/resource_provider.py
V1_0 = (VCPU, MEMORY_MB, DISK_GB, PCI_DEVICE, SRIOV_NET_VF, NUMA_SOCKET,
NUMA_CORE, NUMA_THREAD, NUMA_MEMORY_MB, IPV4_ADDRESS)
@classmethod
def normalize_name(cls, rc_name):
if rc_name is None:
return None
norm_name = rc_name.upper()
cust_prefix = cls.CUSTOM_NAMESPACE
norm_name = cust_prefix + norm_name
# Replace some punctuation characters with underscores
norm_name = re.sub('[^0-9A-Z]+', '_', norm_name)
return norm_name
class ResourceClassField(fields.AutoTypedField):
AUTO_TYPE = ResourceClass()

View File

@ -31,7 +31,7 @@ import nova.conf
from nova import exception
from nova.i18n import _
from nova import objects
from nova.objects import fields
from nova import rc_fields as fields
from nova.scheduler import utils as scheduler_utils
from nova import utils

View File

@ -31,8 +31,8 @@ from nova import exception
from nova.i18n import _, _LE, _LW
from nova import objects
from nova.objects import base as obj_base
from nova.objects import fields
from nova.objects import instance as obj_instance
from nova import rc_fields as fields
from nova import rpc

View File

@ -22,7 +22,7 @@ from nova import conf
from nova import context
from nova import exception
from nova import objects
from nova.objects import fields
from nova import rc_fields as fields
from nova.scheduler.client import report
from nova import test
from nova.tests import uuidsentinel as uuids

View File

@ -21,7 +21,7 @@ from nova.compute import vm_states
from nova import conf
from nova import context
from nova import objects
from nova.objects import fields
from nova import rc_fields as fields
from nova import test
from nova.tests.functional.api.openstack.placement import test_report_client
from nova.tests import uuidsentinel as uuids

View File

@ -16,8 +16,8 @@ import sqlalchemy as sa
from nova.api.openstack.placement import lib as placement_lib
from nova import context
from nova import exception
from nova.objects import fields
from nova.objects import resource_provider as rp_obj
from nova import rc_fields as fields
from nova import test
from nova.tests import fixtures
from nova.tests import uuidsentinel as uuids

View File

@ -17,7 +17,7 @@ from oslo_utils import timeutils
from nova.db.sqlalchemy import resource_class_cache as rc_cache
from nova import exception
from nova.objects import fields
from nova import rc_fields as fields
from nova import test
from nova.tests import fixtures

View File

@ -19,8 +19,8 @@ import sqlalchemy as sa
import nova
from nova import context
from nova import exception
from nova.objects import fields
from nova.objects import resource_provider as rp_obj
from nova import rc_fields as fields
from nova import test
from nova.tests import fixtures
from nova.tests import uuidsentinel

View File

@ -31,8 +31,8 @@ from nova import context
# NOTE(mriedem): We only use objects as a convenience to populate the database
# in the tests, we don't use them in the actual CLI.
from nova import objects
from nova.objects import fields
from nova.objects import resource_provider as rp_obj
from nova import rc_fields as fields
from nova import test
from nova.tests import fixtures as nova_fixtures
from nova.tests import uuidsentinel as uuids

View File

@ -31,6 +31,7 @@ from nova.objects import base as obj_base
from nova.objects import fields as obj_fields
from nova.objects import pci_device
from nova.pci import manager as pci_manager
from nova import rc_fields
from nova import test
from nova.tests.unit import fake_notifier
from nova.tests.unit.objects import test_pci_device as fake_pci_device
@ -1352,19 +1353,19 @@ class TestNormalizatInventoryFromComputeNode(test.NoDBTestCase):
# allocation_ratio or reserved amounts for some resources. Verify that
# the information on the compute node fills in this information...
inv = {
obj_fields.ResourceClass.VCPU: {
rc_fields.ResourceClass.VCPU: {
'total': vcpus,
'min_unit': 1,
'max_unit': vcpus,
'step_size': 1,
},
obj_fields.ResourceClass.MEMORY_MB: {
rc_fields.ResourceClass.MEMORY_MB: {
'total': memory_mb,
'min_unit': 1,
'max_unit': memory_mb,
'step_size': 1,
},
obj_fields.ResourceClass.DISK_GB: {
rc_fields.ResourceClass.DISK_GB: {
'total': disk_gb,
'min_unit': 1,
'max_unit': disk_gb,
@ -1372,7 +1373,7 @@ class TestNormalizatInventoryFromComputeNode(test.NoDBTestCase):
},
}
expected = {
obj_fields.ResourceClass.VCPU: {
rc_fields.ResourceClass.VCPU: {
'total': vcpus,
'reserved': 1,
'min_unit': 1,
@ -1380,7 +1381,7 @@ class TestNormalizatInventoryFromComputeNode(test.NoDBTestCase):
'step_size': 1,
'allocation_ratio': 16.0,
},
obj_fields.ResourceClass.MEMORY_MB: {
rc_fields.ResourceClass.MEMORY_MB: {
'total': memory_mb,
'reserved': 10,
'min_unit': 1,
@ -1388,7 +1389,7 @@ class TestNormalizatInventoryFromComputeNode(test.NoDBTestCase):
'step_size': 1,
'allocation_ratio': 1.5,
},
obj_fields.ResourceClass.DISK_GB: {
rc_fields.ResourceClass.DISK_GB: {
'total': disk_gb,
'reserved': 1, # Rounded up from CONF.reserved_host_disk_mb
'min_unit': 1,
@ -1425,7 +1426,7 @@ class TestNormalizatInventoryFromComputeNode(test.NoDBTestCase):
# blocks for VCPU, MEMORY_MB, DISK_GB and the custom resource class
# inventory items
inv = {
obj_fields.ResourceClass.VCPU: {
rc_fields.ResourceClass.VCPU: {
'total': vcpus,
'reserved': 0,
'min_unit': 1,
@ -1433,7 +1434,7 @@ class TestNormalizatInventoryFromComputeNode(test.NoDBTestCase):
'step_size': 1,
'allocation_ratio': 1.0,
},
obj_fields.ResourceClass.MEMORY_MB: {
rc_fields.ResourceClass.MEMORY_MB: {
'total': memory_mb,
'reserved': 0,
'min_unit': 1,
@ -1441,7 +1442,7 @@ class TestNormalizatInventoryFromComputeNode(test.NoDBTestCase):
'step_size': 1,
'allocation_ratio': 1.0,
},
obj_fields.ResourceClass.DISK_GB: {
rc_fields.ResourceClass.DISK_GB: {
'total': disk_gb,
'reserved': 0,
'min_unit': 1,

View File

@ -23,6 +23,7 @@ import six
from nova import exception
from nova.network import model as network_model
from nova.objects import fields
from nova import rc_fields
from nova import test
from nova.tests.unit import fake_instance
from nova import utils
@ -334,7 +335,7 @@ class TestVMMode(TestField):
class TestResourceClass(TestString):
def setUp(self):
super(TestResourceClass, self).setUp()
self.field = fields.ResourceClassField()
self.field = rc_fields.ResourceClassField()
self.coerce_good_values = [
('VCPU', 'VCPU'),
('MEMORY_MB', 'MEMORY_MB'),
@ -361,7 +362,7 @@ class TestResourceClass(TestString):
("CUSTM_BOB", "CUSTOM_CUSTM_BOB"),
]
for test_value, expected in values:
result = fields.ResourceClass.normalize_name(test_value)
result = rc_fields.ResourceClass.normalize_name(test_value)
self.assertEqual(expected, result)

View File

@ -19,8 +19,8 @@ import nova
from nova import context
from nova.db.sqlalchemy import api_models as models
from nova import exception
from nova.objects import fields
from nova.objects import resource_provider
from nova import rc_fields as fields
from nova import test
from nova.tests.unit.objects import test_objects
from nova.tests import uuidsentinel as uuids

View File

@ -21,7 +21,7 @@ import nova.conf
from nova import context
from nova import exception
from nova import objects
from nova.objects import fields
from nova import rc_fields as fields
from nova.scheduler.client import report
from nova.scheduler import utils as scheduler_utils
from nova import test

View File

@ -34,7 +34,7 @@ from nova import context as nova_context
from nova import exception
from nova.network import model as network_model
from nova import objects
from nova.objects import fields
from nova import rc_fields as fields
from nova import servicegroup
from nova import test
from nova.tests import fixtures

View File

@ -74,6 +74,7 @@ from nova.objects import virtual_interface as obj_vif
from nova.pci import manager as pci_manager
from nova.pci import utils as pci_utils
import nova.privsep.libvirt
from nova import rc_fields
from nova import test
from nova.tests.unit import fake_block_device
from nova.tests.unit import fake_diagnostics
@ -16822,19 +16823,19 @@ class TestGetInventory(test.NoDBTestCase):
total_vgpus=0):
mock_vgpus.return_value = total_vgpus
expected_inv = {
fields.ResourceClass.VCPU: {
rc_fields.ResourceClass.VCPU: {
'total': 24,
'min_unit': 1,
'max_unit': 24,
'step_size': 1,
},
fields.ResourceClass.MEMORY_MB: {
rc_fields.ResourceClass.MEMORY_MB: {
'total': 1024,
'min_unit': 1,
'max_unit': 1024,
'step_size': 1,
},
fields.ResourceClass.DISK_GB: {
rc_fields.ResourceClass.DISK_GB: {
'total': 200,
'min_unit': 1,
'max_unit': 200,
@ -16843,7 +16844,7 @@ class TestGetInventory(test.NoDBTestCase):
}
if total_vgpus > 0:
expected_inv.update({
fields.ResourceClass.VGPU: {
rc_fields.ResourceClass.VGPU: {
'total': total_vgpus,
'min_unit': 1,
'max_unit': total_vgpus,
@ -19265,7 +19266,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
'rp1': {
'resources': {
# Just any resource class but VGPU
fields.ResourceClass.VCPU: 1,
rc_fields.ResourceClass.VCPU: 1,
}
}
}
@ -19278,7 +19279,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
allocations = {
'rp1': {
'resources': {
fields.ResourceClass.VGPU: 1,
rc_fields.ResourceClass.VGPU: 1,
}
}
}
@ -19300,7 +19301,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
allocations = {
'rp1': {
'resources': {
fields.ResourceClass.VGPU: 1,
rc_fields.ResourceClass.VGPU: 1,
}
}
}
@ -19333,7 +19334,7 @@ class LibvirtDriverTestCase(test.NoDBTestCase):
allocations = {
'rp1': {
'resources': {
fields.ResourceClass.VGPU: 1,
rc_fields.ResourceClass.VGPU: 1,
}
}
}

View File

@ -42,7 +42,7 @@ from nova import exception
from nova.image import glance
from nova.network import model as network_model
from nova import objects
from nova.objects import fields
from nova import rc_fields as fields
from nova import test
from nova.tests.unit import fake_diagnostics
from nova.tests.unit import fake_instance

View File

@ -20,6 +20,7 @@ from oslo_utils import units
from nova import exception
from nova.objects import fields as obj_fields
from nova import rc_fields
from nova.tests.unit.virt.xenapi import stubs
from nova.tests import uuidsentinel as uuids
from nova.virt import driver
@ -251,25 +252,25 @@ class XenAPIDriverTestCase(stubs.XenAPITestBaseNoDB):
@mock.patch.object(host.HostState, 'get_host_stats')
def test_get_inventory(self, mock_get_stats):
expected_inv = {
obj_fields.ResourceClass.VCPU: {
rc_fields.ResourceClass.VCPU: {
'total': 50,
'min_unit': 1,
'max_unit': 50,
'step_size': 1,
},
obj_fields.ResourceClass.MEMORY_MB: {
rc_fields.ResourceClass.MEMORY_MB: {
'total': 3,
'min_unit': 1,
'max_unit': 3,
'step_size': 1,
},
obj_fields.ResourceClass.DISK_GB: {
rc_fields.ResourceClass.DISK_GB: {
'total': 5,
'min_unit': 1,
'max_unit': 5,
'step_size': 1,
},
obj_fields.ResourceClass.VGPU: {
rc_fields.ResourceClass.VGPU: {
'total': 7,
'min_unit': 1,
'max_unit': 1,
@ -295,7 +296,7 @@ class XenAPIDriverTestCase(stubs.XenAPITestBaseNoDB):
inv = drv.get_inventory(mock.sentinel.nodename)
# check if the inventory data does NOT contain VGPU.
self.assertNotIn(obj_fields.ResourceClass.VGPU, inv)
self.assertNotIn(rc_fields.ResourceClass.VGPU, inv)
def test_get_vgpu_total_single_grp(self):
# Test when only one group included in the host_stats.

View File

@ -45,6 +45,7 @@ from nova import exception
from nova.i18n import _
from nova import objects
from nova.objects import fields as obj_fields
from nova import rc_fields
from nova import servicegroup
from nova import utils
from nova.virt import configdrive
@ -498,7 +499,7 @@ class IronicDriver(virt_driver.ComputeDriver):
@staticmethod
def _pike_flavor_migration_for_node(ctx, node_rc, instance_uuid):
normalized_rc = obj_fields.ResourceClass.normalize_name(node_rc)
normalized_rc = rc_fields.ResourceClass.normalize_name(node_rc)
instance = objects.Instance.get_by_uuid(ctx, instance_uuid,
expected_attrs=["flavor"])
specs = instance.flavor.extra_specs
@ -754,9 +755,9 @@ class IronicDriver(virt_driver.ComputeDriver):
info = self._node_resource(node)
result = {}
for rc, field in [(obj_fields.ResourceClass.VCPU, 'vcpus'),
(obj_fields.ResourceClass.MEMORY_MB, 'memory_mb'),
(obj_fields.ResourceClass.DISK_GB, 'local_gb')]:
for rc, field in [(rc_fields.ResourceClass.VCPU, 'vcpus'),
(rc_fields.ResourceClass.MEMORY_MB, 'memory_mb'),
(rc_fields.ResourceClass.DISK_GB, 'local_gb')]:
# NOTE(dtantsur): any of these fields can be zero starting with
# the Pike release.
if info[field]:
@ -773,7 +774,7 @@ class IronicDriver(virt_driver.ComputeDriver):
if rc_name is not None:
# TODO(jaypipes): Raise an exception in Queens if Ironic doesn't
# report a resource class for the node
norm_name = obj_fields.ResourceClass.normalize_name(rc_name)
norm_name = rc_fields.ResourceClass.normalize_name(rc_name)
if norm_name is not None:
result[norm_name] = {
'total': 1,

View File

@ -89,6 +89,7 @@ from nova.pci import manager as pci_manager
from nova.pci import utils as pci_utils
import nova.privsep.libvirt
import nova.privsep.path
from nova import rc_fields
from nova import utils
from nova import version
from nova.virt import block_device as driver_block_device
@ -6054,7 +6055,7 @@ class LibvirtDriver(driver.ComputeDriver):
if not allocations:
# If no allocations, there is no vGPU request.
return {}
RC_VGPU = fields.ResourceClass.VGPU
RC_VGPU = rc_fields.ResourceClass.VGPU
vgpu_allocations = {}
for rp in allocations:
res = allocations[rp]['resources']
@ -6133,7 +6134,7 @@ class LibvirtDriver(driver.ComputeDriver):
'while at the moment libvirt only supports one. Only '
'the first allocation will be looked up.')
alloc = six.next(six.itervalues(vgpu_allocations))
vgpus_asked = alloc['resources'][fields.ResourceClass.VGPU]
vgpus_asked = alloc['resources'][rc_fields.ResourceClass.VGPU]
requested_types = self._get_supported_vgpu_types()
# Which mediated devices are created but not assigned to a guest ?
@ -6357,19 +6358,19 @@ class LibvirtDriver(driver.ComputeDriver):
# the RT injects those values into the inventory dict based on the
# compute_nodes record values.
result = {
fields.ResourceClass.VCPU: {
rc_fields.ResourceClass.VCPU: {
'total': vcpus,
'min_unit': 1,
'max_unit': vcpus,
'step_size': 1,
},
fields.ResourceClass.MEMORY_MB: {
rc_fields.ResourceClass.MEMORY_MB: {
'total': memory_mb,
'min_unit': 1,
'max_unit': memory_mb,
'step_size': 1,
},
fields.ResourceClass.DISK_GB: {
rc_fields.ResourceClass.DISK_GB: {
'total': disk_gb,
'min_unit': 1,
'max_unit': disk_gb,
@ -6379,7 +6380,7 @@ class LibvirtDriver(driver.ComputeDriver):
if vgpus > 0:
# Only provide VGPU resource classes if the driver supports it.
result[fields.ResourceClass.VGPU] = {
result[rc_fields.ResourceClass.VGPU] = {
'total': vgpus,
'min_unit': 1,
'max_unit': vgpus,

View File

@ -38,8 +38,8 @@ from nova.compute import utils as compute_utils
import nova.conf
from nova import exception
from nova.i18n import _
from nova.objects import fields as obj_fields
import nova.privsep.path
from nova import rc_fields as fields
from nova.virt import driver
from nova.virt.vmwareapi import constants
from nova.virt.vmwareapi import ds_util
@ -366,21 +366,21 @@ class VMwareVCDriver(driver.ComputeDriver):
reserved_disk_gb = compute_utils.convert_mb_to_ceil_gb(
CONF.reserved_host_disk_mb)
result = {
obj_fields.ResourceClass.VCPU: {
fields.ResourceClass.VCPU: {
'total': stats['cpu']['vcpus'],
'reserved': CONF.reserved_host_cpus,
'min_unit': 1,
'max_unit': stats['cpu']['max_vcpus_per_host'],
'step_size': 1,
},
obj_fields.ResourceClass.MEMORY_MB: {
fields.ResourceClass.MEMORY_MB: {
'total': stats['mem']['total'],
'reserved': CONF.reserved_host_memory_mb,
'min_unit': 1,
'max_unit': stats['mem']['max_mem_mb_per_host'],
'step_size': 1,
},
obj_fields.ResourceClass.DISK_GB: {
fields.ResourceClass.DISK_GB: {
'total': total_disk_capacity // units.Gi,
'reserved': reserved_disk_gb,
'min_unit': 1,

View File

@ -36,7 +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 import rc_fields as fields
from nova.virt import driver
from nova.virt.xenapi import host
from nova.virt.xenapi import pool