Example #1
0
    def getViews(self, namespace_id, skip=0, count=100):
        """Retrieves a list of views associated with the specified 'namespace_id' under the current tenant"""
        if namespace_id is None:
            raise TypeError

        response = requests.get(
            self.__url + self.__viewsPath.format(tenant_id=self.__tenant, namespace_id=namespace_id, skip=skip, count=count),
            headers=self.__sdsHeaders())
        if response.status_code < 200 or response.status_code >= 300:
            response.close()
            raise SdsError("Failed to get all SdsViews. {status}:{reason}".
                          format(status=response.status_code, reason=response.text))

        content = json.loads(response.content)
        results = []
        for item in content:
            results.append(SdsView.fromJson(item))
        response.close()
        return results
Example #2
0
    def getOrCreateView(self, namespace_id, view):
        """Tells Sds Service to create a view based on a local SdsView object"""
        if namespace_id is None:
            raise TypeError
        if view is None or not isinstance(view, SdsView):
            raise TypeError

        response = requests.post(
            self.__url + self.__viewsPath.format(tenant_id=self.__tenant, namespace_id=namespace_id, view_id=view.Id),
            data=view.toJson(), 
            headers=self.__sdsHeaders())
        if response.status_code < 200 or response.status_code >= 300:
            response.close()
            raise SdsError("Failed to create SdsView, {view_id}. {status}:{reason}".
                          format(view_id=view.Id, status=response.status_code, reason=response.text))

        view = SdsView.fromJson(json.loads(response.content))
        response.close()
        return view
Example #3
0
    def getView(self, namespace_id, view_id):
        """Retrieves the view specified by 'view_id' from Sds Service"""
        if namespace_id is None:
            raise TypeError
        if view_id is None:
            raise TypeError

        response = requests.get(
            self.__url + self.__viewsPath.format(tenant_id=self.__tenant, namespace_id=namespace_id,
            view_id=view_id), 
            headers=self.__sdsHeaders())
        if response.status_code < 200 or response.status_code >= 300:
            response.close()
            raise SdsError("Failed to get SdsView, {view_id}. {status}:{reason}".
                          format(view_id=view_id, status=response.status_code, reason=response.text))

        view = SdsView.fromJson(json.loads(response.content))
        response.close()
        return view