summaryrefslogtreecommitdiff
path: root/ironic/objects/portgroup.py
diff options
context:
space:
mode:
authorRuby Loo <ruby.loo@intel.com>2017-10-12 18:30:52 -0400
committerRuby Loo <opensrloo@gmail.com>2018-04-02 17:56:47 +0000
commit37b85b6a399dba120de49d9056529852b2284793 (patch)
tree15729826ce2f7701e14c3b3b3f98d89a0c347cf1 /ironic/objects/portgroup.py
parent5816e50766e3ed9e08ff7fd7176a85b2ab835659 (diff)
downloadironic-37b85b6a399dba120de49d9056529852b2284793.tar.gz
Copy port[group] VIF info from extra to internal_info
For API versions >= 1.28, Port & portgroup's .extra['vif_port_id'] was deprecated in Ocata. Before we can remove support for this, we need to copy that information to the object's internal_info['tenant_vif_port_id']. This copy/migration is done at the API layer when the user specifies the .extra[] value, as well as when the 'ironic db-sync online_data-migrations' is run. In order to know whether the ports and port groups have been migrated, their IronicObject versions are incremented. This also fixes it so that for API versions < 1.28, the deprecation warning is not shown, since we still need to support extra['vif_port_id'] in this case. When a port or portgroup's .extra['vif_port_id'] is removed via a PATCH API request, that VIF is removed from that object's internal_info. Change-Id: I69468c935e68dd9d37a474c318c3ceb9cdfc5868 Partial-Bug: 1722850
Diffstat (limited to 'ironic/objects/portgroup.py')
-rw-r--r--ironic/objects/portgroup.py68
1 files changed, 67 insertions, 1 deletions
diff --git a/ironic/objects/portgroup.py b/ironic/objects/portgroup.py
index a12542d7a..360f876f6 100644
--- a/ironic/objects/portgroup.py
+++ b/ironic/objects/portgroup.py
@@ -16,6 +16,7 @@
from oslo_utils import netutils
from oslo_utils import strutils
from oslo_utils import uuidutils
+from oslo_utils import versionutils
from oslo_versionedobjects import base as object_base
from ironic.common import exception
@@ -26,13 +27,47 @@ from ironic.objects import fields as object_fields
from ironic.objects import notification
+def migrate_vif_port_id(context, max_count):
+ """Copy portgroup's VIF info from extra to internal_info.
+
+ :param context: The context.
+ :param max_count: The maximum number of objects to migrate. Must be
+ >= 0. If zero, all the objects will be migrated.
+ :returns: A 2-tuple -- the total number of objects that need to be
+ migrated (at the beginning of this call) and the number
+ of migrated objects.
+ """
+ # TODO(rloo): remove this method in Stein, when we remove from dbsync.py
+
+ # NOTE(rloo): if we introduce newer portgroup versions in the same cycle,
+ # we could add those versions along with 1.4. This is only so we don't
+ # duplicate work; it isn't necessary.
+ db_objs = Portgroup.dbapi.get_not_versions('Portgroup', ['1.4'])
+ total = len(db_objs)
+ max_count = max_count or total
+ done = 0
+ for db_obj in db_objs:
+ # NOTE(rloo): this will indirectly invoke
+ # Portgroup._convert_to_version() which does all the real
+ # work
+ portgroup = Portgroup._from_db_object(context, Portgroup(), db_obj)
+ portgroup.save()
+ done += 1
+ if done == max_count:
+ break
+ return total, done
+
+
@base.IronicObjectRegistry.register
class Portgroup(base.IronicObject, object_base.VersionedObjectDictCompat):
# Version 1.0: Initial version
# Version 1.1: Add internal_info field
# Version 1.2: Add standalone_ports_supported field
# Version 1.3: Add mode and properties fields
- VERSION = '1.3'
+ # Version 1.4: Migrate/copy extra['vif_port_id'] to
+ # internal_info['tenant_vif_port_id'] (not an explicit db
+ # change)
+ VERSION = '1.4'
dbapi = dbapi.get_instance()
@@ -49,6 +84,37 @@ class Portgroup(base.IronicObject, object_base.VersionedObjectDictCompat):
'properties': object_fields.FlexibleDictField(nullable=True),
}
+ def _convert_to_version(self, target_version,
+ remove_unavailable_fields=True):
+ """Convert to the target version.
+
+ Convert the object to the target version. The target version may be
+ the same, older, or newer than the version of the object. This is
+ used for DB interactions as well as for serialization/deserialization.
+
+ Version 1.4: if extra['vif_port_id'] is specified (non-null) and
+ internal_info['tenant_vif_port_id'] is not specified, copy the
+ .extra value to internal_info. There is nothing to do here when
+ downgrading to an older version.
+
+ :param target_version: the desired version of the object
+ :param remove_unavailable_fields: True to remove fields that are
+ unavailable in the target version; set this to True when
+ (de)serializing. False to set the unavailable fields to appropriate
+ values; set this to False for DB interactions.
+ """
+ target_version = versionutils.convert_version_to_tuple(target_version)
+ if target_version >= (1, 4):
+ if self.obj_attr_is_set('extra'):
+ vif = self.extra.get('vif_port_id')
+ if vif:
+ internal_info = (self.internal_info
+ if self.obj_attr_is_set('internal_info')
+ else {})
+ if 'tenant_vif_port_id' not in internal_info:
+ internal_info['tenant_vif_port_id'] = vif
+ self.internal_info = internal_info
+
# NOTE(xek): We don't want to enable RPC on this call just yet. Remotable
# methods can be used in the future to replace current explicit RPC calls.
# Implications of calling new remote procedures should be thought through.