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,
66 resource_list = api_ims_inventory_v1.model(
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,
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,
91 resource_json_mapping['children'] = fields.List(
92 fields.Nested(ResourceDTO.recursive_resource_mapping(
94 return api_ims_inventory_v1.model(
95 'ResourceGetDto' + str(iteration_number), resource_json_mapping)
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,
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
116 def get_resource_get(self):
117 return api_ims_inventory_v1.model(
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()))
133 class DeploymentManagerDTO:
135 deployment_manager_get = api_ims_inventory_v1.model(
136 "DeploymentManagerGetDto",
138 'deploymentManagerId': fields.String(
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,
151 class SubscriptionDTO:
153 subscription_get = api_ims_inventory_v1.model(
154 "SubscriptionGetDto",
156 'subscriptionId': fields.String(required=True,
157 description='Subscription ID'),
158 'callback': fields.String,
159 'consumerSubscriptionId': fields.String,
160 'filter': fields.String,
164 subscription = api_ims_inventory_v1.model(
165 "SubscriptionCreateDto",
167 'callback': fields.String(
168 required=True, description='Subscription callback address'),
169 'consumerSubscriptionId': fields.String,
170 'filter': fields.String,
174 subscription_post_resp = api_ims_inventory_v1.model(
175 "SubscriptionCreatedRespDto",
177 'subscriptionId': fields.String(required=True,
178 description='Subscription ID'),