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