Workaround the nfdeployment desc input param issue
[pti/o2.git] / o2dms / domain / dms.py
1 # Copyright (C) 2021 Wind River Systems, Inc.\r
2 #\r
3 #  Licensed under the Apache License, Version 2.0 (the "License");\r
4 #  you may not use this file except in compliance with the License.\r
5 #  You may obtain a copy of the License at\r
6 #\r
7 #      http://www.apache.org/licenses/LICENSE-2.0\r
8 #\r
9 #  Unless required by applicable law or agreed to in writing, software\r
10 #  distributed under the License is distributed on an "AS IS" BASIS,\r
11 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12 #  See the License for the specific language governing permissions and\r
13 #  limitations under the License.\r
14 \r
15 from __future__ import annotations\r
16 # from os import stat\r
17 import json\r
18 from o2dms.domain import events\r
19 from o2dms.domain.states import NfDeploymentState\r
20 \r
21 from o2common.domain.base import AgRoot, Serializer\r
22 \r
23 \r
24 class NfDeploymentDesc(AgRoot, Serializer):\r
25     def __init__(self, id: str, name: str, dmsId: str, description: str = '',\r
26                  inputParams: str = '', outputParams: str = '',\r
27                  artifactRepoUrl: str = '', artifactName: str = '') -> None:\r
28         super().__init__()\r
29         self.id = id\r
30         self.version_number = 0\r
31         self.deploymentManagerId = dmsId\r
32         self.name = name\r
33         self.description = description\r
34         self.artifactRepoUrl = artifactRepoUrl\r
35         self.artifactName = artifactName\r
36         self.status = 0\r
37 \r
38         if type(inputParams) is str:\r
39             inputParams = json.loads(inputParams)\r
40         self.inputParams = json.dumps(inputParams)\r
41 \r
42         if type(outputParams) is str:\r
43             outputParams = json.loads(outputParams)\r
44         self.outputParams = json.dumps(outputParams)\r
45 \r
46         # self.extensions = []\r
47 \r
48 \r
49 class NfDeployment(AgRoot, Serializer):\r
50     def __init__(self, id: str, name: str, dmsId: str, description: str = '',\r
51                  descriptorId: str = '', parentId: str = '',) -> None:\r
52         super().__init__()\r
53         self.id = id\r
54         self.version_number = 0\r
55         self.deploymentManagerId = dmsId\r
56         self.name = name\r
57         self.description = description\r
58         self.descriptorId = descriptorId\r
59         self.parentDeploymentId = parentId\r
60         self.status = NfDeploymentState.Initial\r
61 \r
62     def transit_state(self, state: NfDeploymentState):\r
63         if (self.status != state):\r
64             self._append_event(self.status, state)\r
65             # self.status = state\r
66 \r
67     def set_state(self, state: NfDeploymentState):\r
68         if (self.status != state):\r
69             self.status = state\r
70 \r
71     def _append_event(self, fromState, toState):\r
72         if not hasattr(self, "events"):\r
73             self.events = []\r
74         self.events.append(\r
75             events.NfDeploymentStateChanged(\r
76                 NfDeploymentId=self.id, FromState=fromState, ToState=toState))\r
77 \r
78 \r
79 class NfOCloudVResource(AgRoot, Serializer):\r
80     def __init__(self, id: str, name: str, dmsId: str, description: str = '',\r
81                  descriptorId: str = '', nfDeploymentId: str = '',\r
82                  vresourceType: int = 0,) -> None:\r
83         super().__init__()\r
84         self.id = id\r
85         self.version_number = 0\r
86         self.deploymentManagerId = dmsId\r
87         self.name = name\r
88         self.description = description\r
89         self.descriptorId = descriptorId\r
90         self.nfDeploymentId = nfDeploymentId\r
91         self.vresourceType = vresourceType\r
92         self.status = 0\r
93         self.metadata = []\r