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)
66 if 'capabilities' in d and d['capabilities'] != '':
67 d['capabilities'] = json.loads(d['capabilities'])
71 class ResourcePool(AgRoot, Serializer):
72 def __init__(self, id: str, name: str, location: str,
73 ocloudid: str, gLocationId: str = '',
74 description: str = '') -> None:
76 self.resourcePoolId = id
77 self.globalLocationId = gLocationId
79 self.description = description
80 self.oCloudId = ocloudid
81 self.location = location
85 self.version_number = 0
88 class ResourceType(AgRoot, Serializer):
89 def __init__(self, typeid: str, name: str, typeEnum: ResourceTypeEnum,
90 vendor: str = '', model: str = '',
92 description: str = '') -> None:
94 self.resourceTypeId = typeid
95 self.resourceTypeEnum = typeEnum
97 self.description = description
100 self.version = version
101 self.alarmDictionary = None
102 self.resourceKind = ResourceKindEnum.UNDEFINED
103 self.resourceClass = ResourceTypeEnum.UNDEFINED
106 self.version_number = 0
109 d = Serializer.serialize(self)
110 if 'alarmDictionary' in d and \
111 type(d['alarmDictionary']) is AlarmDictionary:
112 d['alarmDictionary'] = d['alarmDictionary'].serialize()
116 class Resource(AgRoot, Serializer):
117 def __init__(self, resourceId: str, resourceTypeId: str,
118 resourcePoolId: str, parentId: str = '',
119 gAssetId: str = '', elements: str = '',
120 description: str = '', extensions: str = '') -> None:
122 self.resourceId = resourceId
123 self.description = description
124 self.resourceTypeId = resourceTypeId
125 self.globalAssetId = gAssetId
126 self.resourcePoolId = resourcePoolId
127 self.elements = elements
128 self.extensions = extensions
130 self.parentId = parentId
133 self.version_number = 0
135 def set_children(self, children: list):
136 self.children = children
138 def set_resource_type_name(self, resource_type_name: str):
139 self.resourceTypeName = resource_type_name
142 d = Serializer.serialize(self)
144 if 'elements' in d and d['elements'] != '':
145 d['elements'] = json.loads(d['elements'])
147 if not hasattr(self, 'children') or len(self.children) == 0:
152 for child in self.children:
153 d['children'].append(child.serialize())
157 class Ocloud(AgRoot, Serializer):
158 def __init__(self, ocloudid: str, name: str, imsendpoint: str,
159 globalcloudId: str = '',
160 description: str = '', version_number: int = 0) -> None:
162 self.oCloudId = ocloudid
163 self.globalCloudId = globalcloudId
165 self.description = description
166 self.serviceUri = imsendpoint
167 self.resourceTypes = []
168 self.resourcePools = []
169 self.deploymentManagers = []
170 self.smoRegistrationService = ''
173 self.version_number = version_number
175 # def addDeploymentManager(self,
176 # deploymentManager: DeploymentManager):
178 # deploymentManager.oCloudId = self.oCloudId
180 # lambda x: x.deploymentManagerId ==
181 # deploymentManager.deploymentManagerId,
182 # self.deploymentManagers)
183 # for o in old or []:
184 # self.deploymentManagers.remove(o)
185 # self.deploymentManagers.append(deploymentManager)