Esempio n. 1
0
    def get_tenants(self, admin_token, marker, limit, url):
        self.__validate_token(admin_token)

        ts = []
        dtenants = db_api.tenant_get_page(marker, limit)
        for dtenant in dtenants:
            ts.append(tenants.Tenant(dtenant.id,
                                     dtenant.desc, dtenant.enabled))
        prev, next = db_api.tenant_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 tenants.Tenants(ts, links)
Esempio n. 2
0
 def get_tenants(self, admin_token, marker, limit, url):
     try:
         (token, user) = self.__validate_token(admin_token)
         # If Global admin return all tenants.
         ts = []
         dtenants = db_api.tenant_get_page(marker, limit)
         for dtenant in dtenants:
             ts.append(tenants.Tenant(dtenant.id,
                                      dtenant.desc, dtenant.enabled))
         prev, next = db_api.tenant_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 tenants.Tenants(ts, links)
     except fault.UnauthorizedFault:
         #If not global admin ,return tenants specific to user.
         (token, user) = self.__validate_token(admin_token, False)
         ts = []
         dtenants = db_api.tenants_for_user_get_page(user, marker, limit)
         for dtenant in dtenants:
             ts.append(tenants.Tenant(dtenant.id,
                                      dtenant.desc, dtenant.enabled))
         prev, next = db_api.tenants_for_user_get_page_markers(user, 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 tenants.Tenants(ts, links)