Esempio n. 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)
Esempio n. 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)
Esempio n. 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'])
Esempio n. 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
Esempio n. 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'])
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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'])
Esempio n. 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()
Esempio n. 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()
Esempio n. 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'])
Esempio n. 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'])
Esempio n. 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
Esempio n. 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'])
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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'])
Esempio n. 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
Esempio n. 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'])
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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'])
Esempio n. 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'])
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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
Esempio n. 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'])
Esempio n. 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'])
Esempio n. 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()
Esempio n. 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()
Esempio n. 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()
Esempio n. 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()
Esempio n. 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()
Esempio n. 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()
Esempio n. 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()
Esempio n. 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()
Esempio n. 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()