def get_tenant_endpoints(self, admin_token, marker, limit, url, tenant_id): self.__validate_service_or_keystone_admin_token(admin_token) if tenant_id == None: raise fault.BadRequestFault("Expecting a Tenant Id") if api.TENANT.get(tenant_id) == None: raise fault.ItemNotFoundFault("The tenant not found") ts = [] dtenant_endpoints = \ api.ENDPOINT_TEMPLATE.\ endpoint_get_by_tenant_get_page( tenant_id, marker, limit) for dtenant_endpoint in dtenant_endpoints: ts.append(Endpoint(dtenant_endpoint.id, url + '/endpointTemplates/' + \ str(dtenant_endpoint.endpoint_template_id))) links = [] if ts.__len__(): prev, next = \ api.ENDPOINT_TEMPLATE.endpoint_get_by_tenant_get_page_markers( tenant_id, marker, limit) if prev: links.append( atom.Link('prev', "%s?'marker=%s&limit=%s'" % (url, prev, limit))) if next: links.append( atom.Link('next', "%s?'marker=%s&limit=%s'" % (url, next, limit))) return Endpoints(ts, links)
def get_tenant_users(self, admin_token, tenant_id, marker, limit, url): self.__validate_token(admin_token, False) if tenant_id == None: raise fault.BadRequestFault("Expecting a Tenant Id") dtenant = api.TENANT.get(tenant_id) if dtenant is None: raise fault.ItemNotFoundFault("The tenant not found") if not dtenant.enabled: raise fault.TenantDisabledFault("Your account has been disabled") ts = [] dtenantusers = api.USER.users_get_by_tenant_get_page( tenant_id, marker, limit) for dtenantuser in dtenantusers: ts.append( User( None, dtenantuser.id, dtenantuser.name, tenant_id, dtenantuser.email, dtenantuser.eppn, dtenantuser.enabled, dtenantuser.tenant_roles if hasattr( dtenantuser, "tenant_roles") else None)) links = [] if ts.__len__(): prev, next = api.USER.users_get_by_tenant_get_page_markers( tenant_id, marker, limit) if prev: links.append( atom.Link('prev', "%s?'marker=%s&limit=%s'" % (url, prev, limit))) if next: links.append( atom.Link('next', "%s?'marker=%s&limit=%s'" % (url, next, limit))) return Users(ts, links)
def get_tenants(self, admin_token, marker, limit, url, is_service_operation=False): """Fetch tenants for either an admin or service operation.""" ts = [] if is_service_operation: # Check regular token validity. (_token, user) = self.__validate_token(admin_token, False) # Return tenants specific to user dtenants = api.TENANT.tenants_for_user_get_page( user, marker, limit) prev_page, next_page = api.TENANT.\ tenants_for_user_get_page_markers(user, marker, limit) else: #Check Admin Token (_token, user) = self.__validate_admin_token(admin_token) # Return all tenants dtenants = api.TENANT.get_page(marker, limit) prev_page, next_page = api.TENANT.get_page_markers(marker, limit) for dtenant in dtenants: ts.append(Tenant(id=dtenant.id, name=dtenant.name, description=dtenant.desc, enabled=dtenant.enabled)) links = [] if prev_page: links.append(atom.Link('prev', "%s?'marker=%s&limit=%s'" % (url, prev_page, limit))) if next_page: links.append(atom.Link('next', "%s?'marker=%s&limit=%s'" % (url, next_page, limit))) return Tenants(ts, links)
def get_roles(self, admin_token, marker, limit, url): self.__validate_service_or_keystone_admin_token(admin_token) ts = [] droles = api.ROLE.get_page(marker, limit) for drole in droles: ts.append(Role(drole.id, drole.name, drole.desc, drole.service_id)) prev, next = api.ROLE.get_page_markers(marker, limit) links = [] if prev: links.append(atom.Link('prev', "%s?'marker=%s&limit=%s'" \ % (url, prev, limit))) if next: links.append(atom.Link('next', "%s?'marker=%s&limit=%s'" \ % (url, next, limit))) return Roles(ts, links)
def get_users(self, admin_token, marker, limit, url): self.__validate_admin_token(admin_token) ts = [] dusers = api.USER.users_get_page(marker, limit) for duser in dusers: ts.append(User(None, duser.id, duser.name, duser.tenant_id, duser.email, duser.enabled)) links = [] if ts.__len__(): prev, next = api.USER.users_get_page_markers(marker, limit) if prev: links.append(atom.Link('prev', "%s?'marker=%s&limit=%s'" % (url, prev, limit))) if next: links.append(atom.Link('next', "%s?'marker=%s&limit=%s'" % (url, next, limit))) return Users(ts, links)
def get_services(self, admin_token, marker, limit, url): self.__validate_service_or_keystone_admin_token(admin_token) ts = [] dservices = api.SERVICE.get_page(marker, limit) for dservice in dservices: ts.append(Service(dservice.id, dservice.name, dservice.type, dservice.desc)) prev, next = api.SERVICE.get_page_markers(marker, limit) links = [] if prev: links.append(atom.Link('prev', "%s?'marker=%s&limit=%s'" \ % (url, prev, limit))) if next: links.append(atom.Link('next', "%s?'marker=%s&limit=%s'" \ % (url, next, limit))) return Services(ts, links)
def get_user_roles(self, admin_token, marker, limit, url, user_id): self.__validate_service_or_keystone_admin_token(admin_token) duser = api.USER.get(user_id) if not duser: raise fault.ItemNotFoundFault("The user could not be found") ts = [] drole_refs = api.ROLE.ref_get_page(marker, limit, user_id) for drole_ref in drole_refs: ts.append(RoleRef(drole_ref.id, drole_ref.role_id, drole_ref.tenant_id)) prev, next = api.ROLE.ref_get_page_markers(user_id, marker, limit) links = [] if prev: links.append(atom.Link('prev', "%s?'marker=%s&limit=%s'" % (url, prev, limit))) if next: links.append(atom.Link('next', "%s?'marker=%s&limit=%s'" % (url, next, limit))) return RoleRefs(ts, links)
def get_endpoint_templates(self, admin_token, marker, limit, url): self.__validate_service_or_keystone_admin_token(admin_token) ts = [] dendpoint_templates = api.ENDPOINT_TEMPLATE.get_page(marker, limit) for dendpoint_template in dendpoint_templates: ts.append( EndpointTemplate(dendpoint_template.id, dendpoint_template.region, dendpoint_template.service_id, dendpoint_template.public_url, dendpoint_template.admin_url, dendpoint_template.internal_url, dendpoint_template.enabled, dendpoint_template.is_global)) prev, next = api.ENDPOINT_TEMPLATE.get_page_markers(marker, limit) links = [] if prev: links.append(atom.Link('prev', "%s?'marker=%s&limit=%s'" \ % (url, prev, limit))) if next: links.append(atom.Link('next', "%s?'marker=%s&limit=%s'" \ % (url, next, limit))) return EndpointTemplates(ts, links)