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 o2common.domain.base import AgRoot, Serializer
19 # from dataclasses import dataclass
20 # from datetime import date
21 # from typing import Optional, List, Set
22 from .resource_type import ResourceTypeEnum
23 # from uuid import UUID
26 DeploymentManagerProfileDefault = 'default'
27 DeploymentManagerProfileSOL018 = 'sol018'
28 DeploymentManagerProfileSOL018HelmCLI = 'sol018_helmcli'
31 class DeploymentManager(AgRoot, Serializer):
32 def __init__(self, id: str, name: str, ocloudid: str,
33 dmsendpoint: str, description: str = '',
34 supportedLocations: str = '', capabilities: str = '',
35 capacity: str = '', profile: str = '') -> None:
37 self.deploymentManagerId = id
38 self.version_number = 0
39 self.oCloudId = ocloudid
41 self.description = description
42 self.deploymentManagementServiceEndpoint = dmsendpoint
43 self.supportedLocations = supportedLocations
44 self.capabilities = capabilities
45 self.capacity = capacity
46 self.profile = profile
51 d = Serializer.serialize(self)
53 if 'profile' in d and d['profile'] != '':
54 d['profile'] = json.loads(d['profile'])
55 d['profileSupportList'] = [
56 DeploymentManagerProfileDefault,
57 DeploymentManagerProfileSOL018,
58 DeploymentManagerProfileSOL018HelmCLI,
64 class ResourcePool(AgRoot, Serializer):
65 def __init__(self, id: str, name: str, location: str,
66 ocloudid: str, gLocationId: str = '',
67 description: str = '') -> None:
69 self.resourcePoolId = id
70 self.version_number = 0
71 self.oCloudId = ocloudid
72 self.globalLocationId = gLocationId
74 self.location = location
75 self.description = description
79 class ResourceType(AgRoot, Serializer):
80 def __init__(self, typeid: str, name: str, typeEnum: ResourceTypeEnum,
81 ocloudid: str, vender: str = '', model: str = '',
83 description: str = '') -> None:
85 self.resourceTypeId = typeid
86 self.version_number = 0
87 self.oCloudId = ocloudid
88 self.resourceTypeEnum = typeEnum
92 self.version = version
93 self.description = description
97 class Resource(AgRoot, Serializer):
98 def __init__(self, resourceId: str, resourceTypeId: str,
99 resourcePoolId: str, name: str, parentId: str = '',
100 gAssetId: str = '', elements: str = '',
101 description: str = '') -> None:
103 self.resourceId = resourceId
104 self.version_number = 0
105 self.resourceTypeId = resourceTypeId
106 self.resourcePoolId = resourcePoolId
108 self.globalAssetId = gAssetId
109 self.parentId = parentId
110 self.elements = elements
111 self.description = description
115 def set_children(self, children: list):
116 self.children = children
118 def set_resource_type_name(self, resource_type_name: str):
119 self.resourceTypeName = resource_type_name
122 d = Serializer.serialize(self)
124 if 'elements' in d and d['elements'] != '':
125 d['elements'] = json.loads(d['elements'])
127 if not hasattr(self, 'children') or len(self.children) == 0:
132 for child in self.children:
133 d['children'].append(child.serialize())
137 class Ocloud(AgRoot, Serializer):
138 def __init__(self, ocloudid: str, name: str, imsendpoint: str,
139 globalcloudId: str = '',
140 description: str = '', version_number: int = 0) -> None:
142 self.oCloudId = ocloudid
143 self.globalcloudId = globalcloudId
144 self.version_number = version_number
146 self.description = description
147 self.serviceUri = imsendpoint
148 self.resourcePools = []
149 self.deploymentManagers = []
150 self.resourceTypes = []
153 # def addDeploymentManager(self,
154 # deploymentManager: DeploymentManager):
156 # deploymentManager.oCloudId = self.oCloudId
158 # lambda x: x.deploymentManagerId ==
159 # deploymentManager.deploymentManagerId,
160 # self.deploymentManagers)
161 # for o in old or []:
162 # self.deploymentManagers.remove(o)
163 # self.deploymentManagers.append(deploymentManager)