示例#1
0
def main():
    tempest_tenant_names = ["Tempest", "Tempest2"]

    print "[INIT]"
    print "Initializing openstack clients...",
    mgr = OSClientManager.create_from_env_vars()
    print "DONE"

    print "Fetching Tenants...",
    tenants = mgr.identity_client.tenants.list()
    tenant_ids = [tenant.id for tenant in tenants]
    temptest_tenant_ids = [tenant.id for tenant in tenants
                           if tenant.name in tempest_tenant_names]

    print "DONE"

    print "Fetching Users...",
    users = mgr.identity_client.users.list()
    print "DONE"

    print "[CLEANING UP INSTANCES]"
    print "Fetching instances...",
    instances = mgr.compute_client.servers.list(True, {"all_tenants": "1"})
    print "DONE"
    operation_list = OperationList()
    for instance in instances:
        tenant_id = instance.tenant_id
        if (tenant_id not in tenant_ids) or (tenant_id in temptest_tenant_ids):
            tenant = _find_by_id(tenants, instance.tenant_id)
            user = _find_by_id(users, instance.user_id)
            tenant_name = "N/A" if tenant == None else tenant.name
            user_name = "N/A" if user == None else user.name

            operation_list.add_operation(
                "Delete %s (Tenant:%s, User: %s)" % (instance.name,
                                                     tenant_name,
                                                     user_name), instance
                .delete)

    operation_list.confirm_and_execute()


    print "[CLEANING UP VOLUMES]"

    print "Fetching volumes...",
    volumes = mgr.volume_client.volumes.findall()
    print "DONE"

    print "Cleaning up Tempest volumes"

    operation_list = OperationList()

    for volume in volumes:
        tenant_id = getattr(volume, 'os-vol-tenant-attr:tenant_id')
        #user_id =
        if (tenant_id not in tenant_ids) or (tenant_id in temptest_tenant_ids):
            tenant = _find_by_id(tenants, tenant_id)
            tenant_name = "N/A" if tenant == None else tenant.name
            operation_list.add_operation("Delete %s (tenant:%s)" % (
                volume.display_name, tenant_name),
                                         volume.delete)

    operation_list.confirm_and_execute()
import os
from common.shared import delete_resource
from common.os_client_manager import OSClientManager
from neutronclient.v2_0.client import Client



#TODO: delete a list of resources


if __name__ == "__main__":


	mgr = OSClientManager.create_from_env_vars()

    neutron_client = mgr.network_client

    print "DETERMINING WHAT SHOULD BE KEPT...",
    all_networks = neutron_client.list_networks()
    skip_network_names = ["public", "private"]
    skip_network_ids = [network["id"] for network in all_networks["networks"] if
                        network["name"] in skip_network_names]

    all_subnets = neutron_client.list_subnets()
    skip_subnet_ids = [subnet["id"] for subnet in all_subnets["subnets"] if
                       subnet["network_id"] in skip_network_ids]
    print "DONE"

    
    print "CLEANING UP FWAAS"
    firewalls = neutron_client.list_firewalls() 
示例#3
0
def main():
    dns_processes = map_dnsprocess_to_networks()

    mgr = OSClientManager.create_from_env_vars()
    network_client = mgr.network_client

    neutron_routers = network_client.list_routers()
    neutron_routers = {router['id']: router for router in
                       neutron_routers['routers']}

    neutron_networks = network_client.list_networks()
    neutron_networks = {network['id']: network for network in
                        neutron_networks['networks']}


    # TODO change this so that we start from neutron networks and then try
    # to map to namespaces (instead of namespaces to networks).

    # list over all namespaces and match corresponding openstack resources
    routers = []
    networks = []
    for ns in NamespaceDriver.list_namespaces():
        if ns.startswith("qdhcp-"):
            network_id = ns.replace("qdhcp-", "")
            neutron_network = neutron_networks[network_id]
            network = Network(network_id, ns, neutron_network,
                              dns_processes.get(network_id))
            networks.append(network)

        elif ns.startswith("qrouter-"):
            router_id = ns.replace("qrouter-", "")
            neutron_router = neutron_routers[router_id]
            routers.append(Router(router_id, ns, neutron_router))



    # Print out results
    print "Networks"
    for network in networks:
        print "\t network:%s \t namespace:%s" % (
        network.neutron_network['name'], network.namespace)
        for link in network.links:
            print "\t \t LINK: %s (TYPE: %s, MAC:%s)" % (
            link.name, link.type, link.mac)

    print "Routers"
    for router in routers:
        print "\t router:%s \t namespace:%s" % (
        router.neutron_router['name'], router.namespace)
        for link in router.links:
            print "\t \t LINK: %s (TYPE: %s, MAC:%s)" % (
            link.name, link.type, link.mac)


    # Output HTML File
    template_dir = "os_ns_visualizer/templates"
    output_dir = os.path.expanduser("~")
    output_file = os.path.join(output_dir, "result.html")
    css_file = os.path.join(template_dir, "styles.css")

    print "Creating HTML file (%s)..." % output_file,
    env = Environment(loader=FileSystemLoader(template_dir))
    template = env.get_template('template.html')
    output = template.render(networks=networks, routers=routers)

    f = open(output_file, "w")
    f.write(output)
    f.close()
    shutil.copy(css_file, output_dir)
    print DONE