コード例 #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()