Docs: Update all API docs with example
[pti/o2.git] / o2ims / views / ocloud_dto.py
1 # Copyright (C) 2021 Wind River Systems, Inc.
2 #
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
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 from flask_restx import fields
16
17 from o2ims.views.api_ns import api_ims_inventory as api_ims_inventory_v1
18 from o2common.views.flask_restx_fields import Json2Dict
19
20
21 class InventoryApiV1DTO:
22
23     api_version = api_ims_inventory_v1.model(
24         'InventoryV1ApiVersionStructure',
25         {
26             'version': fields.String(
27                 required=True,
28                 example='1.0.0',
29                 description='Identifies a supported version.'
30             )
31         },
32         mask='{version,}'
33     )
34
35     api_version_info_get = api_ims_inventory_v1.model(
36         "InventoryV1APIVersion",
37         {
38             'uriPrefix': fields.String(
39                 required=True,
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.'),
48         },
49         mask='{uriPrefix,apiVersions}'
50     )
51
52
53 class OcloudDTO:
54
55     ocloud = api_ims_inventory_v1.model(
56         "OcloudDto",
57         {
58             'oCloudId': fields.String(
59                 required=True,
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(
75                 example='An ocloud',
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(
91                 example='',
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.'),
95         },
96         mask='{oCloudId,globalCloudId,globalcloudId,name,description,' +\
97         'serviceUri}'
98     )
99
100
101 class ResourceTypeDTO:
102     alarm_definition = api_ims_inventory_v1.model(
103         "AlarmDefinitionDto",
104         {
105             'alarmDefinitionId': fields.String(
106                 example='eaefa070-7cb6-3403-be46-177bd9ccc2d3',
107                 description='Provides a unique identifier of the alarm ' +
108                 'being raised.'),
109             'alarmName': fields.String(
110                 example='100.104',
111                 description='Provides short name for the alarm.'),
112             'alarmLastChange': fields.String(
113                 example='0.1',
114                 description='Indicates the Alarm Dictionary Version in ' +
115                 'which this alarm last changed.'),
116             'alarmChangeType': fields.String(
117                 example='ADDED',
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(
134                 example='MANUAL',
135                 description='Identifies whether alarm is cleared ' +
136                 'automatically or manually.'),
137             'managementInterfaceId': fields.String(
138                 example='O2IMS',
139                 description='List of management interface over which ' +
140                 'alarms are transmitted for this Entity Type.'),
141             'pkNotificationField': fields.String(
142                 example='',
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(
148                 example='',
149                 description='List of metadata key-value pairs used to ' +
150                 'associate meaningful metadata to the related resource type.'),
151         }
152
153     )
154     alarm_dictionary = api_ims_inventory_v1.model(
155         "AlarmDictionaryDto",
156         {
157             'id': fields.String(
158                 example='7e1e59c3-c99e-3d1c-9934-21548a3a699a',
159                 description='Identifier for the Alarm Dictionary.'),
160             'alarmDictionaryVersion': fields.String(
161                 example='0.1',
162                 description='Version of the Alarm Dictionary.'),
163             'alarmDictionarySchemaVersion': fields.String(
164                 example='0.1',
165                 description='Version of the Alarm Dictionary Schema to ' +
166                 'which this alarm dictionary conforms.'),
167             'entityType': fields.String(
168                 example='pserver',
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(
173                 example='',
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(
178                 example='O2IMS',
179                 description='List of management interface over which ' +
180                 'alarms are transmitted for this Entity Type.'),
181             'pkNotificationField': fields.String(
182                 example='',
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',
191                 example='',
192                 description='Contains the list of alarms that can be ' +
193                 'detected against this ResourceType.'),
194         }
195     )
196
197     resource_type_get = api_ims_inventory_v1.model(
198         "ResourceTypeGetDto",
199         {
200             'resourceTypeId': fields.String(
201                 required=True,
202                 example='60cba7be-e2cd-3b8c-a7ff-16e0f10573f9',
203                 description='Identifier for the Resource Type.'),
204             'name': fields.String(
205                 example='pserver',
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 ' +
210                 'type.'),
211             'vendor': fields.String(
212                 example='',
213                 description='Provider of the Resource.'),
214             'model': fields.String(
215                 example='',
216                 description='Information about the model of the resource ' +
217                 'as defined by its provider.'),
218             'version': fields.String(
219                 example='',
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(
228                 example='',
229                 description='List of metadata key-value pairs used to ' +
230                 'associate meaningful metadata to the related resource type.'),
231         },
232         mask='{resourceTypeId,name,description,model,vendor,version}'
233     )
234
235
236 class ResourcePoolDTO:
237
238     resource_pool_get = api_ims_inventory_v1.model(
239         "ResourcePoolGetDto",
240         {
241             'resourcePoolId': fields.String(
242                 required=True,
243                 example='f078a1d3-56df-46c2-88a2-dd659aa3f6bd',
244                 description='Identifier for the Resource Pool in the ' +
245                 'O-Cloud instance.'),
246             'globalLocationId': fields.String(
247                 example='',
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(
251                 example='RegionOne',
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 ' +
256                 'resource pool.'),
257             'oCloudId': fields.String(
258                 example='f078a1d3-56df-46c2-88a2-dd659aa3f6bd',
259                 description='Identifier for the containing O-Cloud.'),
260             'location': fields.String(
261                 example='',
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(
266                 example='',
267                 description='List of metadata key-value pairs ' +\
268                 'used to associate meaningful metadata to ' +\
269                 'the related resource pool.')
270         },
271         mask='{resourcePoolId,oCloudId,globalLocationId,name,description}'
272     )
273
274
275 class ResourceDTO:
276     resource_list = api_ims_inventory_v1.model(
277         "ResourceListDto",
278         {
279             'resourceId': fields.String(
280                 required=True,
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 ' +
286                 'this resource.'),
287             'resourcePoolId': fields.String(
288                 example='f078a1d3-56df-46c2-88a2-dd659aa3f6bd',
289                 description='Identifier of the Resource Pool containing ' +
290                 'this resource.'),
291             'globalAssetId': fields.String(
292                 example='',
293                 description='Identifier or serial number of the resource.'),
294             # 'name': fields.String,
295             'parentId': fields.String(
296                 example='None',
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')
315         },
316         mask='{resourceId,resourcePoolId,resourceTypeId,description,parentId}'
317     )
318
319     def recursive_resource_mapping(iteration_number=2):
320         resource_json_mapping = {
321             'resourceId': fields.String(
322                 required=True,
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 ' +
328                 'this resource.'),
329             'resourcePoolId': fields.String(
330                 example='f078a1d3-56df-46c2-88a2-dd659aa3f6bd',
331                 description='Identifier of the Resource Pool containing ' +
332                 'this resource.'),
333             'globalAssetId': fields.String(
334                 example='',
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')
349         }
350         if iteration_number:
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,' +
357             'parentId}')
358
359
360 class DeploymentManagerDTO:
361
362     deployment_manager_list = api_ims_inventory_v1.model(
363         "DeploymentManagerListDto",
364         {
365             'deploymentManagerId': fields.String(
366                 required=True,
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(
373                 example='A DMS',
374                 description='Human readable description of the deployment ' +
375                 'manager.'),
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(
390                 fields.String,
391                 example=['native_k8sapi'],
392                 description='Profile support list, use default for the ' +
393                 'return endpoint'),
394             'extensions': fields.String(
395                 example='',
396                 description='List of metadata key-value pairs used to ' +
397                 'associate meaningful metadata to the related Deployment ' +
398                 'Manager'),
399         },
400         mask='{deploymentManagerId,name,description,oCloudId,serviceUri,' + \
401         'profileSupportList}'
402     )
403
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',
432             example='helm',
433             description='Helm CLI SSH login username'),
434         'helmcli_password': fields.String(
435             attribute='helmcli_password',
436             example='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'),
442     })
443
444     extensions = api_ims_inventory_v1.model("DeploymentManagerExtensions", {
445         'profileName': fields.String(
446             example='',
447             description=''),
448         'profileData': fields.Nested(profile, False, True),
449     })
450
451     deployment_manager_get = api_ims_inventory_v1.model(
452         "DeploymentManagerGetDto",
453         {
454             'deploymentManagerId': fields.String(
455                 required=True,
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(
462                 example='A DMS',
463                 description='Human readable description of the deployment ' +
464                 'manager.'),
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)
479         },
480         mask='{deploymentManagerId,name,description,oCloudId,serviceUri,' +\
481         'extensions/profileName,extensions/profileData}'
482     )
483
484
485 class SubscriptionDTO:
486
487     subscription_get = api_ims_inventory_v1.model(
488         "SubscriptionGetDto",
489         {
490             'subscriptionId': fields.String(
491                 required=True,
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(
505                 example='',
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.'),
510         },
511         mask='{subscriptionId,callback}'
512     )
513
514     subscription_create = api_ims_inventory_v1.model(
515         "SubscriptionCreateDto",
516         {
517             'callback': fields.String(
518                 required=True,
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(
527                 example='',
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.'),
532         }
533     )