diff --git a/src/config/api-server/vnc_cfg_ifmap.py b/src/config/api-server/vnc_cfg_ifmap.py index e53ce423fc1..71677a2ad88 100644 --- a/src/config/api-server/vnc_cfg_ifmap.py +++ b/src/config/api-server/vnc_cfg_ifmap.py @@ -1510,17 +1510,23 @@ def match_uuid(self, obj_dict, obj_uuid): return False # end match_uuid - def _update_subnet_uuid(self, vn_dict): - vn_uuid = vn_dict['uuid'] + def update_subnet_uuid(self, vn_dict, do_update=False): + vn_uuid = vn_dict.get('uuid') - def _get_subnet_key(subnet): + def _read_subnet_uuid(subnet): + if vn_uuid is None: + return None pfx = subnet['subnet']['ip_prefix'] pfx_len = subnet['subnet']['ip_prefix_len'] network = IPNetwork('%s/%s' % (pfx, pfx_len)) - return '%s %s/%s' % (vn_uuid, str(network.ip), pfx_len) + subnet_key = '%s %s/%s' % (vn_uuid, str(network.ip), pfx_len) + try: + return self.useragent_kv_retrieve(subnet_key) + except NoUserAgentKey: + return None - ipam_refs = vn_dict['network_ipam_refs'] + ipam_refs = vn_dict.get('network_ipam_refs', []) updated = False for ipam in ipam_refs: vnsn = ipam['attr'] @@ -1529,15 +1535,15 @@ def _get_subnet_key(subnet): if subnet.get('subnet_uuid'): continue - subnet_key = _get_subnet_key(subnet) - subnet_uuid = self.useragent_kv_retrieve(subnet_key) + subnet_uuid = _read_subnet_uuid(subnet) or str(uuid.uuid4()) subnet['subnet_uuid'] = subnet_uuid if not updated: updated = True - if updated: - self._cassandra_db._cassandra_virtual_network_update(vn_uuid, vn_dict) - # end _update_subnet_uuid + if updated and do_update: + self._cassandra_db._cassandra_virtual_network_update(vn_uuid, + vn_dict) + # end update_subnet_uuid def _dbe_resync(self, obj_uuid, obj_cols): obj_type = None @@ -1558,7 +1564,7 @@ def _dbe_resync(self, obj_uuid, obj_cols): if (obj_type == 'virtual_network' and 'network_ipam_refs' in obj_dict): - self._update_subnet_uuid(obj_dict) + self._update_subnet_uuid(obj_dict, do_update=True) except Exception as e: self.config_object_error( obj_uuid, None, obj_type, 'dbe_resync:cassandra_read', str(e)) diff --git a/src/config/api-server/vnc_cfg_types.py b/src/config/api-server/vnc_cfg_types.py index f20a35f6e21..54502cb39f6 100644 --- a/src/config/api-server/vnc_cfg_types.py +++ b/src/config/api-server/vnc_cfg_types.py @@ -366,17 +366,6 @@ def _check_route_targets(cls, obj_dict, db_conn): return (True, '') # end _check_route_targets - @classmethod - def _check_and_create_subnet_uuid(cls, vn_dict): - ipam_refs = vn_dict.get('network_ipam_refs', []) - for ipam in ipam_refs: - vnsn = ipam['attr'] - subnets = vnsn['ipam_subnets'] - for subnet in subnets: - if not subnet.get('subnet_uuid'): - subnet['subnet_uuid'] = str(uuid.uuid4()) - # end _check_and_create_subnet_uuid - @classmethod def http_post_collection(cls, tenant_name, obj_dict, db_conn): try: @@ -396,7 +385,7 @@ def http_post_collection(cls, tenant_name, obj_dict, db_conn): if not ok: return (False, (403, pformat(obj_dict['fq_name']) + ' : ' + quota_limit)) - cls._check_and_create_subnet_uuid(obj_dict) + db_conn.update_subnet_uuid(obj_dict) (ok, error) = cls._check_route_targets(obj_dict, db_conn) if not ok: @@ -453,7 +442,7 @@ def http_put(cls, id, fq_name, obj_dict, db_conn): except Exception as e: return (False, (500, str(e))) - cls._check_and_create_subnet_uuid(obj_dict) + db_conn.update_subnet_uuid(obj_dict) (ok, error) = cls._check_route_targets(obj_dict, db_conn) if not ok: