Преглед изворни кода

Show deleted replicas and executions

Gabriel-Adrian Samfira пре 6 година
родитељ
комит
e1f0e6e3e9

+ 2 - 15
coriolis/api/v1/migrations.py

@@ -31,21 +31,8 @@ class MigrationController(api_wsgi.Controller):
 
         return migration_view.single(req, migration)
 
-    def _get_show_deleted(self, val):
-        if val is None:
-            return val
-        try:
-            show_deleted = json.loads(val)
-            if type(show_deleted) is bool:
-                return show_deleted
-        except Exception as err:
-            LOG.warn(
-                "failed to parse show_deleted: %s" % err)
-            pass
-        return None
-
     def index(self, req):
-        show_deleted = self._get_show_deleted(
+        show_deleted = api_utils._get_show_deleted(
             req.GET.get("show_deleted", None))
         context = req.environ["coriolis.context"]
         context.show_deleted = show_deleted
@@ -55,7 +42,7 @@ class MigrationController(api_wsgi.Controller):
                 context, include_tasks=False))
 
     def detail(self, req):
-        show_deleted = self._get_show_deleted(
+        show_deleted = api_utils._get_show_deleted(
             req.GET.get("show_deleted", None))
         context = req.environ["coriolis.context"]
         context.show_deleted = show_deleted

+ 8 - 4
coriolis/api/v1/replicas.py

@@ -31,17 +31,21 @@ class ReplicaController(api_wsgi.Controller):
 
         return replica_view.single(req, replica)
 
-    def index(self, req, show_deleted=False):
+    def index(self, req):
+        show_deleted = api_utils._get_show_deleted(
+            req.GET.get("show_deleted", None))
         context = req.environ["coriolis.context"]
-        context["show_deleted"] = show_deleted
+        context.show_deleted = show_deleted
         context.can(replica_policies.get_replicas_policy_label("list"))
         return replica_view.collection(
             req, self._replica_api.get_replicas(
                 context, include_tasks_executions=False))
 
-    def detail(self, req, show_deleted=False):
+    def detail(self, req):
+        show_deleted = api_utils._get_show_deleted(
+            req.GET.get("show_deleted", None))
         context = req.environ["coriolis.context"]
-        context["show_deleted"] = show_deleted
+        context.show_deleted = show_deleted
         context.can(
             replica_policies.get_replicas_policy_label("show_executions"))
         return replica_view.collection(

+ 15 - 0
coriolis/api/v1/utils.py

@@ -1,6 +1,7 @@
 # Copyright 2018 Cloudbase Solutions Srl
 # All Rights Reserved.
 
+import json
 
 from oslo_log import log as logging
 from webob import exc
@@ -12,6 +13,20 @@ from coriolis import schemas
 LOG = logging.getLogger(__name__)
 
 
+def _get_show_deleted(val):
+    if val is None:
+        return val
+    try:
+        show_deleted = json.loads(val)
+        if type(show_deleted) is bool:
+            return show_deleted
+    except Exception as err:
+        LOG.warn(
+            "failed to parse show_deleted: %s" % err)
+        pass
+    return None
+
+
 def validate_network_map(network_map):
     """ Validates the JSON schema for the network_map. """
     try:

+ 2 - 4
coriolis/api/v1/views/migration_view.py

@@ -27,10 +27,10 @@ def _format_migration(req, migration, keys=None):
     migration_dict = dict(itertools.chain.from_iterable(
         transform(k, v) for k, v in migration.items()))
 
-    if len(migration_dict["executions"]):
-
+    if len(migration_dict.get("executions", [])):
         execution = view.format_replica_tasks_execution(
             req, migration_dict["executions"][0])
+        del migration_dict["executions"]
     else:
         execution = {}
 
@@ -42,8 +42,6 @@ def _format_migration(req, migration, keys=None):
     if not CONF.include_task_info_in_migrations_api and (
             "info" in migration_dict):
         migration_dict.pop("info")
-
-    del migration_dict["executions"]
     return migration_dict
 
 

+ 7 - 2
coriolis/db/api.py

@@ -276,15 +276,20 @@ def _get_replica_with_tasks_executions_options(q):
 
 
 @enginefacade.reader
-def get_replicas(context, include_tasks_executions=False):
+def get_replicas(context,
+                 include_tasks_executions=False,
+                 include_info=False):
     q = _soft_delete_aware_query(context, models.Replica)
     if include_tasks_executions:
         q = _get_replica_with_tasks_executions_options(q)
+    if include_info is False:
+        q = q.options(orm.defer('info'))
     q = q.filter()
     if is_user_context(context):
         q = q.filter(
             models.Replica.project_id == context.tenant)
-    return q.all()
+    db_result = q.all()
+    return [i.to_dict(include_info=include_info) for i in db_result]
 
 
 @enginefacade.reader