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
21 class InventoryApiV1DTO:
23 api_version = api_ims_inventory_v1.model(
24 'InventoryV1ApiVersionStructure',
26 'version': fields.String(
29 description='Identifies a supported version.'
35 api_version_info_get = api_ims_inventory_v1.model(
36 "InventoryV1APIVersion",
38 'uriPrefix': fields.String(
40 example='https://128.224.115.36:30205/' +
41 'o2ims-infrastructureInventory/v1',
42 description='Specifies the URI prefix for the API'),
43 'apiVersions': fields.List(
44 fields.Nested(api_version),
45 example=[{'version': '1.0.0'}],
46 description='Version(s) supported for the API ' +
47 'signaled by the uriPrefix attribute.'),
49 mask='{uriPrefix,apiVersions}'
55 ocloud = api_ims_inventory_v1.model(
58 'oCloudId': fields.String(
60 example='f078a1d3-56df-46c2-88a2-dd659aa3f6bd',
61 description='Identifier for the containing O-Cloud.'),
62 'globalCloudId': fields.String(
63 example='10a07219-4201-4b3e-a52d-81ab6a755d8a',
64 description='Identifier of the O-Cloud instance. ' +
65 'Globally unique across O-Cloud instances.'),
66 'globalcloudId': fields.String(
67 attribute='globalCloudId',
68 example='10a07219-4201-4b3e-a52d-81ab6a755d8a',
69 description='Identifier of the O-Cloud instance. ' +
70 'Globally unique across O-Cloud instances.(Specification)'),
71 'name': fields.String(
72 example='95b818b8-b315-4d9f-af37-b82c492101f1',
73 description='Human readable name of the O-Cloud.'),
74 'description': fields.String(
76 description='Human readable description of the O-Cloud.'),
77 'serviceUri': fields.String(
78 attribute='serviceUri',
79 example='https://128.224.115.51:30205',
80 description='The fully qualified URI root to all ' +
81 'services provided by the O2ims interface'),
82 # 'infrastructureManagementServiceEndpoint': fields.String(
83 # attribute='serviceUri'),
84 # 'infrastructureMangementServiceEndPoint': fields.String(
85 # attribute='serviceUri'),
86 # 'resourceTypes': fields.String,
87 # 'resourcePools': fields.String,
88 # 'deploymentManagers': fields.String,
89 # 'smoRegistrationService': fields.String
90 'extensions': fields.String(
92 description='These are unspecified (not standardized) ' +\
93 'properties (keys) which are tailored by the vendor ' +\
94 'to extend the information provided about the O-Cloud.'),
96 mask='{oCloudId,globalCloudId,globalcloudId,name,description,' +\
101 class ResourceTypeDTO:
102 alarm_definition = api_ims_inventory_v1.model(
103 "AlarmDefinitionDto",
105 'alarmDefinitionId': fields.String(
106 example='eaefa070-7cb6-3403-be46-177bd9ccc2d3',
107 description='Provides a unique identifier of the alarm ' +
109 'alarmName': fields.String(
111 description='Provides short name for the alarm.'),
112 'alarmLastChange': fields.String(
114 description='Indicates the Alarm Dictionary Version in ' +
115 'which this alarm last changed.'),
116 'alarmChangeType': fields.String(
118 description='Indicates the type of change that occurred ' +
119 'during the alarm last change; added, deleted, modified.'),
120 'alarmDescription': fields.String(
121 example='host=<hostname>.filesystem=<mount-dir>\n ' +
122 'File System threshold exceeded; threshold x%, actual y% .\n' +
123 ' CRITICAL @ 90%\n ' +
124 'MAJOR @ 80%\nOR\n' +
125 'host=<hostname>.volumegroup=<volumegroup-name>\n ' +
126 'Monitor and if condition persists, consider addin ...',
127 description='Provides a longer descriptive meaning of ' +
128 'the alarm condition and a description of the ' +
129 'consequences of the alarm condition.'),
130 'proposedRepairActions': fields.String(
131 example='Reduce usage or resize filesystem.',
132 description='Provides guidance for proposed repair actions.'),
133 'clearingType': fields.String(
135 description='Identifies whether alarm is cleared ' +
136 'automatically or manually.'),
137 'managementInterfaceId': fields.String(
139 description='List of management interface over which ' +
140 'alarms are transmitted for this Entity Type.'),
141 'pkNotificationField': fields.String(
143 description='Identifies which field or list of fields in ' +
144 'the alarm notification contains the primary key (PK) into ' +
145 'the Alarm Dictionary for this interface; i.e. which ' +
146 'field contains the Alarm Definition ID.'),
147 'alarmAdditionalFields': fields.String(
149 description='List of metadata key-value pairs used to ' +
150 'associate meaningful metadata to the related resource type.'),
154 alarm_dictionary = api_ims_inventory_v1.model(
155 "AlarmDictionaryDto",
158 example='7e1e59c3-c99e-3d1c-9934-21548a3a699a',
159 description='Identifier for the Alarm Dictionary.'),
160 'alarmDictionaryVersion': fields.String(
162 description='Version of the Alarm Dictionary.'),
163 'alarmDictionarySchemaVersion': fields.String(
165 description='Version of the Alarm Dictionary Schema to ' +
166 'which this alarm dictionary conforms.'),
167 'entityType': fields.String(
169 description='O-RAN entity type emitting the alarm: This ' +
170 'shall be unique per vendor ResourceType.model and ' +
171 'ResourceType.version'),
172 'vendor': fields.String(
174 description='Vendor of the Entity Type to whom this ' +
175 'Alarm Dictionary applies. This should be the same value ' +
176 'as in the ResourceType.vendor attribute.'),
177 'managementInterfaceId': fields.String(
179 description='List of management interface over which ' +
180 'alarms are transmitted for this Entity Type.'),
181 'pkNotificationField': fields.String(
183 description='Identifies which field or list of fields in ' +
184 'the alarm notification contains the primary key (PK) into ' +
185 'the Alarm Dictionary for this interface; i.e. which field ' +
186 'contains the Alarm Definition ID.'),
187 # 'alarmDefinition': fields.String,
188 'alarmDefinition': fields.List(
189 fields.Nested(alarm_definition),
190 attribute='alarmDefinition',
192 description='Contains the list of alarms that can be ' +
193 'detected against this ResourceType.'),
197 resource_type_get = api_ims_inventory_v1.model(
198 "ResourceTypeGetDto",
200 'resourceTypeId': fields.String(
202 example='60cba7be-e2cd-3b8c-a7ff-16e0f10573f9',
203 description='Identifier for the Resource Type.'),
204 'name': fields.String(
206 description='Human readable name of the resource type.'),
207 'description': fields.String(
208 example='The Physical Server resource type',
209 description='Human readable description of the resource ' +
211 'vendor': fields.String(
213 description='Provider of the Resource.'),
214 'model': fields.String(
216 description='Information about the model of the resource ' +
217 'as defined by its provider.'),
218 'version': fields.String(
220 description='Version or generation of the resource as ' +
221 'defined by its provider.'),
222 'alarmDictionary': fields.Nested(
223 alarm_dictionary, False, True),
224 # description='Dictionary of alarms for this resource type.'),
225 # 'resourceKind': fields.String,
226 # 'resourceClass': fields.String,
227 'extensions': fields.String(
229 description='List of metadata key-value pairs used to ' +
230 'associate meaningful metadata to the related resource type.'),
232 mask='{resourceTypeId,name,description,model,vendor,version}'
236 class ResourcePoolDTO:
238 resource_pool_get = api_ims_inventory_v1.model(
239 "ResourcePoolGetDto",
241 'resourcePoolId': fields.String(
243 example='f078a1d3-56df-46c2-88a2-dd659aa3f6bd',
244 description='Identifier for the Resource Pool in the ' +
245 'O-Cloud instance.'),
246 'globalLocationId': fields.String(
248 description='This identifier is copied from the O-Cloud ' +
249 'Id assigned by the SMO during the O-Cloud deployment.'),
250 'name': fields.String(
252 description='Human readable name of the resource pool.'),
253 'description': fields.String(
254 example='A Resource Pool',
255 description='Human readable description of the ' +
257 'oCloudId': fields.String(
258 example='f078a1d3-56df-46c2-88a2-dd659aa3f6bd',
259 description='Identifier for the containing O-Cloud.'),
260 'location': fields.String(
262 description='Information about the geographical ' +
263 'location of the resource pool as detected by the O-Cloud.'),
264 # 'resources': fields.String,
265 'extensions': fields.String(
267 description='List of metadata key-value pairs ' +\
268 'used to associate meaningful metadata to ' +\
269 'the related resource pool.')
271 mask='{resourcePoolId,oCloudId,globalLocationId,name,description}'
276 resource_list = api_ims_inventory_v1.model(
279 'resourceId': fields.String(
281 example='5b3a2da8-17da-466c-b5f7-972590c7baf2',
282 description='Identifier for the Resource.'),
283 'resourceTypeId': fields.String(
284 example='60cba7be-e2cd-3b8c-a7ff-16e0f10573f9',
285 description='Identifier for the Resource Type of ' +
287 'resourcePoolId': fields.String(
288 example='f078a1d3-56df-46c2-88a2-dd659aa3f6bd',
289 description='Identifier of the Resource Pool containing ' +
291 'globalAssetId': fields.String(
293 description='Identifier or serial number of the resource.'),
294 # 'name': fields.String,
295 'parentId': fields.String(
297 description='Identifier for the parent resource.'),
298 'description': fields.String(
299 example="id:1;hostname:controller-0;mgmt_mac:00:00:00:00:" +
300 "00:00;mgmt_ip:192.168.204.2;personality:controller;" +
301 "subfunctions:controller,worker;administrative:unlocked;" +
302 "operational:enabled;availability:available;" +
303 "clock_synchronization:ntp;capabilities:" +
304 "{'is_max_cpu_configurable': 'configurable', " +
305 "'stor_function': 'monitor', 'Personality': " +
306 "'Controller-Active'};boot_device:/dev/disk/by-path" +
307 "/pci-0000:02:00.0-scsi-0:1:0:0;rootfs_device:/dev/disk/" +
308 "by-path/pci-0000:02:00.0-scsi-0:1:0:0;software_load:" +
309 "22.12;install_state:None;max_cpu_mhz_allowed:None",
310 description='Human readable description of the resource.'),
311 # 'elements': fields.String,
312 # 'extensions': fields.String
313 'extensions': Json2Dict(attribute='extensions')
314 # 'extensions': fields.Raw(attribute='extensions')
316 mask='{resourceId,resourcePoolId,resourceTypeId,description,parentId}'
319 def recursive_resource_mapping(iteration_number=2):
320 resource_json_mapping = {
321 'resourceId': fields.String(
323 example='eee8b101-6b7f-4f0a-b54b-89adc0f3f906',
324 description='Identifier for the Resource.'),
325 'resourceTypeId': fields.String(
326 example='a45983bb-199a-30ec-b7a1-eab2455f333c',
327 description='Identifier for the Resource Type of ' +
329 'resourcePoolId': fields.String(
330 example='f078a1d3-56df-46c2-88a2-dd659aa3f6bd',
331 description='Identifier of the Resource Pool containing ' +
333 'globalAssetId': fields.String(
335 description='Identifier or serial number of the resource.'),
336 # 'name': fields.String,
337 'parentId': fields.String(
338 example='5b3a2da8-17da-466c-b5f7-972590c7baf2',
339 description='Identifier for the parent resource.'),
340 'description': fields.String(
341 example="cpu:0;core:0;thread:0;cpu_family:6;cpu_model:" +
342 "Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz;" +
343 "allocated_function:Platform;numa_node:0",
344 description='Human readable description of the resource.'),
345 # 'elements': fields.String,
346 # 'extensions': fields.String
347 'extensions': Json2Dict(attribute='extensions')
348 # 'extensions': fields.Raw(attribute='extensions')
351 resource_json_mapping['elements'] = fields.List(
352 fields.Nested(ResourceDTO.recursive_resource_mapping(
353 iteration_number-1)), attribute='children')
354 return api_ims_inventory_v1.model(
355 'ResourceGetDto' + str(iteration_number), resource_json_mapping,
356 mask='{resourceId,resourcePoolId,resourceTypeId,description,' +
360 class DeploymentManagerDTO:
362 deployment_manager_list = api_ims_inventory_v1.model(
363 "DeploymentManagerListDto",
365 'deploymentManagerId': fields.String(
367 example='c765516a-a84e-30c9-b954-9c3031bf71c8',
368 description='Identifier for the Deployment Manager.'),
369 'name': fields.String(
370 example='95b818b8-b315-4d9f-af37-b82c492101f1.kubernetes',
371 description='Human readable name of the deployment manager.'),
372 'description': fields.String(
374 description='Human readable description of the deployment ' +
376 'oCloudId': fields.String(
377 example='f078a1d3-56df-46c2-88a2-dd659aa3f6bd',
378 description='Identifier for the containing O-Cloud.'),
379 'serviceUri': fields.String(
380 attribute='serviceUri',
381 example='https://128.224.115.51:6443',
382 description='The fully qualified URI to a Deployment ' +
383 'Management server for O2dms services.'),
384 # 'deploymentManagementServiceEndpoint': fields.String(
385 # attribute='serviceUri'),
386 # 'supportedLocations': fields.String,
387 # 'capabilities': fields.String,
388 # 'capacity': fields.String,
389 'profileSupportList': fields.List(
391 example=['native_k8sapi'],
392 description='Profile support list, use default for the ' +
394 'extensions': fields.String(
396 description='List of metadata key-value pairs used to ' +
397 'associate meaningful metadata to the related Deployment ' +
400 mask='{deploymentManagerId,name,description,oCloudId,serviceUri,' + \
401 'profileSupportList}'
404 profile = api_ims_inventory_v1.model("DeploymentManagerGetDtoProfile", {
405 'cluster_api_endpoint': fields.String(
406 attribute='cluster_api_endpoint',
407 example='https://128.224.115.51:6443',
408 description='Kubernetes Cluster API Endpoint'),
409 'cluster_ca_cert': fields.String(
410 attribute='cluster_ca_cert',
411 example='LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUZEakNDQX.....',
412 description='Kubernetes Cluster CA cert'),
413 'admin_user': fields.String(
414 attribute='admin_user',
415 example='kubernetes-admin',
416 description='Kubernetes Admin username'),
417 'admin_client_cert': fields.String(
418 attribute='admin_client_cert',
419 example='LS0tLS1CRUdJTiBDRVJUSUZJQ0FURS0tLS0tCk1JSUVJRENDQW.....',
420 description='Kubernetes Admin client cert'),
421 'admin_client_key': fields.String(
422 attribute='admin_client_key',
423 example='LS0tLS1CRUdJTiBSU0EgUFJJVkFURSBLRVktLS0tLQpNSUlFcE.....',
424 description='Kubernetes Admin client key'),
425 # 'kube_config_file': fields.String(attribute='kube_config_file')
426 'helmcli_host_with_port': fields.String(
427 attribute='helmcli_host_with_port',
428 example='128.224.115.34:30022',
429 description='Helm CLI Host address with SSH port'),
430 'helmcli_username': fields.String(
431 attribute='helmcli_username',
433 description='Helm CLI SSH login username'),
434 'helmcli_password': fields.String(
435 attribute='helmcli_password',
437 description='Helm CLI SSH login password'),
438 'helmcli_kubeconfig': fields.String(
439 attribute='helmcli_kubeconfig',
440 example='/share/kubeconfig_c765516a.config',
441 description='Helm CLI KUBECONFIG path'),
444 extensions = api_ims_inventory_v1.model("DeploymentManagerExtensions", {
445 'profileName': fields.String(
448 'profileData': fields.Nested(profile, False, True),
451 deployment_manager_get = api_ims_inventory_v1.model(
452 "DeploymentManagerGetDto",
454 'deploymentManagerId': fields.String(
456 example='c765516a-a84e-30c9-b954-9c3031bf71c8',
457 description='Identifier for the Deployment Manager.'),
458 'name': fields.String(
459 example='95b818b8-b315-4d9f-af37-b82c492101f1.kubernetes',
460 description='Human readable name of the deployment manager.'),
461 'description': fields.String(
463 description='Human readable description of the deployment ' +
465 'oCloudId': fields.String(
466 example='f078a1d3-56df-46c2-88a2-dd659aa3f6bd',
467 description='Identifier for the containing O-Cloud.'),
468 'serviceUri': fields.String(
469 attribute='serviceUri',
470 example='https://128.224.115.51:6443',
471 description='The fully qualified URI to a Deployment ' +
472 'Management server for O2dms services.'),
473 # 'deploymentManagementServiceEndpoint': fields.String(
474 # attribute='serviceUri'),
475 # 'supportedLocations': fields.String,
476 # 'capabilities': fields.String,
477 # 'capacity': fields.String,
478 'extensions': fields.Nested(extensions, True, True)
480 mask='{deploymentManagerId,name,description,oCloudId,serviceUri,' +\
481 'extensions/profileName,extensions/profileData}'
485 class SubscriptionDTO:
487 subscription_get = api_ims_inventory_v1.model(
488 "SubscriptionGetDto",
490 'subscriptionId': fields.String(
492 example='0bea3e71-d2f7-4bf3-9c06-41d8d35806f9',
493 description='Identifier for the Subscription.'),
494 'callback': fields.String(
495 example='https://128.224.115.15:1081/smo/v1/' +
496 'o2ims_inventory_observer',
497 description='The fully qualified URI to a consumer ' +
498 'procedure which can process a Post of the ' +
499 'InventoryEventNotification.'),
500 'consumerSubscriptionId': fields.String(
501 example='3F20D850-AF4F-A84F-FB5A-0AD585410361',
502 description='Identifier for the consumer of events sent due ' +
503 'to the Subscription.'),
504 'filter': fields.String(
506 description='Criteria for events which do not need to be ' +
507 'reported or will be filtered by the subscription ' +
508 'notification service. Therefore, if a filter is not ' +
509 'provided then all events are reported.'),
511 mask='{subscriptionId,callback}'
514 subscription_create = api_ims_inventory_v1.model(
515 "SubscriptionCreateDto",
517 'callback': fields.String(
519 example='https://128.224.115.15:1081/smo/v1/' +
520 'o2ims_inventory_observer',
521 description='Identifier for the Subscription.'),
522 'consumerSubscriptionId': fields.String(
523 example='3F20D850-AF4F-A84F-FB5A-0AD585410361',
524 description='Identifier for the consumer of events sent due ' +
525 'to the Subscription.'),
526 'filter': fields.String(
528 description='Criteria for events which do not need to be ' +
529 'reported or will be filtered by the subscription ' +
530 'notification service. Therefore, if a filter is not ' +
531 'provided then all events are reported.'),