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.config import config
19 from o2common.domain.base import AgRoot, Serializer
20 # from dataclasses import dataclass
21 # from datetime import date
22 # from typing import Optional, List, Set
23 from .resource_type import ResourceKindEnum, ResourceTypeEnum
24 from .alarm_obj import AlarmDictionary
27 DeploymentManagerProfileDefault = 'native_k8sapi'
28 DeploymentManagerProfileSOL018 = 'sol018'
29 DeploymentManagerProfileSOL018HelmCLI = 'sol018_helmcli'
32 class DeploymentManager(AgRoot, Serializer):
33 def __init__(self, id: str, name: str, ocloudid: str,
34 dmsendpoint: str, description: str = '',
35 supportedLocations: str = '', capabilities: str = '',
36 capacity: str = '', profile: str = '') -> None:
38 self.deploymentManagerId = id
40 self.description = description
41 self.oCloudId = ocloudid
42 self.serviceUri = dmsendpoint
43 self.supportedLocations = supportedLocations
44 self.capabilities = capabilities
45 self.capacity = capacity
46 self.profile = profile
49 self.version_number = 0
52 d = Serializer.serialize(self)
54 if 'profile' in d and d['profile'] != '':
55 d['profile'] = json.loads(d['profile'])
56 d['profileSupportList'] = [
57 DeploymentManagerProfileDefault,
59 profiles = config.get_dms_support_profiles()
60 for profile in profiles:
61 if profile == DeploymentManagerProfileSOL018:
62 d['profileSupportList'].append(profile)
63 elif profile == DeploymentManagerProfileSOL018HelmCLI:
64 d['profileSupportList'].append(profile)
69 class ResourcePool(AgRoot, Serializer):
70 def __init__(self, id: str, name: str, location: str,
71 ocloudid: str, gLocationId: str = '',
72 description: str = '') -> None:
74 self.resourcePoolId = id
75 self.globalLocationId = gLocationId
77 self.description = description
78 self.oCloudId = ocloudid
79 self.location = location
83 self.version_number = 0
86 class ResourceType(AgRoot, Serializer):
87 def __init__(self, typeid: str, name: str, typeEnum: ResourceTypeEnum,
88 vendor: str = '', model: str = '',
90 description: str = '') -> None:
92 self.resourceTypeId = typeid
93 self.resourceTypeEnum = typeEnum
95 self.description = description
98 self.version = version
99 self.alarmDictionary = None
100 self.resourceKind = ResourceKindEnum.UNDEFINED
101 self.resourceClass = ResourceTypeEnum.UNDEFINED
104 self.version_number = 0
107 d = Serializer.serialize(self)
108 if 'alarmDictionary' in d and \
109 type(d['alarmDictionary']) is AlarmDictionary:
110 d['alarmDictionary'] = d['alarmDictionary'].serialize()
114 class Resource(AgRoot, Serializer):
115 def __init__(self, resourceId: str, resourceTypeId: str,
116 resourcePoolId: str, name: str, parentId: str = '',
117 gAssetId: str = '', elements: str = '',
118 description: str = '', extensions: str = '') -> None:
120 self.resourceId = resourceId
121 self.description = description
122 self.resourceTypeId = resourceTypeId
123 self.globalAssetId = gAssetId
124 self.resourcePoolId = resourcePoolId
125 self.elements = elements
126 self.extensions = extensions
129 self.parentId = parentId
132 self.version_number = 0
134 def set_children(self, children: list):
135 self.children = children
137 def set_resource_type_name(self, resource_type_name: str):
138 self.resourceTypeName = resource_type_name
141 d = Serializer.serialize(self)
143 if 'elements' in d and d['elements'] != '':
144 d['elements'] = json.loads(d['elements'])
146 if not hasattr(self, 'children') or len(self.children) == 0:
151 for child in self.children:
152 d['children'].append(child.serialize())
156 class Ocloud(AgRoot, Serializer):
157 def __init__(self, ocloudid: str, name: str, imsendpoint: str,
158 globalcloudId: str = '',
159 description: str = '', version_number: int = 0) -> None:
161 self.oCloudId = ocloudid
162 self.globalCloudId = globalcloudId
164 self.description = description
165 self.serviceUri = imsendpoint
166 self.resourceTypes = []
167 self.resourcePools = []
168 self.deploymentManagers = []
169 self.smoRegistrationService = ''
172 self.version_number = version_number
174 # def addDeploymentManager(self,
175 # deploymentManager: DeploymentManager):
177 # deploymentManager.oCloudId = self.oCloudId
179 # lambda x: x.deploymentManagerId ==
180 # deploymentManager.deploymentManagerId,
181 # self.deploymentManagers)
182 # for o in old or []:
183 # self.deploymentManagers.remove(o)
184 # self.deploymentManagers.append(deploymentManager)