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_v1
22 ocloud = api_ims_inventory_v1.model(
25 'oCloudId': fields.String(required=True),
26 'globalCloudId': fields.String,
27 'name': fields.String,
28 'description': fields.String,
29 'infrastructureManagementServiceEndpoint': fields.String,
34 class ResourceTypeDTO:
36 resource_type_get = api_ims_inventory_v1.model(
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,
49 class ResourcePoolDTO:
51 resource_pool_get = api_ims_inventory_v1.model(
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,
65 resource_list = api_ims_inventory_v1.model(
68 'resourceId': fields.String(required=True,
69 description='Resource ID'),
70 'resourceTypeId': fields.String,
71 'resourcePoolId': fields.String,
72 'name': fields.String,
73 'parentId': fields.String,
74 'description': fields.String,
78 list_result = api_ims_inventory_v1.model(
79 "ResourceListPagenationDto",
81 'count': fields.Integer(),
82 'page_num': fields.Integer(),
83 'results': fields.List(fields.Nested(resource_list))
87 # def get_paginated_list(results, url, start, limit):
90 # count = len(results)
91 # if count < start or limit < 0:
92 # api_ims_inventory_v1.abort(404)
95 # obj['start'] = start
96 # obj['limit'] = limit
97 # obj['count'] = count
101 # obj['previous'] = ''
103 # start_copy = max(1, start - limit)
104 # limit_copy = start - 1
105 # obj['previous'] = url + \
106 # '?start=%d&limit=%d' % (start_copy, limit_copy)
108 # if start + limit > count:
111 # start_copy = start + limit
112 # obj['next'] = url + '?start=%d&limit=%d' % (start_copy, limit)
113 # # finally extract result according to bounds
114 # # obj['results'] = results[(start - 1):(start - 1 + limit)]
115 # obj['result'] = fields.List(fields.Nested(ResourceDTO.resource_list))
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 'name': fields.String,
125 'parentId': fields.String,
126 'description': fields.String,
127 'elements': fields.String,
130 resource_json_mapping['children'] = fields.List(
131 fields.Nested(ResourceDTO.recursive_resource_mapping(
132 iteration_number-1)))
133 return api_ims_inventory_v1.model(
134 'ResourceGetDto' + str(iteration_number), resource_json_mapping)
136 # def _recursive_resource_mapping(self, iteration_number=2):
137 # resource_json_mapping = {
138 # 'resourceId': fields.String(required=True,
139 # description='Resource ID'),
140 # 'resourceTypeId': fields.String,
141 # 'resourcePoolId': fields.String,
142 # 'name': fields.String,
143 # 'parentId': fields.String,
144 # 'description': fields.String,
146 # if iteration_number:
147 # resource_json_mapping['children'] = fields.List(
148 # fields.Nested(self._recursive_resource_mapping(
149 # iteration_number-1)))
150 # # print(type(resource_json_mapping['children']))
151 # if resource_json_mapping['children'] is None:
152 # del resource_json_mapping['children']
153 # return resource_json_mapping
155 # def get_resource_get(self):
156 # return api_ims_inventory_v1.model(
159 # 'resourceId': fields.String(required=True,
160 # description='Resource ID'),
161 # 'resourceTypeId': fields.String,
162 # 'resourcePoolId': fields.String,
163 # 'name': fields.String,
164 # 'parentId': fields.String,
165 # 'description': fields.String,
166 # 'children': fields.List(fields.Nested(
167 # self._recursive_resource_mapping()))
172 class DeploymentManagerDTO:
174 deployment_manager_list = api_ims_inventory_v1.model(
175 "DeploymentManagerListDto",
177 'deploymentManagerId': fields.String(
179 description='Deployment manager ID'),
180 'name': fields.String,
181 'description': fields.String,
182 'deploymentManagementServiceEndpoint': fields.String,
183 'supportedLocations': fields.String,
184 'capabilities': fields.String,
185 'capacity': fields.String,
186 'profileSupportList': fields.List(
188 description='Profile support list, use default for the return \
193 profile = api_ims_inventory_v1.model("DeploymentManagerGetDtoProfile", {
194 'cluster_api_endpoint': fields.String(
195 attributes='cluster_api_endpoint'),
196 'cluster_ca_cert': fields.String(attributes='cluster_ca_cert'),
197 'admin_user': fields.String(attributes='admin_user'),
198 'admin_client_cert': fields.String(attributes='admin_client_cert'),
199 'admin_client_key': fields.String(attributes='admin_client_key'),
200 # 'kube_config_file': fields.String(attributes='kube_config_file')
201 'helmcli_host_with_port': fields.String(
202 attributes='helmcli_host_with_port'),
203 'helmcli_username': fields.String(attributes='helmcli_username'),
204 'helmcli_password': fields.String(attributes='helmcli_password'),
205 'helmcli_kubeconfig': fields.String(attributes='helmcli_kubeconfig'),
208 deployment_manager_get = api_ims_inventory_v1.model(
209 "DeploymentManagerGetDto",
211 'deploymentManagerId': fields.String(
213 description='Deployment manager ID'),
214 'name': fields.String,
215 'description': fields.String,
216 'deploymentManagementServiceEndpoint': fields.String,
217 'supportedLocations': fields.String,
218 'capabilities': fields.String,
219 'capacity': fields.String,
220 'profileName': fields.String,
221 'profileData': fields.Nested(profile, False, True),
226 class SubscriptionDTO:
228 subscription_get = api_ims_inventory_v1.model(
229 "SubscriptionGetDto",
231 'subscriptionId': fields.String(required=True,
232 description='Subscription ID'),
233 'callback': fields.String,
234 'consumerSubscriptionId': fields.String,
235 'filter': fields.String,
239 subscription = api_ims_inventory_v1.model(
240 "SubscriptionCreateDto",
242 'callback': fields.String(
243 required=True, description='Subscription callback address'),
244 'consumerSubscriptionId': fields.String,
245 'filter': fields.String,
249 subscription_post_resp = api_ims_inventory_v1.model(
250 "SubscriptionCreatedRespDto",
252 'subscriptionId': fields.String(required=True,
253 description='Subscription ID'),