示例#1
0
    def get(self):
        parser = reqparse.RequestParser()
        parser.add_argument("start", type=int, required=True)
        parser.add_argument("end", type=int, required=True)
        parser.add_argument("distinct", type=bool, default=False)

        args = parser.parse_args()
        common_args = QUERY_PARSER.parse_args()

        if args["distinct"]:
            query = Summary(args["start"], args["end"]).query
        else:
            query = self._query(args["start"], args["end"])

        result = {'total': 0, 'pages': 0, 'items': []}
        try:
            qp = query.paginate(common_args["page"], common_args["count"])
            result['total'] = qp.total
            result['pages'] = qp.pages
            result['page'] = qp.page
            if args["distinct"]:
                result['items'] = [item[0] for item in qp.items]
            else:
                result['items'] = [{'ts': item[0], 'server_id': item[1], 'server': item[2],
                                    'hypervisor': item[3], 'account': str(item[4]),
                                    'tenant': str(item[5]), 'flavor': str(item[6])}
                                    for item in qp.items]
        except NotFound:
            pass
        except Exception as e:
            logger.error("Query of summary failed. Detail: %s" % str(e))

        return result
示例#2
0
 def get(self):
     args = QUERY_PARSER.parse_args()
     if args["filter"]:
         return super(InstanceResource, self).get()
     else:
         return self._latest_state()