def remove_ports(neutron_client, ports, network_ids): for port in ports: if port['network_id'] in network_ids: port_id = port['id'] try: subnet_id = port['fixed_ips'][0]['subnet_id'] except: logger.info(" > WARNING: Port %s does not contain 'fixed_ips'" % port_id) print port router_id = port['device_id'] if len(port['fixed_ips']) == 0 and router_id == '': logger.debug("Removing port %s ..." % port_id) if (os_utils.delete_neutron_port(neutron_client, port_id)): logger.debug(" > Done!") else: logger.error("There has been a problem removing the " "port %s ..." % port_id) force_remove_port(neutron_client, port_id) elif port['device_owner'] == 'network:router_interface': logger.debug("Detaching port %s (subnet %s) from router %s ..." % (port_id, subnet_id, router_id)) if os_utils.remove_interface_router( neutron_client, router_id, subnet_id): time.sleep(5) # leave 5 seconds to detach logger.debug(" > Done!") else: logger.error("There has been a problem removing the " "interface %s from router %s..." % (subnet_id, router_id)) force_remove_port(neutron_client, port_id) else: force_remove_port(neutron_client, port_id)
def force_remove_port(neutron_client, port_id): logger.debug("Clearing device_owner for port %s ..." % port_id) os_utils.update_neutron_port(neutron_client, port_id, device_owner='clear') logger.debug("Removing port %s ..." % port_id) if os_utils.delete_neutron_port(neutron_client, port_id): logger.debug(" > Done!") else: logger.error("There has been a problem removing the port %s..." % port_id)
def force_remove_port(neutron_client, port_id): logger.debug("Clearing device_owner for port %s ..." % port_id) os_utils.update_neutron_port(neutron_client, port_id, device_owner='clear') logger.debug("Removing port %s ..." % port_id) if os_utils.delete_neutron_port(neutron_client, port_id): logger.debug(" > Done!") else: logger.error("There has been a problem removing the port %s..." % port_id)
def remove_ports(neutron_client, ports, network_ids): for port in ports: if port['network_id'] in network_ids: port_id = port['id'] try: subnet_id = port['fixed_ips'][0]['subnet_id'] except: logger.debug( " > WARNING: Port %s does not contain fixed_ips" % port_id) logger.info(port) router_id = port['device_id'] if len(port['fixed_ips']) == 0 and router_id == '': logger.debug("Removing port %s ..." % port_id) if (os_utils.delete_neutron_port(neutron_client, port_id)): logger.debug(" > Done!") else: logger.error("There has been a problem removing the " "port %s ..." % port_id) force_remove_port(neutron_client, port_id) elif port['device_owner'] == 'network:router_interface': logger.debug( "Detaching port %s (subnet %s) from router %s ..." % (port_id, subnet_id, router_id)) if os_utils.remove_interface_router(neutron_client, router_id, subnet_id): time.sleep(5) # leave 5 seconds to detach logger.debug(" > Done!") else: logger.error("There has been a problem removing the " "interface %s from router %s..." % (subnet_id, router_id)) force_remove_port(neutron_client, port_id) else: force_remove_port(neutron_client, port_id)