diff --git a/vmware_nsx/api_replay/client.py b/vmware_nsx/api_replay/client.py index d2a82e09dc..873c0222cc 100644 --- a/vmware_nsx/api_replay/client.py +++ b/vmware_nsx/api_replay/client.py @@ -354,6 +354,9 @@ class ApiReplayClient(utils.PrepareObjectForMigration): body = self.prepare_qos_policy(pol) new_pol = self.dest_neutron.create_qos_policy( body={'policy': body}) + self.check_and_apply_tags( + self.dest_neutron, 'qos/policies', + pol['id'], pol) except Exception as e: self.add_error("Failed to create QoS policy %(pol)s: " "%(e)s" % {'pol': pol['id'], 'e': e}) @@ -405,6 +408,9 @@ class ApiReplayClient(utils.PrepareObjectForMigration): body = self.prepare_security_group(sg) new_sg = self.dest_neutron.create_security_group( {'security_group': body}) + self.check_and_apply_tags( + self.dest_neutron, 'security-groups', + sg['id'], sg) LOG.info("Created security-group %(count)s/%(total)s: " "%(sg)s", {'count': count, 'total': total_num, @@ -510,6 +516,9 @@ class ApiReplayClient(utils.PrepareObjectForMigration): try: new_router = (self.dest_neutron.create_router( {'router': body})) + self.check_and_apply_tags( + self.dest_neutron, 'routers', + router['id'], router) LOG.info("created router %(count)s/%(total)s: %(rtr)s", {'count': count, 'total': total_num, 'rtr': new_router}) @@ -637,6 +646,9 @@ class ApiReplayClient(utils.PrepareObjectForMigration): try: created_net = self.dest_neutron.create_network( {'network': body})['network'] + self.check_and_apply_tags( + self.dest_neutron, 'networks', network['id'], network) + LOG.info("Created network %(count)s/%(total)s: %(net)s", {'count': count, 'total': total_num, 'net': created_net}) @@ -694,6 +706,9 @@ class ApiReplayClient(utils.PrepareObjectForMigration): try: created_subnet = self.dest_neutron.create_subnet( {'subnet': body})['subnet'] + self.check_and_apply_tags( + self.dest_neutron, 'subnets', + subnet['id'], subnet) LOG.info("Created subnet: %s", created_subnet['id']) subnets_map[subnet_id] = created_subnet['id'] if enable_dhcp: @@ -774,6 +789,9 @@ class ApiReplayClient(utils.PrepareObjectForMigration): del body['device_id'] created_port = self.dest_neutron.create_port( {'port': body})['port'] + self.check_and_apply_tags( + self.dest_neutron, 'ports', + port['id'], port) LOG.info("Created interface port %(port)s (subnet " "%(subnet)s, ip %(ip)s, mac %(mac)s)", {'port': created_port['id'], @@ -801,6 +819,9 @@ class ApiReplayClient(utils.PrepareObjectForMigration): try: created_port = self.dest_neutron.create_port( {'port': body})['port'] + self.check_and_apply_tags( + self.dest_neutron, 'ports', + port['id'], port) except Exception as e: # NOTE(arosen): this occurs here if you run the # script multiple times as we don't track this. @@ -844,6 +865,9 @@ class ApiReplayClient(utils.PrepareObjectForMigration): body = self.prepare_floatingip(source_fip) try: fip = self.dest_neutron.create_floatingip({'floatingip': body}) + self.check_and_apply_tags( + self.dest_neutron, 'floatingips', + source_fip['id'], source_fip) LOG.info("Created floatingip %(count)s/%(total)s : %(fip)s", {'count': count, 'total': total_num, 'fip': fip}) except Exception as e: diff --git a/vmware_nsx/api_replay/utils.py b/vmware_nsx/api_replay/utils.py index d067f9cf4b..72013e4d30 100644 --- a/vmware_nsx/api_replay/utils.py +++ b/vmware_nsx/api_replay/utils.py @@ -141,6 +141,17 @@ class PrepareObjectForMigration(object): if 'description' in body and body['description'] is None: body['description'] = '' + def check_and_apply_tags(self, client, resource_type, + resource_id, resource_data): + """Check if a resource has tags, and apply them. + + The routine calls tag API once for each tag as Neutron API does not + support bulk addition of tags. + """ + tags = resource_data.get('tags', []) + for tag in tags: + client.add_tag(resource_type, resource_id, tag) + # direct_call arg means that the object is prepared for calling the plugin # create method directly def prepare_security_group_rule(self, sg_rule, direct_call=False):