def delete_old_dhcp_edge(context, old_edge_id, bindings): LOG.info(_LI("Deleting the old DHCP edge: %s"), old_edge_id) # using one of the router-ids in the bindings for the deleting dhcp_names = [binding['router_id'] for binding in bindings] dhcp_name = dhcp_names[0] with locking.LockManager.get_lock(old_edge_id): # Delete from NSXv backend # (using the first dhcp name as the "router name") # Note - If we will not delete the router, but free it - it will be # immediately used as the new one, So it is better to delete it. try: nsxv.delete_edge(old_edge_id) except Exception as e: LOG.warning(_LW("Failed to delete the old edge %(id)s: %(e)s"), { 'id': old_edge_id, 'e': e }) # Continue the process anyway # The edge may have been already deleted at the backend try: # Remove bindings from Neutron DB nsxv_db.delete_nsxv_router_binding(context.session, dhcp_name) nsxv_db.clean_edge_vnic_binding(context.session, old_edge_id) except Exception as e: LOG.warning( _LW("Failed to delete the old edge %(id)s from the " "DB : %(e)s"), { 'id': old_edge_id, 'e': e })
def delete_old_dhcp_edge(context, old_edge_id, bindings): LOG.info("Deleting the old DHCP edge: %s", old_edge_id) with locking.LockManager.get_lock(old_edge_id): # Delete from NSXv backend # Note - If we will not delete the router, but free it - it will be # immediately used as the new one, So it is better to delete it. try: nsxv.delete_edge(old_edge_id) except Exception as e: LOG.warning("Failed to delete the old edge %(id)s: %(e)s", { 'id': old_edge_id, 'e': e }) # Continue the process anyway # The edge may have been already deleted at the backend try: # Remove bindings from Neutron DB nsxv_db.clean_edge_router_binding(context.session, old_edge_id) nsxv_db.clean_edge_vnic_binding(context.session, old_edge_id) except Exception as e: LOG.warning( "Failed to delete the old edge %(id)s from the " "DB : %(e)s", { 'id': old_edge_id, 'e': e })
def delete_edge(self, context, router_id, edge_id, dist=False): LOG.debug("Deleting edge %s", edge_id) if context is None: context = q_context.get_admin_context() try: LOG.debug("Deleting router binding %s", router_id) nsxv_db.delete_nsxv_router_binding(context.session, router_id) if not dist: LOG.debug("Deleting vnic bindings for edge %s", edge_id) nsxv_db.clean_edge_vnic_binding(context.session, edge_id) except sa_exc.NoResultFound: LOG.warning("Router Binding for %s not found", router_id) if edge_id: try: self.vcns.delete_edge(edge_id) return True except exceptions.ResourceNotFound: return True except exceptions.VcnsApiException as e: LOG.exception( "VCNS: Failed to delete %(edge_id)s:\n" "%(response)s", { 'edge_id': edge_id, 'response': e.response }) return False except Exception: LOG.exception("VCNS: Failed to delete %s", edge_id) return False
def _delete_backup_from_neutron_db(edge_id, router_id): # Remove bindings from Neutron DB edgeapi = utils.NeutronDbClient() nsxv_db.delete_nsxv_router_binding( edgeapi.context.session, router_id) if edge_id: nsxv_db.clean_edge_vnic_binding(edgeapi.context.session, edge_id)
def delete_edge(self, context, router_id, edge_id, dist=False): try: nsxv_db.delete_nsxv_router_binding(context.session, router_id) if not dist: nsxv_db.clean_edge_vnic_binding(context.session, edge_id) except sa_exc.NoResultFound: LOG.warning(_LW("Router Binding for %s not found"), router_id) if edge_id: try: self.vcns.delete_edge(edge_id) return True except exceptions.ResourceNotFound: return True except exceptions.VcnsApiException as e: LOG.exception( _LE("VCNS: Failed to delete %(edge_id)s:\n" "%(response)s"), { 'edge_id': edge_id, 'response': e.response }) return False except Exception: LOG.exception(_LE("VCNS: Failed to delete %s"), edge_id) return False
def delete_edge(self, context, router_id, edge_id, dist=False): LOG.debug("Deleting edge %s", edge_id) if context is None: context = q_context.get_admin_context() try: LOG.debug("Deleting router binding %s", router_id) nsxv_db.delete_nsxv_router_binding(context.session, router_id) if not dist: LOG.debug("Deleting vnic bindings for edge %s", edge_id) nsxv_db.clean_edge_vnic_binding(context.session, edge_id) except sa_exc.NoResultFound: LOG.warning("Router Binding for %s not found", router_id) if edge_id: try: self.vcns.delete_edge(edge_id) return True except exceptions.ResourceNotFound: return True except exceptions.VcnsApiException as e: LOG.exception("VCNS: Failed to delete %(edge_id)s:\n" "%(response)s", {'edge_id': edge_id, 'response': e.response}) return False except Exception: LOG.exception("VCNS: Failed to delete %s", edge_id) return False
def nsx_clean_backup_edge(resource, event, trigger, **kwargs): """Delete backup edge""" errmsg = ("Need to specify edge-id property. Add --property " "edge-id=<edge-id>") if not kwargs.get('property'): LOG.error(_LE("%s"), errmsg) return properties = admin_utils.parse_multi_keyval_opt(kwargs['property']) edge_id = properties.get('edge-id') if not edge_id: LOG.error(_LE("%s"), errmsg) return try: edge = nsxv.get_edge(edge_id) except exceptions.NeutronException as x: LOG.error(_LE("%s"), str(x)) else: # edge[0] is response status code # edge[1] is response body backup_edges = [e['id'] for e in get_nsxv_backup_edges()] if (not edge[1]['name'].startswith('backup-') or edge[1]['id'] not in backup_edges): LOG.error(_LE('Edge: %s is not a backup edge; aborting delete'), edge_id) return confirm = admin_utils.query_yes_no("Do you want to delete edge: %s" % edge_id, default="no") if not confirm: LOG.info(_LI("Backup edge deletion aborted by user")) return try: with locking.LockManager.get_lock(edge_id): # Delete from NSXv backend nsxv.delete_edge(edge_id) # Remove bindings from Neutron DB edgeapi = utils.NeutronDbClient() nsxv_db.delete_nsxv_router_binding(edgeapi.context.session, edge[1]['name']) nsxv_db.clean_edge_vnic_binding(edgeapi.context.session, edge_id) except Exception as expt: LOG.error(_LE("%s"), str(expt))
def nsx_clean_backup_edge(resource, event, trigger, **kwargs): """Delete backup edge""" errmsg = ("Need to specify edge-id property. Add --property " "edge-id=<edge-id>") if not kwargs.get('property'): LOG.error(_LE("%s"), errmsg) return properties = admin_utils.parse_multi_keyval_opt(kwargs['property']) edge_id = properties.get('edge-id') if not edge_id: LOG.error(_LE("%s"), errmsg) return try: edge = nsxv.get_edge(edge_id) except exceptions.NeutronException as e: LOG.error(_LE("%s"), str(e)) else: # edge[0] is response status code # edge[1] is response body backup_edges = [e['id'] for e in get_nsxv_backup_edges()] if (not edge[1]['name'].startswith('backup-') or edge[1]['id'] not in backup_edges): LOG.error( _LE('Edge: %s is not a backup edge; aborting delete'), edge_id) return confirm = admin_utils.query_yes_no( "Do you want to delete edge: %s" % edge_id, default="no") if not confirm: LOG.info(_LI("Backup edge deletion aborted by user")) return try: with locking.LockManager.get_lock(edge_id): # Delete from NSXv backend nsxv.delete_edge(edge_id) # Remove bindings from Neutron DB edgeapi = utils.NeutronDbClient() nsxv_db.delete_nsxv_router_binding( edgeapi.context.session, edge[1]['name']) nsxv_db.clean_edge_vnic_binding(edgeapi.context.session, edge_id) except Exception as e: LOG.error(_LE("%s"), str(e))
def delete_old_edge(context, old_edge_id): LOG.info("Deleting the old edge: %s", old_edge_id) # clean it up from the DB nsxv_db.clean_edge_router_binding(context.session, old_edge_id) nsxv_db.clean_edge_vnic_binding(context.session, old_edge_id) nsxv_db.cleanup_nsxv_edge_firewallrule_binding(context.session, old_edge_id) with locking.LockManager.get_lock(old_edge_id): # Delete from NSXv backend # Note - If we will not delete the edge, but free it - it will be # immediately used as the new one, So it is better to delete it. try: nsxv = utils.get_nsxv_client() nsxv.delete_edge(old_edge_id) except Exception as e: LOG.warning("Failed to delete the old edge %(id)s: %(e)s", {'id': old_edge_id, 'e': e})
def delete_old_edge(context, old_edge_id): LOG.info(_LI("Deleting the old edge: %s"), old_edge_id) # clean it up from the DB nsxv_db.clean_edge_router_binding(context.session, old_edge_id) nsxv_db.clean_edge_vnic_binding(context.session, old_edge_id) nsxv_db.cleanup_nsxv_edge_firewallrule_binding(context.session, old_edge_id) with locking.LockManager.get_lock(old_edge_id): # Delete from NSXv backend # Note - If we will not delete the edge, but free it - it will be # immediately used as the new one, So it is better to delete it. try: nsxv = utils.get_nsxv_client() nsxv.delete_edge(old_edge_id) except Exception as e: LOG.warning(_LW("Failed to delete the old edge %(id)s: %(e)s"), {'id': old_edge_id, 'e': e})
def delete_old_dhcp_edge(context, old_edge_id, bindings): LOG.info("Deleting the old DHCP edge: %s", old_edge_id) with locking.LockManager.get_lock(old_edge_id): # Delete from NSXv backend # Note - If we will not delete the router, but free it - it will be # immediately used as the new one, So it is better to delete it. try: nsxv.delete_edge(old_edge_id) except Exception as e: LOG.warning("Failed to delete the old edge %(id)s: %(e)s", {'id': old_edge_id, 'e': e}) # Continue the process anyway # The edge may have been already deleted at the backend try: # Remove bindings from Neutron DB nsxv_db.clean_edge_router_binding(context.session, old_edge_id) nsxv_db.clean_edge_vnic_binding(context.session, old_edge_id) except Exception as e: LOG.warning("Failed to delete the old edge %(id)s from the " "DB : %(e)s", {'id': old_edge_id, 'e': e})