Merge "Fix INF-356 DC client auth token is invalid"
[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 OcloudDTO:
22
23     ocloud = api_ims_inventory_v1.model(
24         "OcloudDto",
25         {
26             'oCloudId': fields.String(required=True),
27             'globalcloudId': fields.String(attribute='globalCloudId'),
28             'name': fields.String,
29             'description': fields.String,
30             'serviceUri': fields.String(attribute='serviceUri'),
31             # 'infrastructureManagementServiceEndpoint': fields.String(
32             # attribute='serviceUri'),
33             # 'infrastructureMangementServiceEndPoint': fields.String(
34             # attribute='serviceUri'),
35             # 'resourceTypes': fields.String,
36             # 'resourcePools': fields.String,
37             # 'deploymentManagers': fields.String,
38             # 'smoRegistrationService': fields.String
39             'extensions': fields.String
40         },
41         mask='{oCloudId,globalcloudId,name,description,serviceUri}'
42     )
43
44
45 class ResourceTypeDTO:
46     alarm_dictionary = api_ims_inventory_v1.model(
47         "AlarmDictionaryDto",
48         {
49             'id': fields.String,
50             'alarmDictionaryVersion': fields.String,
51             'alarmDictionarySchemVersion': fields.String,
52             'entityType': fields.String,
53             'vendor': fields.String,
54             'managementInterfaceId': fields.String,
55             'pkNotificationField': fields.String,
56             'alarmDefinition': fields.String,
57         }
58     )
59
60     resource_type_get = api_ims_inventory_v1.model(
61         "ResourceTypeGetDto",
62         {
63             'resourceTypeId': fields.String(required=True,
64                                             description='Resource type ID'),
65             'name': fields.String,
66             'description': fields.String,
67             'vendor': fields.String,
68             'model': fields.String,
69             'version': fields.String,
70             'alarmDictionary': fields.Nested(alarm_dictionary, False, True),
71             # 'resourceKind': fields.String,
72             # 'resourceClass': fields.String,
73             'extensions': fields.String
74         },
75         mask='{resourceTypeId,name,description,model,vendor,version}'
76     )
77
78
79 class ResourcePoolDTO:
80
81     resource_pool_get = api_ims_inventory_v1.model(
82         "ResourcePoolGetDto",
83         {
84             'resourcePoolId': fields.String(required=True,
85                                             description='Resource pool ID'),
86             'globalLocationId': fields.String,
87             'name': fields.String,
88             'description': fields.String,
89             'oCloudId': fields.String,
90             'location': fields.String,
91             # 'resources': fields.String,
92             'extensions': fields.String
93         },
94         mask='{resourcePoolId,oCloudId,globalLocationId,name,description}'
95     )
96
97
98 class ResourceDTO:
99     resource_list = api_ims_inventory_v1.model(
100         "ResourceListDto",
101         {
102             'resourceId': fields.String(required=True,
103                                         description='Resource ID'),
104             'resourceTypeId': fields.String,
105             'resourcePoolId': fields.String,
106             'globalAssetId': fields.String,
107             # 'name': fields.String,
108             'parentId': fields.String,
109             'description': fields.String,
110             # 'elements': fields.String,
111             # 'extensions': fields.String
112             'extensions': Json2Dict(attribute='extensions')
113             # 'extensions': fields.Raw(attribute='extensions')
114         },
115         mask='{resourceId,resourcePoolId,resourceTypeId,description,parentId}'
116     )
117
118     def recursive_resource_mapping(iteration_number=2):
119         resource_json_mapping = {
120             'resourceId': fields.String(required=True,
121                                         description='Resource ID'),
122             'resourceTypeId': fields.String,
123             'resourcePoolId': fields.String,
124             'globalAssetId': fields.String,
125             # 'name': fields.String,
126             'parentId': fields.String,
127             'description': fields.String,
128             # 'elements': fields.String,
129             # 'extensions': fields.String
130             'extensions': Json2Dict(attribute='extensions')
131             # 'extensions': fields.Raw(attribute='extensions')
132         }
133         if iteration_number:
134             resource_json_mapping['elements'] = fields.List(
135                 fields.Nested(ResourceDTO.recursive_resource_mapping(
136                     iteration_number-1)), attribute='children')
137         return api_ims_inventory_v1.model(
138             'ResourceGetDto' + str(iteration_number), resource_json_mapping,
139             mask='{resourceId,resourcePoolId,resourceTypeId,description,' +
140             'parentId}')
141
142
143 class DeploymentManagerDTO:
144
145     deployment_manager_list = api_ims_inventory_v1.model(
146         "DeploymentManagerListDto",
147         {
148             'deploymentManagerId': fields.String(
149                 required=True,
150                 description='Deployment manager ID'),
151             'name': fields.String,
152             'description': fields.String,
153             'oCloudId': fields.String,
154             'serviceUri': fields.String(attribute='serviceUri'),
155             # 'deploymentManagementServiceEndpoint': fields.String(
156             # attribute='serviceUri'),
157             # 'supportedLocations': fields.String,
158             # 'capabilities': fields.String,
159             # 'capacity': fields.String,
160             'profileSupportList': fields.List(
161                 fields.String,
162                 description='Profile support list, use default for the return \
163                      endpoint'),
164             'extensions': fields.String
165         },
166         mask='{deploymentManagerId,name,description,oCloudId,serviceUri,' + \
167         'profileSupportList}'
168     )
169
170     profile = api_ims_inventory_v1.model("DeploymentManagerGetDtoProfile", {
171         'cluster_api_endpoint': fields.String(
172             attribute='cluster_api_endpoint'),
173         'cluster_ca_cert': fields.String(attribute='cluster_ca_cert'),
174         'admin_user': fields.String(attribute='admin_user'),
175         'admin_client_cert': fields.String(attribute='admin_client_cert'),
176         'admin_client_key': fields.String(attribute='admin_client_key'),
177         # 'kube_config_file': fields.String(attribute='kube_config_file')
178         'helmcli_host_with_port': fields.String(
179             attribute='helmcli_host_with_port'),
180         'helmcli_username': fields.String(attribute='helmcli_username'),
181         'helmcli_password': fields.String(attribute='helmcli_password'),
182         'helmcli_kubeconfig': fields.String(attribute='helmcli_kubeconfig'),
183     })
184
185     extensions = api_ims_inventory_v1.model("DeploymentManagerExtensions", {
186         'profileName': fields.String,
187         'profileData': fields.Nested(profile, False, True),
188     })
189
190     deployment_manager_get = api_ims_inventory_v1.model(
191         "DeploymentManagerGetDto",
192         {
193             'deploymentManagerId': fields.String(
194                 required=True,
195                 description='Deployment manager ID'),
196             'name': fields.String,
197             'description': fields.String,
198             'oCloudId': fields.String,
199             'serviceUri': fields.String(attribute='serviceUri'),
200             # 'deploymentManagementServiceEndpoint': fields.String(
201             # attribute='serviceUri'),
202             # 'supportedLocations': fields.String,
203             # 'capabilities': fields.String,
204             # 'capacity': fields.String,
205             'extensions': fields.Nested(extensions, True, True)
206         },
207         mask='{deploymentManagerId,name,description,oCloudId,serviceUri,' +\
208         'extensions/profileName,extensions/profileData}'
209     )
210
211
212 class SubscriptionDTO:
213
214     subscription_get = api_ims_inventory_v1.model(
215         "SubscriptionGetDto",
216         {
217             'subscriptionId': fields.String(required=True,
218                                             description='Subscription ID'),
219             'callback': fields.String,
220             'consumerSubscriptionId': fields.String,
221             'filter': fields.String,
222         },
223         mask='{subscriptionId,callback}'
224     )
225
226     subscription_create = api_ims_inventory_v1.model(
227         "SubscriptionCreateDto",
228         {
229             'callback': fields.String(
230                 required=True, description='Subscription callback address'),
231             'consumerSubscriptionId': fields.String,
232             'filter': fields.String,
233         }
234     )