Fix nfdeployment uninstall issue
[pti/o2.git] / o2ims / views / ocloud_view.py
index f970517..0436f3a 100644 (file)
@@ -16,7 +16,10 @@ import uuid
 \r
 from o2common.service import unit_of_work\r
 from o2ims.views.ocloud_dto import SubscriptionDTO\r
-from o2ims.domain.ocloud import Subscription\r
+from o2ims.domain.subscription_obj import Subscription\r
+\r
+from o2common.helper import o2logging\r
+logger = o2logging.get_logger(__name__)\r
 \r
 \r
 def oclouds(uow: unit_of_work.AbstractUnitOfWork):\r
@@ -41,7 +44,6 @@ def resource_type_one(resourceTypeId: str,
                       uow: unit_of_work.AbstractUnitOfWork):\r
     with uow:\r
         first = uow.resource_types.get(resourceTypeId)\r
-        print(first)\r
         return first.serialize() if first is not None else None\r
 \r
 \r
@@ -58,9 +60,29 @@ def resource_pool_one(resourcePoolId: str,
         return first.serialize() if first is not None else None\r
 \r
 \r
-def resources(resourcePoolId: str, uow: unit_of_work.AbstractUnitOfWork):\r
+def resources(resourcePoolId: str, uow: unit_of_work.AbstractUnitOfWork,\r
+              **kwargs):\r
+\r
+    filter_kwargs = {}  # filter key should be the same with database name\r
+    if 'resourceTypeName' in kwargs:\r
+        resource_type_name = kwargs['resourceTypeName']\r
+        with uow:\r
+            # res_types = uow.resource_types.list()\r
+            # restype_ids = [\r
+            #     restype.resourceTypeId for restype in res_types\r
+            #     if resourceTypeName == restype.name]\r
+            # restype_id = '' if len(restype_ids) == 0 else restype_ids[0]\r
+            res_type = uow.resource_types.get_by_name(resource_type_name)\r
+            restype_id = '' if res_type is None else res_type.resourceTypeId\r
+        filter_kwargs['resourceTypeId'] = restype_id\r
+\r
+        #     li = uow.resources.list(resourcePoolId)\r
+        # return [r.serialize() for r in li if r.resourceTypeId == restype_id]\r
+    if 'parentId' in kwargs:\r
+        filter_kwargs['parentId'] = kwargs['parentId']\r
+\r
     with uow:\r
-        li = uow.resources.list(resourcePoolId)\r
+        li = uow.resources.list(resourcePoolId, **filter_kwargs)\r
     return [r.serialize() for r in li]\r
 \r
 \r