Pagination in request and response; Fix alarm client issue
[pti/o2.git] / o2ims / views / ocloud_dto.py
index 651de97..c8e5202 100644 (file)
@@ -62,7 +62,6 @@ class ResourcePoolDTO:
 
 
 class ResourceDTO:
-
     resource_list = api_ims_inventory_v1.model(
         "ResourceListDto",
         {
@@ -76,6 +75,46 @@ class ResourceDTO:
         }
     )
 
+    list_result = api_ims_inventory_v1.model(
+        "ResourceListPagenationDto",
+        {
+            'count': fields.Integer(),
+            'page_num': fields.Integer(),
+            'results': fields.List(fields.Nested(resource_list))
+        }
+    )
+
+    # def get_paginated_list(results, url, start, limit):
+    #     start = int(start)
+    #     limit = int(limit)
+    #     count = len(results)
+    #     if count < start or limit < 0:
+    #         api_ims_inventory_v1.abort(404)
+    #     # make response
+    #     obj = {}
+    #     obj['start'] = start
+    #     obj['limit'] = limit
+    #     obj['count'] = count
+    #     # make URLs
+    #     # make previous url
+    #     if start == 1:
+    #         obj['previous'] = ''
+    #     else:
+    #         start_copy = max(1, start - limit)
+    #         limit_copy = start - 1
+    #         obj['previous'] = url + \
+    #             '?start=%d&limit=%d' % (start_copy, limit_copy)
+    #     # make next url
+    #     if start + limit > count:
+    #         obj['next'] = ''
+    #     else:
+    #         start_copy = start + limit
+    #         obj['next'] = url + '?start=%d&limit=%d' % (start_copy, limit)
+    #     # finally extract result according to bounds
+    #     # obj['results'] = results[(start - 1):(start - 1 + limit)]
+    #     obj['result'] = fields.List(fields.Nested(ResourceDTO.resource_list))
+    #     return obj
+
     def recursive_resource_mapping(iteration_number=2):
         resource_json_mapping = {
             'resourceId': fields.String(required=True,