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)
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)
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'])
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
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'])
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
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
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
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'])
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()
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
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'])
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
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
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
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
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'])
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
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
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'])
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'])
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()
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()
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()
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()
# 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()