예제 #1
0
    def search(self, resource_type="generic", query=None, details=False,
               history=False, limit=None, marker=None, sorts=None):
        """List resources

        :param resource_type: Type of the resource
        :type resource_type: str
        :param query: The query dictionary
        :type query: dict
        :param details: Show all attributes of resources
        :type details: bool
        :param history: Show the history of resources
        :type history: bool
        :param limit: maximum number of resources to return
        :type limit: int
        :param marker: the last item of the previous page; we returns the next
                       results after this value.
        :type marker: str
        :param sorts: list of resource attributes to order by. (example
                      ["user_id:desc-nullslast", "project_id:asc"]
        :type sorts: list of str

        See Gnocchi REST API documentation for the format
        of *query dictionary*
        http://docs.openstack.org/developer/gnocchi/rest.html#searching-for-resources
        """

        query = query or {}
        qs = utils.build_pagination_options(details, history, limit, marker,
                                            sorts)
        url = "v1/search/resource/%s?%s" % (resource_type, qs)
        return self._post(
            url, headers={'Content-Type': "application/json"},
            data=ujson.dumps(query)).json()
예제 #2
0
    def list(self, limit=None, marker=None, sorts=None):
        """List metrics

        :param limit: maximum number of resources to return
        :type limit: int
        :param marker: the last item of the previous page; we return the next
                       results after this value.
        :type marker: str
        :param sorts: list of resource attributes to order by. (example
                      ["user_id:desc-nullslast", "project_id:asc"]
        :type sorts: list of str
        """
        params = utils.build_pagination_options(False, False, limit, marker,
                                                sorts)
        metrics = []
        page_url = "%s?%s" % (self.metric_url[:-1],
                              utils.dict_to_querystring(params))
        while page_url:
            page = self._get(page_url)
            metrics.extend(page.json())
            if limit is None or len(metrics) < limit:
                page_url = page.links.get("next", {'url': None})['url']
            else:
                break
        return metrics
예제 #3
0
    def history(self,
                resource_type,
                resource_id,
                details=False,
                limit=None,
                marker=None,
                sorts=None):
        """Get a resource.

        :param resource_type: Type of the resource
        :type resource_type: str
        :param resource_id: ID of the resource
        :type resource_id: str
        :param details: Show all attributes of resources
        :type details: bool
        :param limit: maximum number of resources to return
        :type limit: int
        :param marker: the last item of the previous page; we returns the next
                       results after this value.
        :type marker: str
        :param sorts: list of resource attributes to order by. (example
                      ["user_id:desc-nullslast", "project_id:asc"]
        :type sorts: list of str
        """
        params = utils.build_pagination_options(details, False, limit, marker,
                                                sorts)
        url = "%s%s/%s/history?%s" % (self.url, resource_type, resource_id,
                                      utils.dict_to_querystring(params))
        return self._get(url).json()
예제 #4
0
    def search(self, resource_type="generic", query=None, details=False,
               history=False, limit=None, marker=None, sorts=None):
        """List resources

        :param resource_type: Type of the resource
        :type resource_type: str
        :param query: The query dictionary
        :type query: dict
        :param details: Show all attributes of resources
        :type details: bool
        :param history: Show the history of resources
        :type history: bool
        :param limit: maximum number of resources to return
        :type limit: int
        :param marker: the last item of the previous page; we returns the next
                       results after this value.
        :type marker: str
        :param sorts: list of resource attributes to order by. (example
                      ["user_id:desc-nullslast", "project_id:asc"]
        :type sorts: list of str

        See Gnocchi REST API documentation for the format
        of *query dictionary*
        http://docs.openstack.org/developer/gnocchi/rest.html#searching-for-resources
        """

        query = query or {}
        qs = utils.build_pagination_options(details, history, limit, marker,
                                            sorts)
        url = "v1/search/resource/%s?%s" % (resource_type, qs)
        return self._post(
            url, headers={'Content-Type': "application/json"},
            data=jsonutils.dumps(query)).json()
예제 #5
0
    def list(self, limit=None, marker=None, sorts=None):
        """List metrics

        :param limit: maximum number of resources to return
        :type limit: int
        :param marker: the last item of the previous page; we return the next
                       results after this value.
        :type marker: str
        :param sorts: list of resource attributes to order by. (example
                      ["user_id:desc-nullslast", "project_id:asc"]
        :type sorts: list of str

        """
        qs = utils.build_pagination_options(False, False, limit, marker, sorts)
        return self._get("%s?%s" % (self.metric_url[:-1], qs)).json()
예제 #6
0
    def list(self, limit=None, marker=None, sorts=None):
        """List metrics

        :param limit: maximum number of resources to return
        :type limit: int
        :param marker: the last item of the previous page; we return the next
                       results after this value.
        :type marker: str
        :param sorts: list of resource attributes to order by. (example
                      ["user_id:desc-nullslast", "project_id:asc"]
        :type sorts: list of str

        """
        qs = utils.build_pagination_options(False, False, limit, marker, sorts)
        return self._get("%s?%s" % (self.metric_url[:-1], qs)).json()
예제 #7
0
    def history(self, resource_type, resource_id, details=False,
                limit=None, marker=None, sorts=None):
        """Get a resource

        :param resource_type: Type of the resource
        :type resource_type: str
        :param resource_id: ID of the resource
        :type resource_id: str
        :param details: Show all attributes of resources
        :type details: bool
        :param limit: maximum number of resources to return
        :type limit: int
        :param marker: the last item of the previous page; we returns the next
                       results after this value.
        :type marker: str
        :param sorts: list of resource attributes to order by. (example
                      ["user_id:desc-nullslast", "project_id:asc"]
        :type sorts: list of str
        """
        qs = utils.build_pagination_options(details, False, limit, marker,
                                            sorts)
        url = "%s%s/%s/history?%s" % (self.url, resource_type, resource_id, qs)
        return self._get(url).json()
예제 #8
0
    def list(self, resource_type="generic", details=False, history=False,
             limit=None, marker=None, sorts=None):
        """List resources

        :param resource_type: Type of the resource
        :type resource_type: str
        :param details: Show all attributes of resources
        :type details: bool
        :param history: Show the history of resources
        :type history: bool
        :param limit: maximum number of resources to return
        :type limit: int
        :param marker: the last item of the previous page; we return the next
                       results after this value.
        :type marker: str
        :param sorts: list of resource attributes to order by. (example
                      ["user_id:desc-nullslast", "project_id:asc"]
        :type sorts: list of str
        """
        qs = utils.build_pagination_options(details, history, limit, marker,
                                            sorts)
        url = "%s%s?%s" % (self.url, resource_type, qs)
        return self._get(url).json()