def get_secgroup_uuids(self, security_groups): '''Returns a list of security group UUIDs. Args: security_groups: List of security group names or UUIDs ''' seclist = [] all_groups = None for sg in security_groups: if uuidutils.is_uuid_like(sg): seclist.append(sg) else: if not all_groups: response = self.client().list_security_groups() all_groups = response['security_groups'] same_name_groups = [g for g in all_groups if g['name'] == sg] groups = [g['id'] for g in same_name_groups] if len(groups) == 0: raise exception.PhysicalResourceNotFound(resource_id=sg) elif len(groups) == 1: seclist.append(groups[0]) else: # for admin roles, can get the other users' # securityGroups, so we should match the tenant_id with # the groups, and return the own one own_groups = [ g['id'] for g in same_name_groups if g['tenant_id'] == self.context.tenant_id ] if len(own_groups) == 1: seclist.append(own_groups[0]) else: raise exception.PhysicalResourceNameAmbiguity(name=sg) return seclist
def find_physical_resource(self, cnxt, physical_resource_id): """ Return an identifier for the resource with the specified physical resource ID. arg1 -> RPC context. arg2 -> The physical resource ID to look up. """ rs = db_api.resource_get_by_physical_resource_id( cnxt, physical_resource_id) if not rs: raise exception.PhysicalResourceNotFound( resource_id=physical_resource_id) stack = parser.Stack.load(cnxt, stack=rs.stack) resource = stack[rs.name] return dict(resource.identifier())
def get_secgroup_uuids(security_groups, client, tenant_id): ''' Returns a list of security group UUIDs. Args: security_groups: List of security group names or UUIDs client: reference to neutronclient tenant_id: the tenant id to match the security_groups ''' warnings.warn('neutron.NeutronResource.get_secgroup_uuids is ' 'deprecated. Use ' 'self.client_plugin("neutron").get_secgroup_uuids') seclist = [] all_groups = None for sg in security_groups: if uuidutils.is_uuid_like(sg): seclist.append(sg) else: if not all_groups: response = client.list_security_groups() all_groups = response['security_groups'] same_name_groups = [g for g in all_groups if g['name'] == sg] groups = [g['id'] for g in same_name_groups] if len(groups) == 0: raise exception.PhysicalResourceNotFound(resource_id=sg) elif len(groups) == 1: seclist.append(groups[0]) else: # for admin roles, can get the other users' # securityGroups, so we should match the tenant_id with # the groups, and return the own one own_groups = [ g['id'] for g in same_name_groups if g['tenant_id'] == tenant_id ] if len(own_groups) == 1: seclist.append(own_groups[0]) else: raise exception.PhysicalResourceNameAmbiguity(name=sg) return seclist
def get_secgroup_uuids(security_groups, client): ''' Returns a list of security group UUIDs. Args: security_groups: List of security group names or UUIDs client: reference to neutronclient ''' seclist = [] all_groups = None for sg in security_groups: if uuidutils.is_uuid_like(sg): seclist.append(sg) else: if not all_groups: response = client.list_security_groups() all_groups = response['security_groups'] groups = [g['id'] for g in all_groups if g['name'] == sg] if len(groups) == 0: raise exception.PhysicalResourceNotFound(resource_id=sg) if len(groups) > 1: raise exception.PhysicalResourceNameAmbiguity(name=sg) seclist.append(groups[0]) return seclist