def get_routers(neutron_client):
    logger.debug("Getting routers")
    dic_routers = {}
    routers = os_utils.get_router_list(neutron_client)
    if routers is not None:
        for router in routers:
            dic_routers.update({router['id']: router['name']})
    return {'routers': dic_routers}
def get_routers(neutron_client):
    logger.debug("Getting routers")
    dic_routers = {}
    routers = os_utils.get_router_list(neutron_client)
    if routers is not None:
        for router in routers:
            dic_routers.update({router['id']: router['name']})
    return {'routers': dic_routers}
Exemple #3
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)
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)
Exemple #5
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)