objects: adding an update method to virtual_interface
Adding a save method to the virtual_interface object and an update method to its database model. Partially implements blueprint virt-device-role-tagging Co-authored-by: Artom Lifshitz <alifshit@redhat.com> Change-Id: I52673fc297cb578995be5c7a075c5693b0793bf5
This commit is contained in:
committed by
Artom Lifshitz
parent
32c4c38719
commit
6b989dba22
@@ -21,11 +21,15 @@ from nova.objects import base
|
||||
from nova.objects import fields
|
||||
|
||||
|
||||
VIF_OPTIONAL_FIELDS = ['network_id']
|
||||
|
||||
|
||||
@base.NovaObjectRegistry.register
|
||||
class VirtualInterface(base.NovaPersistentObject, base.NovaObject):
|
||||
# Version 1.0: Initial version
|
||||
# Version 1.1: Add tag field
|
||||
VERSION = '1.1'
|
||||
# Version 1.2: Adding a save method
|
||||
VERSION = '1.2'
|
||||
|
||||
fields = {
|
||||
'id': fields.IntegerField(),
|
||||
@@ -44,7 +48,10 @@ class VirtualInterface(base.NovaPersistentObject, base.NovaObject):
|
||||
@staticmethod
|
||||
def _from_db_object(context, vif, db_vif):
|
||||
for field in vif.fields:
|
||||
setattr(vif, field, db_vif[field])
|
||||
if not db_vif[field] and field in VIF_OPTIONAL_FIELDS:
|
||||
continue
|
||||
else:
|
||||
setattr(vif, field, db_vif[field])
|
||||
vif._context = context
|
||||
vif.obj_reset_changes()
|
||||
return vif
|
||||
@@ -83,6 +90,16 @@ class VirtualInterface(base.NovaPersistentObject, base.NovaObject):
|
||||
db_vif = db.virtual_interface_create(self._context, updates)
|
||||
self._from_db_object(self._context, self, db_vif)
|
||||
|
||||
@base.remotable
|
||||
def save(self):
|
||||
updates = self.obj_get_changes()
|
||||
if 'address' in updates:
|
||||
raise exception.ObjectActionError(action='save',
|
||||
reason='address is not mutable')
|
||||
db_vif = db.virtual_interface_update(self._context, self.address,
|
||||
updates)
|
||||
return self._from_db_object(self._context, self, db_vif)
|
||||
|
||||
@base.remotable_classmethod
|
||||
def delete_by_instance_uuid(cls, context, instance_uuid):
|
||||
db.virtual_interface_delete_by_instance(context, instance_uuid)
|
||||
|
||||
Reference in New Issue
Block a user