Files
nova/nova/objects/virt_device_metadata.py
Stephen Finucane 100b9dc62c db: Unify 'nova.db.api', 'nova.db.sqlalchemy.api'
Merge these, removing an unnecessary layer of abstraction, and place
them in the new 'nova.db.main' directory. The resulting change is huge,
but it's mainly the result of 's/sqlalchemy import api/main import api/'
and 's/nova.db.api/nova.db.main.api/' with some necessary cleanup. We
also need to rework how we do the blocking of API calls since we no
longer have a 'DBAPI' object that we can monkey patch as we were doing
before. This is now done via a global variable that is set by the 'main'
function of 'nova.cmd.compute'.

The main impact of this change is that it's no longer possible to set
'[database] use_db_reconnect' and have all APIs automatically wrapped in
a DB retry. Seeing as this behavior is experimental, isn't applied to
any of the API DB methods (which don't use oslo.db's 'DBAPI' helper),
and is used explicitly in what would appear to be the critical cases
(via the explicit 'oslo_db.api.wrap_db_retry' decorator), this doesn't
seem like a huge loss.

Change-Id: Iad2e4da4546b80a016e477577d23accb2606a6e4
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
2021-08-09 15:34:40 +01:00

141 lines
3.7 KiB
Python

# Copyright (C) 2016, Red Hat, Inc.
#
# 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 oslo_serialization import jsonutils
from oslo_utils import versionutils
from nova.db.main import api as db
from nova.objects import base
from nova.objects import fields
@base.NovaObjectRegistry.register
class DeviceBus(base.NovaObject):
VERSION = '1.0'
@base.NovaObjectRegistry.register
class PCIDeviceBus(DeviceBus):
VERSION = '1.0'
fields = {
'address': fields.PCIAddressField(),
}
@base.NovaObjectRegistry.register
class USBDeviceBus(DeviceBus):
VERSION = '1.0'
fields = {
'address': fields.USBAddressField(),
}
@base.NovaObjectRegistry.register
class SCSIDeviceBus(DeviceBus):
VERSION = '1.0'
fields = {
'address': fields.SCSIAddressField(),
}
@base.NovaObjectRegistry.register
class IDEDeviceBus(DeviceBus):
VERSION = '1.0'
fields = {
'address': fields.IDEAddressField(),
}
@base.NovaObjectRegistry.register
class XenDeviceBus(DeviceBus):
VERSION = '1.0'
fields = {
'address': fields.XenAddressField(),
}
@base.NovaObjectRegistry.register
class DeviceMetadata(base.NovaObject):
VERSION = '1.0'
fields = {
'bus': fields.ObjectField("DeviceBus", subclasses=True),
'tags': fields.ListOfStringsField(),
}
@base.NovaObjectRegistry.register
class NetworkInterfaceMetadata(DeviceMetadata):
# Version 1.0: Initial version
# Version 1.1: Add vlans field
# Version 1.2: Add vf_trusted field
VERSION = '1.2'
fields = {
'mac': fields.MACAddressField(),
'vlan': fields.IntegerField(),
'vf_trusted': fields.BooleanField(default=False),
}
def obj_make_compatible(self, primitive, target_version):
target_version = versionutils.convert_version_to_tuple(target_version)
if target_version < (1, 1) and 'vlan' in primitive:
del primitive['vlan']
if target_version < (1, 2) and 'vf_trusted' in primitive:
del primitive['vf_trusted']
@base.NovaObjectRegistry.register
class DiskMetadata(DeviceMetadata):
VERSION = '1.0'
fields = {
'serial': fields.StringField(nullable=True),
'path': fields.StringField(nullable=True),
}
@base.NovaObjectRegistry.register
class InstanceDeviceMetadata(base.NovaObject):
VERSION = '1.0'
fields = {
'devices': fields.ListOfObjectsField('DeviceMetadata',
subclasses=True),
}
@classmethod
def obj_from_db(cls, context, db_dev_meta):
primitive = jsonutils.loads(db_dev_meta)
device_metadata = cls.obj_from_primitive(primitive)
return device_metadata
@base.remotable_classmethod
def get_by_instance_uuid(cls, context, instance_uuid):
db_extra = db.instance_extra_get_by_instance_uuid(
context, instance_uuid, columns=['device_metadata'])
if not db_extra or db_extra['device_metadata'] is None:
return None
primitive = jsonutils.loads(db_extra['device_metadata'])
device_metadata = cls.obj_from_primitive(primitive)
return device_metadata
def _to_json(self):
return jsonutils.dumps(self.obj_to_primitive())