Add script to clean up all backup edges owned by Neutron

When Neutron server is deleted, we need to clean up all backup
edges created by neutron server. The current clean-all cannot address
the scenario that many neutron servers are using same NSXv backend.

Change-Id: I4f4d19adf7293c2c91c2cd8b52359bb1eb338b84
This commit is contained in:
yuyangbj 2018-04-19 11:20:56 +08:00
parent 5119fd0355
commit 998a245512
2 changed files with 25 additions and 7 deletions

View File

@ -127,9 +127,9 @@ Backup Edges
nsxadmin -r backup-edges -o clean --property edge-id=edge-9 [--force]
- Delete all backup edges::
- Delete all backup edges existing in both neutron and backend when scope is neutron, else backend only::
nsxadmin -r backup-edges -o clean-all [--force]
nsxadmin -r backup-edges -o clean-all --property scope=[neutron/all] [--force]
- List Edge name mismatches between DB and backend, and backup edges that are missing from the backend::

View File

@ -37,7 +37,7 @@ nsxv = utils.get_nsxv_client()
_uuid = uuidutils.generate_uuid
def get_nsxv_backup_edges():
def get_nsxv_backup_edges(scope="all"):
edges = utils.get_nsxv_backend_edges()
backup_edges = []
edgeapi = utils.NeutronDbClient()
@ -46,9 +46,19 @@ def get_nsxv_backup_edges():
# Make sure it is really a backup edge
edge_vnic_binds = nsxv_db.get_edge_vnic_bindings_by_edge(
edgeapi.context.session, edge['id'])
if not edge_vnic_binds:
extend_edge_info(edge)
backup_edges.append(edge)
if scope != "all":
# Make sure the backup edge exists in neutron
# Return backup edges existing in both neutron and backend
# when scope != all
edge_in_neutron = nsxv_db.get_nsxv_router_binding_by_edge(
edgeapi.context.session, edge['id'])
if not edge_vnic_binds and edge_in_neutron:
extend_edge_info(edge)
backup_edges.append(edge)
else:
if not edge_vnic_binds:
extend_edge_info(edge)
backup_edges.append(edge)
return backup_edges
@ -138,7 +148,15 @@ def nsx_clean_backup_edge(resource, event, trigger, **kwargs):
def nsx_clean_all_backup_edges(resource, event, trigger, **kwargs):
"""Delete all backup edges"""
backup_edges = get_nsxv_backup_edges()
scope = "all"
if kwargs.get('property'):
properties = admin_utils.parse_multi_keyval_opt(kwargs['property'])
scope = properties.get("scope", "all")
if scope not in ["neutron", "all"]:
LOG.error("Need to specify the scope in ['neutron', 'all']")
return
backup_edges = get_nsxv_backup_edges(scope=scope)
if not kwargs.get('force'):
#ask for the user confirmation