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 flask_restx import fields
17 from o2ims.views.api_ns import api_ims_inventory as api_ims_inventory_v1
18 from o2common.views.flask_restx_fields import Json2Dict
23 ocloud = api_ims_inventory_v1.model(
26 'oCloudId': fields.String(
28 example='f078a1d3-56df-46c2-88a2-dd659aa3f6bd',
29 description='Identifier for the containing O-Cloud.'),
30 'globalCloudId': fields.String(
31 example='10a07219-4201-4b3e-a52d-81ab6a755d8a',
32 description='Identifier of the O-Cloud instance. ' +
33 'Globally unique across O-Cloud instances.'),
34 'globalcloudId': fields.String(
35 attribute='globalCloudId',
36 example='10a07219-4201-4b3e-a52d-81ab6a755d8a',
37 description='Identifier of the O-Cloud instance. ' +
38 'Globally unique across O-Cloud instances.(Specification)'),
39 'name': fields.String(
40 example='95b818b8-b315-4d9f-af37-b82c492101f1',
41 description='Human readable name of the O-Cloud.'),
42 'description': fields.String(
44 description='Human readable description of the O-Cloud.'),
45 'serviceUri': fields.String(
46 attribute='serviceUri',
47 example='https://128.224.115.51:30205',
48 description='The fully qualified URI root to all ' +
49 'services provided by the O2ims interface'),
50 # 'infrastructureManagementServiceEndpoint': fields.String(
51 # attribute='serviceUri'),
52 # 'infrastructureMangementServiceEndPoint': fields.String(
53 # attribute='serviceUri'),
54 # 'resourceTypes': fields.String,
55 # 'resourcePools': fields.String,
56 # 'deploymentManagers': fields.String,
57 # 'smoRegistrationService': fields.String
58 'extensions': fields.String(
60 description='These are unspecified (not standardized) ' +\
61 'properties (keys) which are tailored by the vendor ' +\
62 'to extend the information provided about the O-Cloud.'),
64 mask='{oCloudId,globalCloudId,globalcloudId,name,description,' +\
69 class ResourceTypeDTO:
70 alarm_definition = api_ims_inventory_v1.model(
73 'alarmDefinitionId': fields.String,
74 'alarmName': fields.String,
75 'alarmLastChange': fields.String,
76 'alarmChangeType': fields.String,
77 'alarmDescription': fields.String,
78 'proposedRepairActions': fields.String,
79 'clearingType': fields.String,
80 'managementInterfaceId': fields.String,
81 'pkNotificationField': fields.String,
82 'alarmAdditionalFields': fields.String,
86 alarm_dictionary = api_ims_inventory_v1.model(
90 'alarmDictionaryVersion': fields.String,
91 'alarmDictionarySchemaVersion': fields.String,
92 'entityType': fields.String,
93 'vendor': fields.String,
94 'managementInterfaceId': fields.String,
95 'pkNotificationField': fields.String,
96 # 'alarmDefinition': fields.String,
97 'alarmDefinition': fields.List(fields.Nested(alarm_definition),
98 attribute='alarmDefinition'),
102 resource_type_get = api_ims_inventory_v1.model(
103 "ResourceTypeGetDto",
105 'resourceTypeId': fields.String(required=True,
106 description='Resource type ID'),
107 'name': fields.String,
108 'description': fields.String,
109 'vendor': fields.String,
110 'model': fields.String,
111 'version': fields.String,
112 'alarmDictionary': fields.Nested(alarm_dictionary, False, True),
113 # 'resourceKind': fields.String,
114 # 'resourceClass': fields.String,
115 'extensions': fields.String
117 mask='{resourceTypeId,name,description,model,vendor,version}'
121 class ResourcePoolDTO:
123 resource_pool_get = api_ims_inventory_v1.model(
124 "ResourcePoolGetDto",
126 'resourcePoolId': fields.String(
128 example='f078a1d3-56df-46c2-88a2-dd659aa3f6bd',
129 description='Identifier for the Resource Pool in the ' +
130 'O-Cloud instance.'),
131 'globalLocationId': fields.String(
133 description='This identifier is copied from the O-Cloud ' +
134 'Id assigned by the SMO during the O-Cloud deployment.'),
135 'name': fields.String(
137 description='Human readable name of the resource pool.'),
138 'description': fields.String(
139 example='A Resource Pool',
140 description='Human readable description of the ' +
142 'oCloudId': fields.String(
143 example='f078a1d3-56df-46c2-88a2-dd659aa3f6bd',
144 description='Identifier for the containing O-Cloud.'),
145 'location': fields.String(
147 description='Information about the geographical ' +
148 'location of the resource pool as detected by the O-Cloud.'),
149 # 'resources': fields.String,
150 'extensions': fields.String(
152 description='List of metadata key-value pairs ' +\
153 'used to associate meaningful metadata to ' +\
154 'the related resource pool.')
156 mask='{resourcePoolId,oCloudId,globalLocationId,name,description}'
161 resource_list = api_ims_inventory_v1.model(
164 'resourceId': fields.String(required=True,
165 description='Resource ID'),
166 'resourceTypeId': fields.String,
167 'resourcePoolId': fields.String,
168 'globalAssetId': fields.String,
169 # 'name': fields.String,
170 'parentId': fields.String,
171 'description': fields.String,
172 # 'elements': fields.String,
173 # 'extensions': fields.String
174 'extensions': Json2Dict(attribute='extensions')
175 # 'extensions': fields.Raw(attribute='extensions')
177 mask='{resourceId,resourcePoolId,resourceTypeId,description,parentId}'
180 def recursive_resource_mapping(iteration_number=2):
181 resource_json_mapping = {
182 'resourceId': fields.String(required=True,
183 description='Resource ID'),
184 'resourceTypeId': fields.String,
185 'resourcePoolId': fields.String,
186 'globalAssetId': fields.String,
187 # 'name': fields.String,
188 'parentId': fields.String,
189 'description': fields.String,
190 # 'elements': fields.String,
191 # 'extensions': fields.String
192 'extensions': Json2Dict(attribute='extensions')
193 # 'extensions': fields.Raw(attribute='extensions')
196 resource_json_mapping['elements'] = fields.List(
197 fields.Nested(ResourceDTO.recursive_resource_mapping(
198 iteration_number-1)), attribute='children')
199 return api_ims_inventory_v1.model(
200 'ResourceGetDto' + str(iteration_number), resource_json_mapping,
201 mask='{resourceId,resourcePoolId,resourceTypeId,description,' +
205 class DeploymentManagerDTO:
207 deployment_manager_list = api_ims_inventory_v1.model(
208 "DeploymentManagerListDto",
210 'deploymentManagerId': fields.String(
212 description='Deployment manager ID'),
213 'name': fields.String,
214 'description': fields.String,
215 'oCloudId': fields.String,
216 'serviceUri': fields.String(attribute='serviceUri'),
217 # 'deploymentManagementServiceEndpoint': fields.String(
218 # attribute='serviceUri'),
219 # 'supportedLocations': fields.String,
220 # 'capabilities': fields.String,
221 # 'capacity': fields.String,
222 'profileSupportList': fields.List(
224 description='Profile support list, use default for the return \
226 'extensions': fields.String
228 mask='{deploymentManagerId,name,description,oCloudId,serviceUri,' + \
229 'profileSupportList}'
232 profile = api_ims_inventory_v1.model("DeploymentManagerGetDtoProfile", {
233 'cluster_api_endpoint': fields.String(
234 attribute='cluster_api_endpoint'),
235 'cluster_ca_cert': fields.String(attribute='cluster_ca_cert'),
236 'admin_user': fields.String(attribute='admin_user'),
237 'admin_client_cert': fields.String(attribute='admin_client_cert'),
238 'admin_client_key': fields.String(attribute='admin_client_key'),
239 # 'kube_config_file': fields.String(attribute='kube_config_file')
240 'helmcli_host_with_port': fields.String(
241 attribute='helmcli_host_with_port'),
242 'helmcli_username': fields.String(attribute='helmcli_username'),
243 'helmcli_password': fields.String(attribute='helmcli_password'),
244 'helmcli_kubeconfig': fields.String(attribute='helmcli_kubeconfig'),
247 extensions = api_ims_inventory_v1.model("DeploymentManagerExtensions", {
248 'profileName': fields.String,
249 'profileData': fields.Nested(profile, False, True),
252 deployment_manager_get = api_ims_inventory_v1.model(
253 "DeploymentManagerGetDto",
255 'deploymentManagerId': fields.String(
257 description='Deployment manager ID'),
258 'name': fields.String,
259 'description': fields.String,
260 'oCloudId': fields.String,
261 'serviceUri': fields.String(attribute='serviceUri'),
262 # 'deploymentManagementServiceEndpoint': fields.String(
263 # attribute='serviceUri'),
264 # 'supportedLocations': fields.String,
265 # 'capabilities': fields.String,
266 # 'capacity': fields.String,
267 'extensions': fields.Nested(extensions, True, True)
269 mask='{deploymentManagerId,name,description,oCloudId,serviceUri,' +\
270 'extensions/profileName,extensions/profileData}'
274 class SubscriptionDTO:
276 subscription_get = api_ims_inventory_v1.model(
277 "SubscriptionGetDto",
279 'subscriptionId': fields.String(required=True,
280 description='Subscription ID'),
281 'callback': fields.String,
282 'consumerSubscriptionId': fields.String,
283 'filter': fields.String,
285 mask='{subscriptionId,callback}'
288 subscription_create = api_ims_inventory_v1.model(
289 "SubscriptionCreateDto",
291 'callback': fields.String(
292 required=True, description='Subscription callback address'),
293 'consumerSubscriptionId': fields.String,
294 'filter': fields.String,