Merge "[API Replay] Support Neutron tag extension" into stable/victoria

This commit is contained in:
Zuul 2021-05-17 16:47:02 +00:00 committed by Gerrit Code Review
commit 20300895d8
2 changed files with 35 additions and 0 deletions

View File

@ -354,6 +354,9 @@ class ApiReplayClient(utils.PrepareObjectForMigration):
body = self.prepare_qos_policy(pol) body = self.prepare_qos_policy(pol)
new_pol = self.dest_neutron.create_qos_policy( new_pol = self.dest_neutron.create_qos_policy(
body={'policy': body}) body={'policy': body})
self.check_and_apply_tags(
self.dest_neutron, 'qos/policies',
pol['id'], pol)
except Exception as e: except Exception as e:
self.add_error("Failed to create QoS policy %(pol)s: " self.add_error("Failed to create QoS policy %(pol)s: "
"%(e)s" % {'pol': pol['id'], 'e': e}) "%(e)s" % {'pol': pol['id'], 'e': e})
@ -405,6 +408,9 @@ class ApiReplayClient(utils.PrepareObjectForMigration):
body = self.prepare_security_group(sg) body = self.prepare_security_group(sg)
new_sg = self.dest_neutron.create_security_group( new_sg = self.dest_neutron.create_security_group(
{'security_group': body}) {'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: " LOG.info("Created security-group %(count)s/%(total)s: "
"%(sg)s", "%(sg)s",
{'count': count, 'total': total_num, {'count': count, 'total': total_num,
@ -510,6 +516,9 @@ class ApiReplayClient(utils.PrepareObjectForMigration):
try: try:
new_router = (self.dest_neutron.create_router( new_router = (self.dest_neutron.create_router(
{'router': body})) {'router': body}))
self.check_and_apply_tags(
self.dest_neutron, 'routers',
router['id'], router)
LOG.info("created router %(count)s/%(total)s: %(rtr)s", LOG.info("created router %(count)s/%(total)s: %(rtr)s",
{'count': count, 'total': total_num, {'count': count, 'total': total_num,
'rtr': new_router}) 'rtr': new_router})
@ -637,6 +646,9 @@ class ApiReplayClient(utils.PrepareObjectForMigration):
try: try:
created_net = self.dest_neutron.create_network( created_net = self.dest_neutron.create_network(
{'network': body})['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", LOG.info("Created network %(count)s/%(total)s: %(net)s",
{'count': count, 'total': total_num, {'count': count, 'total': total_num,
'net': created_net}) 'net': created_net})
@ -694,6 +706,9 @@ class ApiReplayClient(utils.PrepareObjectForMigration):
try: try:
created_subnet = self.dest_neutron.create_subnet( created_subnet = self.dest_neutron.create_subnet(
{'subnet': body})['subnet'] {'subnet': body})['subnet']
self.check_and_apply_tags(
self.dest_neutron, 'subnets',
subnet['id'], subnet)
LOG.info("Created subnet: %s", created_subnet['id']) LOG.info("Created subnet: %s", created_subnet['id'])
subnets_map[subnet_id] = created_subnet['id'] subnets_map[subnet_id] = created_subnet['id']
if enable_dhcp: if enable_dhcp:
@ -774,6 +789,9 @@ class ApiReplayClient(utils.PrepareObjectForMigration):
del body['device_id'] del body['device_id']
created_port = self.dest_neutron.create_port( created_port = self.dest_neutron.create_port(
{'port': body})['port'] {'port': body})['port']
self.check_and_apply_tags(
self.dest_neutron, 'ports',
port['id'], port)
LOG.info("Created interface port %(port)s (subnet " LOG.info("Created interface port %(port)s (subnet "
"%(subnet)s, ip %(ip)s, mac %(mac)s)", "%(subnet)s, ip %(ip)s, mac %(mac)s)",
{'port': created_port['id'], {'port': created_port['id'],
@ -801,6 +819,9 @@ class ApiReplayClient(utils.PrepareObjectForMigration):
try: try:
created_port = self.dest_neutron.create_port( created_port = self.dest_neutron.create_port(
{'port': body})['port'] {'port': body})['port']
self.check_and_apply_tags(
self.dest_neutron, 'ports',
port['id'], port)
except Exception as e: except Exception as e:
# NOTE(arosen): this occurs here if you run the # NOTE(arosen): this occurs here if you run the
# script multiple times as we don't track this. # script multiple times as we don't track this.
@ -844,6 +865,9 @@ class ApiReplayClient(utils.PrepareObjectForMigration):
body = self.prepare_floatingip(source_fip) body = self.prepare_floatingip(source_fip)
try: try:
fip = self.dest_neutron.create_floatingip({'floatingip': body}) 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", LOG.info("Created floatingip %(count)s/%(total)s : %(fip)s",
{'count': count, 'total': total_num, 'fip': fip}) {'count': count, 'total': total_num, 'fip': fip})
except Exception as e: except Exception as e:

View File

@ -141,6 +141,17 @@ class PrepareObjectForMigration(object):
if 'description' in body and body['description'] is None: if 'description' in body and body['description'] is None:
body['description'] = '' 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 # direct_call arg means that the object is prepared for calling the plugin
# create method directly # create method directly
def prepare_security_group_rule(self, sg_rule, direct_call=False): def prepare_security_group_rule(self, sg_rule, direct_call=False):