Convert file endlines to Unix (LF)
[pti/o2.git] / o2ims / views / ocloud_view.py
index 0436f3a..7355f71 100644 (file)
-# Copyright (C) 2021 Wind River Systems, Inc.\r
-#\r
-#  Licensed under the Apache License, Version 2.0 (the "License");\r
-#  you may not use this file except in compliance with the License.\r
-#  You may obtain a copy of the License at\r
-#\r
-#      http://www.apache.org/licenses/LICENSE-2.0\r
-#\r
-#  Unless required by applicable law or agreed to in writing, software\r
-#  distributed under the License is distributed on an "AS IS" BASIS,\r
-#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
-#  See the License for the specific language governing permissions and\r
-#  limitations under the License.\r
-\r
-import uuid\r
-\r
-from o2common.service import unit_of_work\r
-from o2ims.views.ocloud_dto import SubscriptionDTO\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
-    with uow:\r
-        li = uow.oclouds.list()\r
-    return [r.serialize() for r in li]\r
-\r
-\r
-def ocloud_one(ocloudid: str, uow: unit_of_work.AbstractUnitOfWork):\r
-    with uow:\r
-        first = uow.oclouds.get(ocloudid)\r
-        return first.serialize() if first is not None else None\r
-\r
-\r
-def resource_types(uow: unit_of_work.AbstractUnitOfWork):\r
-    with uow:\r
-        li = uow.resource_types.list()\r
-    return [r.serialize() for r in li]\r
-\r
-\r
-def resource_type_one(resourceTypeId: str,\r
-                      uow: unit_of_work.AbstractUnitOfWork):\r
-    with uow:\r
-        first = uow.resource_types.get(resourceTypeId)\r
-        return first.serialize() if first is not None else None\r
-\r
-\r
-def resource_pools(uow: unit_of_work.AbstractUnitOfWork):\r
-    with uow:\r
-        li = uow.resource_pools.list()\r
-    return [r.serialize() for r in li]\r
-\r
-\r
-def resource_pool_one(resourcePoolId: str,\r
-                      uow: unit_of_work.AbstractUnitOfWork):\r
-    with uow:\r
-        first = uow.resource_pools.get(resourcePoolId)\r
-        return first.serialize() if first is not None else None\r
-\r
-\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, **filter_kwargs)\r
-    return [r.serialize() for r in li]\r
-\r
-\r
-def resource_one(resourceId: str, uow: unit_of_work.AbstractUnitOfWork):\r
-    with uow:\r
-        first = uow.resources.get(resourceId)\r
-        return first.serialize() if first is not None else None\r
-\r
-\r
-def deployment_managers(uow: unit_of_work.AbstractUnitOfWork):\r
-    with uow:\r
-        li = uow.deployment_managers.list()\r
-    return [r.serialize() for r in li]\r
-\r
-\r
-def deployment_manager_one(deploymentManagerId: str,\r
-                           uow: unit_of_work.AbstractUnitOfWork):\r
-    with uow:\r
-        first = uow.deployment_managers.get(deploymentManagerId)\r
-        return first.serialize() if first is not None else None\r
-\r
-\r
-def subscriptions(uow: unit_of_work.AbstractUnitOfWork):\r
-    with uow:\r
-        li = uow.subscriptions.list()\r
-    return [r.serialize() for r in li]\r
-\r
-\r
-def subscription_one(subscriptionId: str,\r
-                     uow: unit_of_work.AbstractUnitOfWork):\r
-    with uow:\r
-        first = uow.subscriptions.get(subscriptionId)\r
-        return first.serialize() if first is not None else None\r
-\r
-\r
-def subscription_create(subscriptionDto: SubscriptionDTO.subscription,\r
-                        uow: unit_of_work.AbstractUnitOfWork):\r
-\r
-    sub_uuid = str(uuid.uuid4())\r
-    subscription = Subscription(\r
-        sub_uuid, subscriptionDto['callback'],\r
-        subscriptionDto['consumerSubscriptionId'],\r
-        subscriptionDto['filter'])\r
-    with uow:\r
-        uow.subscriptions.add(subscription)\r
-        uow.commit()\r
-    return {"subscriptionId": sub_uuid}\r
-\r
-\r
-def subscription_delete(subscriptionId: str,\r
-                        uow: unit_of_work.AbstractUnitOfWork):\r
-    with uow:\r
-        uow.subscriptions.delete(subscriptionId)\r
-        uow.commit()\r
-    return True\r
+# Copyright (C) 2021 Wind River Systems, Inc.
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+
+import uuid
+
+from o2common.service import unit_of_work
+from o2ims.views.ocloud_dto import SubscriptionDTO
+from o2ims.domain.subscription_obj import Subscription
+
+from o2common.helper import o2logging
+logger = o2logging.get_logger(__name__)
+
+
+def oclouds(uow: unit_of_work.AbstractUnitOfWork):
+    with uow:
+        li = uow.oclouds.list()
+    return [r.serialize() for r in li]
+
+
+def ocloud_one(ocloudid: str, uow: unit_of_work.AbstractUnitOfWork):
+    with uow:
+        first = uow.oclouds.get(ocloudid)
+        return first.serialize() if first is not None else None
+
+
+def resource_types(uow: unit_of_work.AbstractUnitOfWork):
+    with uow:
+        li = uow.resource_types.list()
+    return [r.serialize() for r in li]
+
+
+def resource_type_one(resourceTypeId: str,
+                      uow: unit_of_work.AbstractUnitOfWork):
+    with uow:
+        first = uow.resource_types.get(resourceTypeId)
+        return first.serialize() if first is not None else None
+
+
+def resource_pools(uow: unit_of_work.AbstractUnitOfWork):
+    with uow:
+        li = uow.resource_pools.list()
+    return [r.serialize() for r in li]
+
+
+def resource_pool_one(resourcePoolId: str,
+                      uow: unit_of_work.AbstractUnitOfWork):
+    with uow:
+        first = uow.resource_pools.get(resourcePoolId)
+        return first.serialize() if first is not None else None
+
+
+def resources(resourcePoolId: str, uow: unit_of_work.AbstractUnitOfWork,
+              **kwargs):
+
+    filter_kwargs = {}  # filter key should be the same with database name
+    if 'resourceTypeName' in kwargs:
+        resource_type_name = kwargs['resourceTypeName']
+        with uow:
+            # res_types = uow.resource_types.list()
+            # restype_ids = [
+            #     restype.resourceTypeId for restype in res_types
+            #     if resourceTypeName == restype.name]
+            # restype_id = '' if len(restype_ids) == 0 else restype_ids[0]
+            res_type = uow.resource_types.get_by_name(resource_type_name)
+            restype_id = '' if res_type is None else res_type.resourceTypeId
+        filter_kwargs['resourceTypeId'] = restype_id
+
+        #     li = uow.resources.list(resourcePoolId)
+        # return [r.serialize() for r in li if r.resourceTypeId == restype_id]
+    if 'parentId' in kwargs:
+        filter_kwargs['parentId'] = kwargs['parentId']
+
+    with uow:
+        li = uow.resources.list(resourcePoolId, **filter_kwargs)
+    return [r.serialize() for r in li]
+
+
+def resource_one(resourceId: str, uow: unit_of_work.AbstractUnitOfWork):
+    with uow:
+        first = uow.resources.get(resourceId)
+        return first.serialize() if first is not None else None
+
+
+def deployment_managers(uow: unit_of_work.AbstractUnitOfWork):
+    with uow:
+        li = uow.deployment_managers.list()
+    return [r.serialize() for r in li]
+
+
+def deployment_manager_one(deploymentManagerId: str,
+                           uow: unit_of_work.AbstractUnitOfWork):
+    with uow:
+        first = uow.deployment_managers.get(deploymentManagerId)
+        return first.serialize() if first is not None else None
+
+
+def subscriptions(uow: unit_of_work.AbstractUnitOfWork):
+    with uow:
+        li = uow.subscriptions.list()
+    return [r.serialize() for r in li]
+
+
+def subscription_one(subscriptionId: str,
+                     uow: unit_of_work.AbstractUnitOfWork):
+    with uow:
+        first = uow.subscriptions.get(subscriptionId)
+        return first.serialize() if first is not None else None
+
+
+def subscription_create(subscriptionDto: SubscriptionDTO.subscription,
+                        uow: unit_of_work.AbstractUnitOfWork):
+
+    sub_uuid = str(uuid.uuid4())
+    subscription = Subscription(
+        sub_uuid, subscriptionDto['callback'],
+        subscriptionDto['consumerSubscriptionId'],
+        subscriptionDto['filter'])
+    with uow:
+        uow.subscriptions.add(subscription)
+        uow.commit()
+    return {"subscriptionId": sub_uuid}
+
+
+def subscription_delete(subscriptionId: str,
+                        uow: unit_of_work.AbstractUnitOfWork):
+    with uow:
+        uow.subscriptions.delete(subscriptionId)
+        uow.commit()
+    return True