V2T migration: Migrate neutron quotas

Change-Id: Id0af91880b90737aa804b4258a28120653553000
This commit is contained in:
asarfaty 2021-02-14 19:59:44 +02:00 committed by Adit Sarfaty
parent cec2c15377
commit 4694a05136
2 changed files with 34 additions and 1 deletions

View File

@ -149,6 +149,7 @@ class ApiReplayClient(utils.PrepareObjectForMigration):
LOG.info("Starting NSX migration to %s.", self.dest_plugin)
# Migrate all the objects
self.migrate_quotas()
self.migrate_security_groups()
self.migrate_qos_policies()
routers_routes, routers_gw_info = self.migrate_routers()
@ -224,6 +225,29 @@ class ApiReplayClient(utils.PrepareObjectForMigration):
return False
def migrate_quotas(self):
global n_errors
source_quotas = self.source_neutron.list_quotas()['quotas']
dest_quotas = self.dest_neutron.list_quotas()['quotas']
total_num = len(source_quotas)
LOG.info("Migrating %s neutron quotas", total_num)
for count, quota in enumerate(source_quotas, 1):
dest_quota = self.have_id(quota['project_id'], dest_quotas)
if dest_quota is False:
body = self.prepare_quota(quota)
try:
new_quota = (self.dest_neutron.update_quota(
quota['project_id'], {'quota': body}))
LOG.info("created quota %(count)s/%(total)s: %(q)s",
{'count': count, 'total': total_num,
'q': new_quota})
except Exception as e:
LOG.error("Failed to create quota %(q)s: %(e)s",
{'q': quota, 'e': e})
n_errors = n_errors + 1
def migrate_qos_rule(self, dest_policy, source_rule):
"""Add the QoS rule from the source to the QoS policy
@ -633,7 +657,7 @@ class ApiReplayClient(utils.PrepareObjectForMigration):
# Ignore internal NSXV objects
if port['project_id'] == nsxv_constants.INTERNAL_TENANT_ID:
LOG.info("Skip router %s: Internal NSX-V port",
LOG.info("Skip port %s: Internal NSX-V port",
port['id'])
continue

View File

@ -60,6 +60,11 @@ class PrepareObjectForMigration(object):
drop_sg_rule_fields = basic_ignore_fields
drop_sg_fields = basic_ignore_fields + ['policy']
drop_quota_fields = basic_ignore_fields + [
'tenant_id',
'project_id',
'housekeeper',
'l2-gateway-connection']
drop_router_fields = basic_ignore_fields + [
'status',
'routes',
@ -144,6 +149,10 @@ class PrepareObjectForMigration(object):
self.fix_description(sg)
return self.drop_fields(sg, self.drop_sg_fields)
def prepare_quota(self, quota):
body = self.drop_fields(quota, self.drop_quota_fields)
return body
def prepare_router(self, rtr, dest_azs=None, direct_call=False):
self.fix_description(rtr)
body = self.drop_fields(rtr, self.drop_router_fields)