[Admin utils] Add a command to build edge mappings file

This will create a JSON file used for edge cutover in V2T
migration.

Change-Id: If9f76e3c7d94db956f04ff41392e2a51bdeb2a81
This commit is contained in:
Salvatore Orlando 2021-06-29 10:13:57 -07:00 committed by Salvatore Orlando
parent 03821d9534
commit b6e0c5decd
2 changed files with 38 additions and 1 deletions

View File

@ -650,10 +650,45 @@ def list_ports_vif_ids(resource, event, trigger, **kwargs):
LOG.info("Mapping data saved into %s", filename)
@admin_utils.output_header
def build_edge_mapping_file(resource, event, trigger, **kwargs):
filename = None
if kwargs.get('property'):
properties = admin_utils.parse_multi_keyval_opt(kwargs['property'])
filename = properties.get('map-file')
context = n_context.get_admin_context()
mappings = []
with utils.NsxVPluginWrapper() as plugin:
routers = plugin.get_routers(context)
for router in routers:
if router.get('distributed'):
binding = nsxv_db.get_nsxv_router_binding(context.session,
router['id'])
if binding:
edge_id = binding['edge_id']
mappings.append(
{'v_edges': [edge_id],
'policy_gateway_name': router['id']})
data = [{'name': 'dlr_edges_to_migrate',
'v_edges_to_policy_gateways_mappings': mappings}]
LOG.info(formatters.output_formatter(
"DLR/Neutron router id mappings", mappings,
['v_edges', 'policy_gateway_name']))
if filename:
f = open(filename, "w")
f.write("%s" % jsonutils.dumps(data))
f.close()
LOG.info("Edge mapping data saved into %s", filename)
registry.subscribe(validate_config_for_migration,
constants.NSX_MIGRATE_V_T,
shell.Operations.VALIDATE.value)
registry.subscribe(build_edge_mapping_file,
constants.NSX_MIGRATE_V_T,
shell.Operations.CUTOVER_MAPPINGS.value)
registry.subscribe(list_ports_vif_ids,
constants.PORTS,
shell.Operations.LIST.value)

View File

@ -79,6 +79,7 @@ class Operations(enum.Enum):
UPDATE_FIREWALL_MATCH = 'update-nat-firewall-match'
SET_STATUS_ERROR = 'set-status-error'
CHECK_COMPUTE_CLUSTERS = 'check-compute-clusters'
CUTOVER_MAPPINGS = 'mappings-for-edge-cutover'
ops = [op.value for op in Operations]
@ -260,7 +261,8 @@ nsxv_resources = {
[Operations.CREATE.value,
Operations.DELETE.value]),
constants.NSX_MIGRATE_V_T: Resource(constants.NSX_MIGRATE_V_T,
[Operations.VALIDATE.value]),
[Operations.VALIDATE.value,
Operations.CUTOVER_MAPPINGS.value]),
constants.PORTS: Resource(constants.PORTS,
[Operations.LIST.value]),
constants.LOADBALANCERS: Resource(constants.LOADBALANCERS,