Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def obj_load_attr(self, attr):
setattr(self, attr, None)
def obj_make_compatible(self, primitive, target_version):
super(InstancePCIRequest, self).obj_make_compatible(primitive,
target_version)
target_version = versionutils.convert_version_to_tuple(target_version)
if target_version < (1, 2) and 'numa_policy' in primitive:
del primitive['numa_policy']
if target_version < (1, 1) and 'request_id' in primitive:
del primitive['request_id']
# TODO(berrange): Remove NovaObjectDictCompat
@base.NovaObjectRegistry.register
class InstancePCIRequests(base.NovaObject,
base.NovaObjectDictCompat):
# Version 1.0: Initial version
# Version 1.1: InstancePCIRequest 1.1
VERSION = '1.1'
fields = {
'instance_uuid': fields.UUIDField(),
'requests': fields.ListOfObjectsField('InstancePCIRequest'),
}
def obj_make_compatible(self, primitive, target_version):
target_version = versionutils.convert_version_to_tuple(target_version)
if target_version < (1, 1) and 'requests' in primitive:
for index, request in enumerate(self.requests):
request.obj_make_compatible(
primitive['requests'][index]['nova_object.data'], '1.0')
if target_version < (1, 1) and 'vlan' in primitive:
del primitive['vlan']
@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'])
#
# 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 import 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'
if not result:
raise exception.FlavorNotFound(flavor_id=(flavor_id or flavorid))
context.session.query(api_models.FlavorProjects).\
filter_by(flavor_id=result.id).delete()
context.session.query(api_models.FlavorExtraSpecs).\
filter_by(flavor_id=result.id).delete()
context.session.delete(result)
return result
# TODO(berrange): Remove NovaObjectDictCompat
# TODO(mriedem): Remove NovaPersistentObject in version 2.0
@base.NovaObjectRegistry.register
class Flavor(base.NovaPersistentObject, base.NovaObject,
base.NovaObjectDictCompat):
# Version 1.0: Initial version
# Version 1.1: Added save_projects(), save_extra_specs(), removed
# remotable from save()
# Version 1.2: Added description field. Note: this field should not be
# persisted with the embedded instance.flavor.
VERSION = '1.2'
fields = {
'id': fields.IntegerField(),
'name': fields.StringField(nullable=True),
'memory_mb': fields.IntegerField(),
'vcpus': fields.IntegerField(),
'root_gb': fields.IntegerField(),
'ephemeral_gb': fields.IntegerField(),
'flavorid': fields.StringField(),
# 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 nova.db import api as db
from nova.objects import base
from nova.objects import fields
@base.NovaObjectRegistry.register
class BandwidthUsage(base.NovaPersistentObject, base.NovaObject):
# Version 1.0: Initial version
# Version 1.1: Add use_slave to get_by_instance_uuid_and_mac
# Version 1.2: Add update_cells to create
VERSION = '1.2'
fields = {
'instance_uuid': fields.UUIDField(),
'mac': fields.StringField(),
'start_period': fields.DateTimeField(),
'last_refreshed': fields.DateTimeField(),
'bw_in': fields.IntegerField(),
'bw_out': fields.IntegerField(),
'last_ctr_in': fields.IntegerField(),
'last_ctr_out': fields.IntegerField()
}
#
# 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 nova.notifications.objects import base
from nova.notifications.objects import flavor as flavor_payload
from nova.notifications.objects import image as image_payload
from nova.notifications.objects import server_group as server_group_payload
from nova.objects import base as nova_base
from nova.objects import fields
@nova_base.NovaObjectRegistry.register_notification
class RequestSpecPayload(base.NotificationPayloadBase):
# Version 1.0: Initial version
# Version 1.1: Add force_hosts, force_nodes, ignore_hosts, image_meta,
# instance_group, requested_destination, retry,
# scheduler_hints and security_groups fields
VERSION = '1.1'
SCHEMA = {
'ignore_hosts': ('request_spec', 'ignore_hosts'),
'instance_uuid': ('request_spec', 'instance_uuid'),
'project_id': ('request_spec', 'project_id'),
'user_id': ('request_spec', 'user_id'),
'availability_zone': ('request_spec', 'availability_zone'),
'num_instances': ('request_spec', 'num_instances'),
'scheduler_hints': ('request_spec', 'scheduler_hints'),
}
return network_model.NetworkInfo.hydrate(cached_info)
try:
return network.API().get_instance_nw_info(admin_context,
instance_ref)
except Exception:
try:
with excutils.save_and_reraise_exception():
LOG.exception('Failed to get nw_info',
instance=instance_ref)
except Exception:
if ignore_missing_network_data:
return
raise
# FIXME(comstud): Temporary as we transition to objects.
if isinstance(instance_ref, obj_base.NovaObject):
nw_info = instance_ref.info_cache.network_info
if nw_info is None:
nw_info = network_model.NetworkInfo()
else:
nw_info = _get_nwinfo_old_skool()
macs = [vif['address'] for vif in nw_info]
uuids = [instance_ref["uuid"]]
bw_usages = objects.BandwidthUsageList.get_by_uuids(admin_context, uuids,
audit_start)
bw = {}
for b in bw_usages:
if b.mac in macs:
label = 'net-name-not-found-%s' % b.mac
@obj_base.remotable_classmethod
def associate(cls, context, project_id, network_id=None, force=False):
db.network_associate(context, project_id, network_id=network_id,
force=force)
'source': self.source,
}
if self.obj_attr_is_set('value'):
if self.name in FIELDS_REQUIRING_CONVERSION:
dict_to_return['value'] = self.value / 100.0
else:
dict_to_return['value'] = self.value
elif self.obj_attr_is_set('numa_membw_values'):
dict_to_return['numa_membw_values'] = self.numa_membw_values
return dict_to_return
@base.NovaObjectRegistry.register
class MonitorMetricList(base.ObjectListBase, base.NovaObject):
# Version 1.0: Initial version
# Version 1.1: MonitorMetric version 1.1
VERSION = '1.1'
fields = {
'objects': fields.ListOfObjectsField('MonitorMetric'),
}
@classmethod
def from_json(cls, metrics):
"""Converts a legacy json object into a list of MonitorMetric objs
and finally returns of MonitorMetricList
:param metrics: a string of json serialized objects
:returns: a MonitorMetricList Object.
"""
# TODO(stephenfin): Remove 'update_cells' in version 2.0 of the object
@base.serialize_args
@base.remotable
def create(self, uuid, mac, bw_in, bw_out, last_ctr_in,
last_ctr_out, start_period=None, last_refreshed=None,
update_cells=True):
db_bw_usage = db.bw_usage_update(
self._context, uuid, mac, start_period, bw_in, bw_out,
last_ctr_in, last_ctr_out, last_refreshed=last_refreshed)
self._from_db_object(self._context, self, db_bw_usage)
@base.NovaObjectRegistry.register
class BandwidthUsageList(base.ObjectListBase, base.NovaObject):
# Version 1.0: Initial version
# Version 1.1: Add use_slave to get_by_uuids
# Version 1.2: BandwidthUsage <= version 1.2
VERSION = '1.2'
fields = {
'objects': fields.ListOfObjectsField('BandwidthUsage'),
}
@staticmethod
@db.select_db_reader_mode
def _db_bw_usage_get_by_uuids(context, uuids, start_period,
use_slave=False):
return db.bw_usage_get_by_uuids(context, uuids=uuids,
start_period=start_period)
@base.serialize_args