Docs: Add API docs from swagger json file; Add user guide document
[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_v1
18
19
20 class OcloudDTO:
21
22     ocloud = api_ims_inventory_v1.model(
23         "OcloudDto",
24         {
25             'oCloudId': fields.String(required=True),
26             'globalCloudId': fields.String,
27             'name': fields.String,
28             'description': fields.String,
29             'infrastructureManagementServiceEndpoint': fields.String,
30         }
31     )
32
33
34 class ResourceTypeDTO:
35
36     resource_type_get = api_ims_inventory_v1.model(
37         "ResourceTypeGetDto",
38         {
39             'resourceTypeId': fields.String(required=True,
40                                             description='Resource type ID'),
41             'name': fields.String,
42             'vendor': fields.String,
43             'version': fields.String,
44             'description': fields.String,
45         }
46     )
47
48
49 class ResourcePoolDTO:
50
51     resource_pool_get = api_ims_inventory_v1.model(
52         "ResourcePoolGetDto",
53         {
54             'resourcePoolId': fields.String(required=True,
55                                             description='Resource pool ID'),
56             'name': fields.String,
57             'globalLocationId': fields.String,
58             'location': fields.String,
59             'description': fields.String,
60         }
61     )
62
63
64 class ResourceDTO:
65
66     resource_list = api_ims_inventory_v1.model(
67         "ResourceListDto",
68         {
69             'resourceId': fields.String(required=True,
70                                         description='Resource ID'),
71             'resourceTypeId': fields.String,
72             'resourcePoolId': fields.String,
73             'name': fields.String,
74             'parentId': fields.String,
75             'description': fields.String,
76         }
77     )
78
79     def recursive_resource_mapping(iteration_number=2):
80         resource_json_mapping = {
81             'resourceId': fields.String(required=True,
82                                         description='Resource ID'),
83             'resourceTypeId': fields.String,
84             'resourcePoolId': fields.String,
85             'name': fields.String,
86             'parentId': fields.String,
87             'description': fields.String,
88             'elements': fields.String,
89         }
90         if iteration_number:
91             resource_json_mapping['children'] = fields.List(
92                 fields.Nested(ResourceDTO.recursive_resource_mapping(
93                     iteration_number-1)))
94         return api_ims_inventory_v1.model(
95             'ResourceGetDto' + str(iteration_number), resource_json_mapping)
96
97     def _recursive_resource_mapping(self, iteration_number=2):
98         resource_json_mapping = {
99             'resourceId': fields.String(required=True,
100                                         description='Resource ID'),
101             'resourceTypeId': fields.String,
102             'resourcePoolId': fields.String,
103             'name': fields.String,
104             'parentId': fields.String,
105             'description': fields.String,
106         }
107         if iteration_number:
108             resource_json_mapping['children'] = fields.List(
109                 fields.Nested(self._recursive_resource_mapping(
110                     iteration_number-1)))
111             # print(type(resource_json_mapping['children']))
112             if resource_json_mapping['children'] is None:
113                 del resource_json_mapping['children']
114         return resource_json_mapping
115
116     def get_resource_get(self):
117         return api_ims_inventory_v1.model(
118             'ResourceGetDto',
119             {
120                 'resourceId': fields.String(required=True,
121                                             description='Resource ID'),
122                 'resourceTypeId': fields.String,
123                 'resourcePoolId': fields.String,
124                 'name': fields.String,
125                 'parentId': fields.String,
126                 'description': fields.String,
127                 'children': fields.List(fields.Nested(
128                     self._recursive_resource_mapping()))
129             }
130         )
131
132
133 class DeploymentManagerDTO:
134
135     deployment_manager_get = api_ims_inventory_v1.model(
136         "DeploymentManagerGetDto",
137         {
138             'deploymentManagerId': fields.String(
139                 required=True,
140                 description='Deployment manager ID'),
141             'name': fields.String,
142             'description': fields.String,
143             'deploymentManagementServiceEndpoint': fields.String,
144             'supportedLocations': fields.String,
145             'capabilities': fields.String,
146             'capacity': fields.String,
147         }
148     )
149
150
151 class SubscriptionDTO:
152
153     subscription_get = api_ims_inventory_v1.model(
154         "SubscriptionGetDto",
155         {
156             'subscriptionId': fields.String(required=True,
157                                             description='Subscription ID'),
158             'callback': fields.String,
159             'consumerSubscriptionId': fields.String,
160             'filter': fields.String,
161         }
162     )
163
164     subscription = api_ims_inventory_v1.model(
165         "SubscriptionCreateDto",
166         {
167             'callback': fields.String(
168                 required=True, description='Subscription callback address'),
169             'consumerSubscriptionId': fields.String,
170             'filter': fields.String,
171         }
172     )
173
174     subscription_post_resp = api_ims_inventory_v1.model(
175         "SubscriptionCreatedRespDto",
176         {
177             'subscriptionId': fields.String(required=True,
178                                             description='Subscription ID'),
179         }
180     )