From 7273802eac4857b11cbd2c9e9db19924562238a2 Mon Sep 17 00:00:00 2001 From: asarfaty Date: Sun, 14 Feb 2021 19:59:44 +0200 Subject: [PATCH] V2T migration: Migrate neutron quotas Change-Id: Id0af91880b90737aa804b4258a28120653553000 --- vmware_nsx/api_replay/client.py | 26 +++++++++++++++++++++++++- vmware_nsx/api_replay/utils.py | 9 +++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/vmware_nsx/api_replay/client.py b/vmware_nsx/api_replay/client.py index ad1ce44ea6..0d40544cbc 100644 --- a/vmware_nsx/api_replay/client.py +++ b/vmware_nsx/api_replay/client.py @@ -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 @@ -636,7 +660,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 diff --git a/vmware_nsx/api_replay/utils.py b/vmware_nsx/api_replay/utils.py index 80236d3019..697f15bf0e 100644 --- a/vmware_nsx/api_replay/utils.py +++ b/vmware_nsx/api_replay/utils.py @@ -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)