1 # Copyright (C) 2021 Wind River Systems, Inc.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 from __future__ import annotations
18 from o2dms.domain import events
19 from o2dms.domain.states import NfDeploymentState
21 from o2common.domain.base import AgRoot, Serializer
24 class NfDeploymentDesc(AgRoot, Serializer):
25 def __init__(self, id: str, name: str, dmsId: str, description: str = '',
26 inputParams: str = '', outputParams: str = '',
27 artifactRepoUrl: str = '', artifactName: str = '') -> None:
30 self.version_number = 0
31 self.deploymentManagerId = dmsId
33 self.description = description
34 self.artifactRepoUrl = artifactRepoUrl
35 self.artifactName = artifactName
38 if type(inputParams) is str:
39 inputParams = json.loads(inputParams)
40 self.inputParams = json.dumps(inputParams)
42 if type(outputParams) is str:
43 outputParams = json.loads(outputParams)
44 self.outputParams = json.dumps(outputParams)
46 # self.extensions = []
49 class NfDeployment(AgRoot, Serializer):
50 def __init__(self, id: str, name: str, dmsId: str, description: str = '',
51 descriptorId: str = '', parentId: str = '',) -> None:
54 self.version_number = 0
55 self.deploymentManagerId = dmsId
57 self.description = description
58 self.descriptorId = descriptorId
59 self.parentDeploymentId = parentId
60 self.status = NfDeploymentState.Initial
62 def transit_state(self, state: NfDeploymentState):
63 if (self.status != state):
64 self._append_event(self.status, state)
67 def set_state(self, state: NfDeploymentState):
68 if (self.status != state):
71 def _append_event(self, fromState, toState):
72 if not hasattr(self, "events"):
75 events.NfDeploymentStateChanged(
76 NfDeploymentId=self.id, FromState=fromState, ToState=toState))
79 class NfOCloudVResource(AgRoot, Serializer):
80 def __init__(self, id: str, name: str, dmsId: str, description: str = '',
81 descriptorId: str = '', nfDeploymentId: str = '',
82 vresourceType: int = 0,) -> None:
85 self.version_number = 0
86 self.deploymentManagerId = dmsId
88 self.description = description
89 self.descriptorId = descriptorId
90 self.nfDeploymentId = nfDeploymentId
91 self.vresourceType = vresourceType