예제 #1
0
def delete_tenant_images(also_shared=False, tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()

    tenant = osclients.get_session().get_project_id()
    glance = osclients.get_glanceclient()
    for image in glance.images.findall(owner=tenant):
        if image.owner != tenant_id:
            continue

        if image.is_public and not also_shared:
            continue
        else:
            glance.images.delete(image.id)
예제 #2
0
def get_tenant_images(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()

    tenant = osclients.get_session().get_project_id()
    public_images = list()
    private_images = list()
    glance = osclients.get_glanceclient()
    for image in glance.images.findall(owner=tenant):
        if image.owner != tenant_id:
            continue
        if image.is_public:
            public_images.append(image.id)
        else:
            private_images.append(image.id)
    return (private_images, public_images)
예제 #3
0
def delete_tenant_networks(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for net in neutron.list_networks()['networks']:
        if net['tenant_id'] != tenant_id:
            continue

        neutron.delete_network(net['id'])
예제 #4
0
def get_tenant_backup_volumes(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()

    volumes = list()
    for volume in cinder.backups.list():
        volumes.append((volume.id, volume.user_id))
    return volumes
예제 #5
0
def delete_tenant_floatingips(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for floatingip in neutron.list_floatingips()['floatingips']:
        if floatingip['tenant_id'] != tenant_id:
            continue

        neutron.delete_floatingip(floatingip['id'])
예제 #6
0
def get_tenant_volume_snapshots(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()

    snapshots = list()
    for snapshot in cinder.volume_snapshots.list():
        snapshots.append(snapshot.id)
    return snapshots
예제 #7
0
def get_tenant_vms(tenant_id=None):
    vms = list()
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()

    for vm in novaclient.servers.list():
        vms.append((vm.id, vm.user_id))
    return vms
예제 #8
0
def get_user_keypairs(tenant_id=None):
    keypairs = list()
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()

    for keypair in novaclient.keypairs.list():
        keypairs.append(keypair.id)
    return keypairs
예제 #9
0
def get_tenant_volume_snapshots(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()

    snapshots = list()
    for snapshot in cinder.volume_snapshots.list():
        snapshots.append(snapshot.id)
    return snapshots
예제 #10
0
def delete_tenant_subnets(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for subnet in neutron.list_subnets()['subnets']:
        if subnet['tenant_id'] != tenant_id:
            continue

        neutron.delete_subnet(subnet['id'])
예제 #11
0
def delete_tenant_security_groups(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()

    for secgroup in novaclient.security_groups.findall():
        if secgroup.name == 'default':
            continue
        secgroup.delete()
예제 #12
0
def delete_tenant_security_groups(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()

    for secgroup in novaclient.security_groups.findall():
        if secgroup.name == 'default':
            continue
        secgroup.delete()
예제 #13
0
def delete_tenant_networks(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for net in neutron.list_networks()['networks']:
        if net['tenant_id'] != tenant_id:
            continue

        neutron.delete_network(net['id'])
예제 #14
0
def delete_tenant_floatingips(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for floatingip in neutron.list_floatingips()['floatingips']:
        if floatingip['tenant_id'] != tenant_id:
            continue

        neutron.delete_floatingip(floatingip['id'])
예제 #15
0
def get_user_keypairs(tenant_id=None):
    keypairs = list()
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()

    for keypair in novaclient.keypairs.list():
        keypairs.append(keypair.id)
    return keypairs
예제 #16
0
def delete_tenant_subnets(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for subnet in neutron.list_subnets()['subnets']:
        if subnet['tenant_id'] != tenant_id:
            continue

        neutron.delete_subnet(subnet['id'])
예제 #17
0
def get_tenant_vms(tenant_id=None):
    vms = list()
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()

    for vm in novaclient.servers.list():
        vms.append((vm.id, vm.user_id))
    return vms
예제 #18
0
def get_tenant_backup_volumes(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()

    volumes = list()
    for volume in cinder.backups.list():
        volumes.append((volume.id, volume.user_id))
    return volumes
예제 #19
0
def get_tenant_ports(tenant_id=None):
    ports = list()
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for port in neutron.list_ports()['ports']:
        if port['tenant_id'] != tenant_id:
            continue
        ports.append(port['id'])
    return ports
예제 #20
0
def delete_tenant_routers(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for router in neutron.list_routers()['routers']:
        if router['tenant_id'] != tenant_id:
            continue

        neutron.remove_gateway_router(router['id'])
        neutron.delete_router(router['id'])
예제 #21
0
def get_tenant_ports(tenant_id=None):
    ports = list()
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for port in neutron.list_ports()['ports']:
        if port['tenant_id'] != tenant_id:
            continue
        ports.append(port['id'])
    return ports
예제 #22
0
def delete_tenant_routers(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for router in neutron.list_routers()['routers']:
        if router['tenant_id'] != tenant_id:
            continue

        neutron.remove_gateway_router(router['id'])
        neutron.delete_router(router['id'])
예제 #23
0
def get_tenant_routers(tenant_id=None):
    routers = list()
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for router in neutron.list_routers()['routers']:
        if router['tenant_id'] != tenant_id:
            continue

        routers.append(router['id'])
    return routers
예제 #24
0
def get_tenant_subnets(tenant_id=None):
    subnets = list()
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for subnet in neutron.list_subnets()['subnets']:
        if subnet['tenant_id'] != tenant_id:
            continue

        subnets.append((subnet['tenant_id'], subnet['id']))
    return subnets
예제 #25
0
def get_tenant_routers(tenant_id=None):
    routers = list()
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for router in neutron.list_routers()['routers']:
        if router['tenant_id'] != tenant_id:
            continue

        routers.append(router['id'])
    return routers
예제 #26
0
def get_tenant_networks(tenant_id=None):
    networks = list()
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for net in neutron.list_networks()['networks']:
        if net['tenant_id'] != tenant_id:
            continue

        networks.append((net['id'], net['shared']))
    return networks
예제 #27
0
def get_tenant_subnets(tenant_id=None):
    subnets = list()
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for subnet in neutron.list_subnets()['subnets']:
        if subnet['tenant_id'] != tenant_id:
            continue

        subnets.append((subnet['tenant_id'], subnet['id']))
    return subnets
예제 #28
0
def get_tenant_floatingips(tenant_id=None):
    floatingips = list()
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for floatingip in neutron.list_floatingips()['floatingips']:
        if floatingip['tenant_id'] != tenant_id:
            continue

        floatingips.append(floatingip['id'])
    return floatingips
예제 #29
0
def get_tenant_networks(tenant_id=None):
    networks = list()
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for net in neutron.list_networks()['networks']:
        if net['tenant_id'] != tenant_id:
            continue

        networks.append((net['id'], net['shared']))
    return networks
예제 #30
0
def get_tenant_floatingips(tenant_id=None):
    floatingips = list()
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for floatingip in neutron.list_floatingips()['floatingips']:
        if floatingip['tenant_id'] != tenant_id:
            continue

        floatingips.append(floatingip['id'])
    return floatingips
예제 #31
0
def delete_tenant_securitygroups(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for security_group in neutron.list_security_groups()['security_groups']:
        if security_group['tenant_id'] != tenant_id:
            continue
        if security_group['name'] == 'default':
            continue

        neutron.delete_security_group(security_group['id'])
예제 #32
0
def delete_tenant_securitygroups(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for security_group in neutron.list_security_groups()['security_groups']:
        if security_group['tenant_id'] != tenant_id:
            continue
        if security_group['name'] == 'default':
            continue

        neutron.delete_security_group(security_group['id'])
예제 #33
0
def get_tenant_security_groups(tenant_id=None):
    security_groups = list()
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()

    for secgroup in novaclient.security_groups.list():
        #print secgroup.tenant_id, secgroup.id
        if secgroup.name == 'default':
            continue
        security_groups.append(secgroup.id)
    return security_groups
예제 #34
0
def get_tenant_securitygroups(tenant_id=None):
    securitygroups = list()
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for security_group in neutron.list_security_groups()['security_groups']:
        if security_group['tenant_id'] != tenant_id:
            continue
        if security_group['name'] == 'default':
            continue
        securitygroups.append(security_group['id'])
    return securitygroups
예제 #35
0
def get_tenant_securitygroups(tenant_id=None):
    securitygroups = list()
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for security_group in neutron.list_security_groups()['security_groups']:
        if security_group['tenant_id'] != tenant_id:
            continue
        if security_group['name'] == 'default':
            continue
        securitygroups.append(security_group['id'])
    return securitygroups
예제 #36
0
def get_tenant_security_groups(tenant_id=None):
    security_groups = list()
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()

    for secgroup in novaclient.security_groups.list():
        #print secgroup.tenant_id, secgroup.id
        if secgroup.name == 'default':
            continue
        security_groups.append(secgroup.id)
    return security_groups
예제 #37
0
def delete_tenant_ports(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for port in neutron.list_ports()['ports']:
        if port['tenant_id'] != tenant_id:
            continue
        if port['device_owner'] == 'network:router_interface':
            subnet = port['fixed_ips'][0]['subnet_id']
            body = {'subnet_id': subnet}
            neutron.remove_interface_router(
                router=port['device_id'], body=body)

        else:
            neutron.delete_port(port['id'])
예제 #38
0
def delete_tenant_ports(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()
    for port in neutron.list_ports()['ports']:
        if port['tenant_id'] != tenant_id:
            continue
        if port['device_owner'] == 'network:router_interface':
            subnet = port['fixed_ips'][0]['subnet_id']
            body = {'subnet_id': subnet}
            neutron.remove_interface_router(router=port['device_id'],
                                            body=body)

        else:
            neutron.delete_port(port['id'])
예제 #39
0
def delete_tenant_backup_volumes(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()

    for volume in cinder.backups.list():
        volume.delete()
예제 #40
0
def delete_user_keypairs(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()

    for keypair in novaclient.keypairs.list():
        keypair.delete()
예제 #41
0
def delete_tenant_vms(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()

    for vm in novaclient.servers.list():
        vm.delete()
예제 #42
0
def delete_user_keypairs(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()

    for keypair in novaclient.keypairs.list():
        keypair.delete()
예제 #43
0
def delete_tenant_backup_volumes(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()

    for volume in cinder.backups.list():
        volume.delete()
예제 #44
0
def delete_tenant_vms(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()

    for vm in novaclient.servers.list():
        vm.delete()
예제 #45
0
def delete_tenant_volume_snapshots(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()

    for snapshot in cinder.volume_snapshots.list():
        snapshot.delete()
예제 #46
0
def delete_tenant_volume_snapshots(tenant_id=None):
    if not tenant_id:
        tenant_id = osclients.get_session().get_project_id()

    for snapshot in cinder.volume_snapshots.list():
        snapshot.delete()
예제 #47
0
# See the License for the specific language governing permissions and
# limitations under the License.
#
# For those usages not covered by the Apache version 2.0 License please
# contact with [email protected]
#

author = 'chema'

import nova
import glance
import cinder
import neutron
import osclients

tenant_id = osclients.get_session().get_project_id()
print 'Tenant id is: ' + tenant_id
print 'User id is: ' + osclients.get_session().get_user_id()
print 'User keypairs:'
print nova.get_user_keypairs()
print 'Tenant VMs:'
print nova.get_tenant_vms()
print 'Tenant security groups (nova):'
print nova.get_tenant_security_groups()

print 'Tenant images:'
print glance.get_tenant_images()

print 'Tenant volume snapshots:'
print cinder.get_tenant_volume_snapshots()