Esempio n. 1
0
def remove_networks(neutron_client, default_networks, default_routers):
    logger.debug("Removing Neutron objects")
    network_ids = []
    networks = os_utils.get_network_list(neutron_client)
    if networks is None:
        logger.debug("There are no networks in the deployment. ")
    else:
        logger.debug("Existing networks:")
        for network in networks:
            net_id = network['id']
            net_name = network['name']
            logger.debug(" '%s', ID=%s " % (net_name, net_id))
            if (net_id in default_networks
                    and net_name in default_networks.values()):
                logger.debug("   > this is a default network and will "
                             "NOT be deleted.")
            elif network['router:external'] is True:
                logger.debug("   > this is an external network and will "
                             "NOT be deleted.")
            else:
                logger.debug("   > this network will be deleted.")
                network_ids.append(net_id)

    # delete ports
    ports = os_utils.get_port_list(neutron_client)
    if ports is None:
        logger.debug("There are no ports in the deployment. ")
    else:
        remove_ports(neutron_client, ports, network_ids)

    # remove routers
    routers = os_utils.get_router_list(neutron_client)
    if routers is None:
        logger.debug("There are no routers in the deployment. ")
    else:
        remove_routers(neutron_client, routers, default_routers)

    # trozet: wait for Neutron to auto-cleanup HA networks when HA router is
    #  deleted
    time.sleep(5)

    # remove networks
    if network_ids is not None:
        for net_id in network_ids:
            networks = os_utils.get_network_list(neutron_client)
            if networks is None:
                logger.debug("No networks left to remove")
                break
            elif not any(network['id'] == net_id for network in networks):
                logger.debug("Network %s has already been removed" % net_id)
                continue
            logger.debug("Removing network %s ..." % net_id)
            if os_utils.delete_neutron_net(neutron_client, net_id):
                logger.debug("  > Done!")
            else:
                logger.error("There has been a problem removing the "
                             "network %s..." % net_id)
Esempio n. 2
0
def cleanup_neutron(neutron_client, floatingip_ids, bgpvpn_ids, interfaces,
                    subnet_ids, router_ids, network_ids):

    if len(floatingip_ids) != 0:
        for floatingip_id in floatingip_ids:
            if not os_utils.delete_floating_ip(neutron_client, floatingip_id):
                logging.error('Fail to delete all floating ips. '
                              'Floating ip with id {} was not deleted.'.format(
                                  floatingip_id))
                return False

    if len(bgpvpn_ids) != 0:
        for bgpvpn_id in bgpvpn_ids:
            delete_bgpvpn(neutron_client, bgpvpn_id)

    if len(interfaces) != 0:
        for router_id, subnet_id in interfaces:
            if not os_utils.remove_interface_router(neutron_client, router_id,
                                                    subnet_id):
                logging.error(
                    'Fail to delete all interface routers. '
                    'Interface router with id {} was not deleted.'.format(
                        router_id))

    if len(router_ids) != 0:
        for router_id in router_ids:
            if not os_utils.remove_gateway_router(neutron_client, router_id):
                logging.error(
                    'Fail to delete all gateway routers. '
                    'Gateway router with id {} was not deleted.'.format(
                        router_id))

    if len(subnet_ids) != 0:
        for subnet_id in subnet_ids:
            if not os_utils.delete_neutron_subnet(neutron_client, subnet_id):
                logging.error(
                    'Fail to delete all subnets. '
                    'Subnet with id {} was not deleted.'.format(subnet_id))
                return False

    if len(router_ids) != 0:
        for router_id in router_ids:
            if not os_utils.delete_neutron_router(neutron_client, router_id):
                logging.error(
                    'Fail to delete all routers. '
                    'Router with id {} was not deleted.'.format(router_id))
                return False

    if len(network_ids) != 0:
        for network_id in network_ids:
            if not os_utils.delete_neutron_net(neutron_client, network_id):
                logging.error(
                    'Fail to delete all networks. '
                    'Network with id {} was not deleted.'.format(network_id))
                return False
    return True
Esempio n. 3
0
def remove_networks(neutron_client, default_networks, default_routers):
    logger.info("Removing Neutron objects")
    network_ids = []
    networks = os_utils.get_network_list(neutron_client)
    if networks is None:
        logger.debug("There are no networks in the deployment. ")
    else:
        logger.debug("Existing networks:")
        for network in networks:
            net_id = network['id']
            net_name = network['name']
            logger.debug(" '%s', ID=%s " % (net_name, net_id))
            if net_id in default_networks:
                logger.debug("   > this is a default network and will "
                             "NOT be deleted.")
            elif network['router:external'] is True:
                logger.debug("   > this is an external network and will "
                             "NOT be deleted.")
            else:
                logger.debug("   > this network will be deleted.")
                network_ids.append(net_id)

    # delete ports
    ports = os_utils.get_port_list(neutron_client)
    if ports is None:
        logger.debug("There are no ports in the deployment. ")
    else:
        remove_ports(neutron_client, ports, network_ids)

    # remove routers
    routers = os_utils.get_router_list(neutron_client)
    if routers is None:
        logger.debug("There are no routers in the deployment. ")
    else:
        remove_routers(neutron_client, routers, default_routers)

    # remove networks
    if network_ids is not None:
        for net_id in network_ids:
            logger.debug("Removing network %s ..." % net_id)
            if os_utils.delete_neutron_net(neutron_client, net_id):
                logger.debug("  > Done!")
            else:
                logger.error("There has been a problem removing the "
                             "network %s..." % net_id)
Esempio n. 4
0
def remove_networks(neutron_client, default_networks, default_routers):
    logger.info("Removing Neutron objects")
    network_ids = []
    networks = os_utils.get_network_list(neutron_client)
    if networks is None:
        logger.debug("There are no networks in the deployment. ")
    else:
        logger.debug("Existing networks:")
        for network in networks:
            net_id = network['id']
            net_name = network['name']
            logger.debug(" '%s', ID=%s " % (net_name, net_id))
            if net_id in default_networks:
                logger.debug("   > this is a default network and will "
                             "NOT be deleted.")
            elif network['router:external'] is True:
                logger.debug("   > this is an external network and will "
                             "NOT be deleted.")
            else:
                logger.debug("   > this network will be deleted.")
                network_ids.append(net_id)

    # delete ports
    ports = os_utils.get_port_list(neutron_client)
    if ports is None:
        logger.debug("There are no ports in the deployment. ")
    else:
        remove_ports(neutron_client, ports, network_ids)

    # remove routers
    routers = os_utils.get_router_list(neutron_client)
    if routers is None:
        logger.debug("There are no routers in the deployment. ")
    else:
        remove_routers(neutron_client, routers, default_routers)

    # remove networks
    if network_ids is not None:
        for net_id in network_ids:
            logger.debug("Removing network %s ..." % net_id)
            if os_utils.delete_neutron_net(neutron_client, net_id):
                logger.debug("  > Done!")
            else:
                logger.error("There has been a problem removing the "
                             "network %s..." % net_id)