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'])
def show_or_create_security_group(mgr_or_client, name,
                                  tenant_id=None, **kwargs):
    sc_list = Q.security_group_list(mgr_or_client, name)
    if len(sc_list) > 0:
        return Q.security_group_show(mgr_or_client, sc_list[0]['id'])
    return Q.security_group_create(mgr_or_client, name,
                                   tenant_id=tenant_id, **kwargs)
def create_security_group_loginable(mgr_or_client, name, **kwargs):
    try:
        sg = Q.security_group_list(mgr_or_client, name=name)[0]
    except Exception:
        sg = Q.security_group_create(mgr_or_client, name)
        create_security_group_ssh_rule(mgr_or_client, sg['id'])
        create_security_group_icmp_rule(mgr_or_client, sg['id'])
    return Q.security_group_show(mgr_or_client, sg['id'])