def destroy_myself(mgr_or_client, **kwargs):
    skip_fip = kwargs.pop('skip_fip',
                          kwargs.pop('skip_floatingip', False))
    force_rm_fip = kwargs.pop('force_rm_fip', False)
    if force_rm_fip:
        skip_fip = False
    spattern = mdata.get_name_search_pattern(**kwargs)
    net_client = Q._g_neutron_client(mgr_or_client)
    tenant_id = kwargs.pop('tenant_id', net_client.tenant_id)
    # rm floatingips: be aware that VMs' might have FIP attached
    # if fail, caller of d_myself should sleep then retry again
    if not skip_fip:
        # TODO(akang): no name attributes in floatingip
        # for now, delete fip if it is not ACTIVE status
        for fip in Q.floatingip_list(mgr_or_client, tenant_id=tenant_id):
            if force_rm_fip or fip['status'] != 'ACTIVE':
                Q.floatingip_delete(mgr_or_client, fip['id'])
    # rm routers
    routers = Q.router_list(mgr_or_client, tenant_id=tenant_id)
    for router in routers:
        if mdata.is_in_spattern(router['name'], spattern):
            delete_this_router(mgr_or_client, router)
    # rm networks/subnets
    for network in Q.network_list(mgr_or_client, tenant_id=tenant_id):
        if mdata.is_in_spattern(network['name'], spattern):
            # TODO(akang): if ports assoc to net, delete them first
            # look for network's subnet which is in port
            Q.network_delete(mgr_or_client, network['id'])

    for sg in Q.security_group_list(mgr_or_client, tenant_id=tenant_id):
        if (mdata.is_in_spattern(sg['name'], spattern) and
                sg['name'] not in ['default']):
            Q.security_group_delete(mgr_or_client, sg['id'])
Ejemplo n.º 2
0
def destroy_all_servers(mgr_or_client, **kwargs):
    spattern = mdata.get_name_search_pattern(**kwargs)
    for s in list_all_servers(mgr_or_client):
        if mdata.is_in_spattern(s['name'], spattern):
            server_delete(mgr_or_client, s['id'])
Ejemplo n.º 3
0
def destroy_my_servers(mgr_or_client, **kwargs):
    spattern = mdata.get_name_search_pattern(**kwargs)
    for s in server_list(mgr_or_client):
        # if spattern not provided, default is True
        if mdata.is_in_spattern(s['name'], spattern):
            server_delete(mgr_or_client, s['id'])