blob: a7a4ca2dce64c3a92d96dc43d011116c54f2bd51 [file] [log] [blame]
Hong Hui Xiao589deee2018-02-02 16:26:17 +08001..
2 This work is licensed under a Creative Commons Attribution 4.0
3 International License.
Aric Gardnerf7da2ce2020-04-09 11:08:14 -07004.. _offeredapis:
Hong Hui Xiao589deee2018-02-02 16:26:17 +08005
6====================================
7Elastic API exposure for Multi Cloud
8====================================
9
10This spec is to provide a framework for Multi-Cloud to expose API.
11
12Problem Description
13===================
14
15Multi-Cloud provides VIM API for other projects in ONAP. API will vary for
16different projects. However, Multi-Cloud exposes its API by static code.
17Current way of API exposing produces code duplications.
18
19#. When a client creates a resource through Multi-Cloud, Multi-Cloud needs
20to convert the API request to back-end OpenStack API request and send to
21OpenStack. When a client requests a resource through Multi-Cloud, Multi-Cloud
22needs to retrieve OpenStack resource, converts to its API and reply to client.
23Even though the two conversion are the same thing with different directions,
24there are 2 sets of code for it.
25
26#. Most of Multi-Cloud API shares same logic. But the code of this same logic
27are duplicated for every API.
28
29Given the fact mentioned above, current code amount of Multi-Cloud are larger
30than it should be. It makes code maintaining be time-consuming and error-prone.
31
32Besides, the swagger files that describe API of Multi-Cloud are maintained
33manually. It is thousands lines of code and hard for developers to maintain.
34
35Proposed Change
36===============
37
38This spec proposes using YAML files to describe Multi-Cloud API. A framework
39will also be provided. When Multi-Cloud services start up, the framework will
40read YAML files, parse them and generate API accordingly. Multi-Cloud can
41dynamically expose API in this way without changing its Python code. And
42developers only need to maintain YAML files that describe Multi-Cloud API.
43The YAML files are expected to be less amount than current way of API exposing,
44because it only contains metadata of Multi-Cloud API.
45
46Using the proposal in this spec, metadata of API are defined in YAML files and
47logic of API handling are concentrated in the framework mentioned above. So
48that the code duplication can be eliminated.
49
50To narrow down the scope of this spec, none of current Multi-Cloud API will be
51changed. This spec will ONLY focus on migrating Multi-Cloud API from current
52way to the proposed framework in this spec. However, migrating all API to the
53proposed framework is out of the scope of this spec. A set of API for one
54specific use case, for example VoLTE, will be migrated to proposed framework.
55Migrating all API can be implemented in other workitem(s) in future.
56
57To narrow down the scope of this spec, a full, normative definition of API and
58resources will not be considered. Only partial API will be considered. But it
59can be implemented in other workitem(s) in future.
60
61To narrow down the scope of this spec, only the functionality that Multi-Cloud
62has now will be considered and extension support will not be considered in this
63spec. But it can be implemented in other workitem(s) in future.
64
65It should be noted that, though this spec focuses on how to convert northbound
66and southboud API, it doesn't prevent tieing northbound API of MultCloud with
67other functionalities. In setion `Definition of API`, an example of API
68definition has been given, developer can add specific code/module path as a
69attribute(like `handler`) under `path`, instead of defining `vim_path`. By
70doing that, developer can tie the northbound API with specific code/module,
71and expose northbound API with any functionality. This spec just shows
72the capability of doing this by using the elastic API exposure framework, the
73implementation for now will still focus on the northbound and southboud API
74conversion.
75
76It should be noted that there is a prior art in OpenStack "Gluon" [1]_ project
Ethan Lynnb3e79cc2018-06-05 17:26:55 +080077which provides a model-driven framework to generate APIs based on model
78definitions
79in YAML. A full, normative definition and extension mechanism of "API
80Specification"
81[2]_ is available in Gluon. Although our current work has limited scope, for
82those
83who are interested in full normative definition and extension mechanism in our
84future
Hong Hui Xiao589deee2018-02-02 16:26:17 +080085work, please refer to those references in "Gluon" [1]_ project and its "API
86Specifications" [2]_.
87
88.. [1] https://wiki.openstack.org/wiki/Gluon
89.. [2] https://github.com/openstack/gluon/blob/master/doc/source/devref/gluon_api_spec.inc
90
91Since the API are defined by YAML files, swagger files can also be generated
Ethan Lynnb3e79cc2018-06-05 17:26:55 +080092from YAML files and exist without manually maintaining. The framework will
93cover the conversion from YAML file to swagger files.
Hong Hui Xiao589deee2018-02-02 16:26:17 +080094
Ethan Lynnb3e79cc2018-06-05 17:26:55 +080095To keep backward compatibility, the proposal in this spec will be bound to
96[MULTICLOUD-150]_.
Hong Hui Xiao589deee2018-02-02 16:26:17 +080097This means that the proposal is only usable when evenlet with pecan is
98enabled. So that uses don't care about this feature will not be affected.
99
100.. [MULTICLOUD-150] https://jira.onap.org/browse/MULTICLOUD-150
101
102
103Definition of API
104-----------------
105
106Take the API of `host` as example. The API will be defined as follow. URLs of
Ethan Lynnb3e79cc2018-06-05 17:26:55 +0800107the API are defined under `paths`. There are several attributes for the API.
108The number of kinds of attributes is not constrained to following example,
109other attributes can be added if needed.
Hong Hui Xiao589deee2018-02-02 16:26:17 +0800110
111::
112
113 paths:
114 /{vimid}/{tenantid}/hosts/{hostid}:
115 parameters:
116 - type: string
117 format: uuid
118 name: vimid
119 - type: string
120 format: uuid
121 name: tenantid
122 - type: string
123 format: uuid
124 name: hostid
125 get:
126 responses:
127 success_code: 200
128 description: content of host
129 schema: host
130 vim_path: {nova_endpoint}/os-hypervisors
131
132parameters
133~~~~~~~~~~
134
Ethan Lynnb3e79cc2018-06-05 17:26:55 +0800135`parameters` are the variables in the URL. It can be extracted from URL and
136then used in data retrieving and manipulating.
Hong Hui Xiao589deee2018-02-02 16:26:17 +0800137
138`parameters` are discriminated by `name`, and validated by `type` and `format`.
139
140post, put, get, delete
141~~~~~~~~~~~~~~~~~~~~~~
142
143These attributes represents the supported HTTP method. In above example, only
144`get` method is defined. When client sends other HTTP method to the URL, a 404
145response will be returned.
146
Ethan Lynnb3e79cc2018-06-05 17:26:55 +0800147`responses` defines the response of the request. `success_code` is the HTTP
148code in the response. `description` is an optional parameter. It describes the
149response.
Hong Hui Xiao589deee2018-02-02 16:26:17 +0800150`schema` points to the RESTful resource that will be in the response body. In
Ethan Lynnb3e79cc2018-06-05 17:26:55 +0800151above example, the RESTful resource is `host`. It should be found in the
152RESTful resource definition section.
Hong Hui Xiao589deee2018-02-02 16:26:17 +0800153
154vim_path
155~~~~~~~~
156
Ethan Lynnb3e79cc2018-06-05 17:26:55 +0800157`vim_path` defines the relative URL path of the southbound VIM. Multi-Cloud
158will use this path to retrieve data from VIM.
Hong Hui Xiao589deee2018-02-02 16:26:17 +0800159
160Definition of RESTful resource
161------------------------------
162
163Take the resource `host` as example. The resource will be defined as follow.
164Resources are defined under `definitions`. The are several attributes for the
165resource. The number of kinds of attributes is not constrained to following
166example, other attributes can be added if needed.
167
168::
169
170 definitions:
171 host:
172 vim_resource: hypervisor
173 properties:
174 name:
175 type: string
176 required: true
177 source: hypervisor.name
178 cpu:
179 type: integer
180 minimal: 1
181 source: hypervisor.vcpus
182 action: copy
183 required: true
184 disk_gb:
185 type: integer
186 minimal: 0
187 source: hypervisor.local_disk_size
188 required: true
189 memory_mb:
190 type: integer
191 minimal: 0
192 source: hypervisor.memory_size
193 required: true
194
195vim_resource
196~~~~~~~~~~~~
197
Ethan Lynnb3e79cc2018-06-05 17:26:55 +0800198`vim_resource` points to the resource that comes from southbound VIM.
199Multi-Cloud will use the resource to build its own resource.
Hong Hui Xiao589deee2018-02-02 16:26:17 +0800200
201properties
202~~~~~~~~~~
203
204`properties` defines the properties of the resource. Each property has a name
205and several attributes. The number of kinds of attributes is not constrained
206to the example, other attributes can be added if needed.
207
Ethan Lynnb3e79cc2018-06-05 17:26:55 +0800208`type` of property means the type of current property. It can be some simple
209data,
210like string or integer. It can also be some composite data like, object or
211array.
Hong Hui Xiao589deee2018-02-02 16:26:17 +0800212
Ethan Lynnb3e79cc2018-06-05 17:26:55 +0800213`required` of property means if this property is required for the resource. If
214it is required, missing this property will cause request failure. Default value
215of `required` is false.
Hong Hui Xiao589deee2018-02-02 16:26:17 +0800216
217`source` of property means that current property will be built from it. It is
Ethan Lynnb3e79cc2018-06-05 17:26:55 +0800218usually a property from `vim_resource`. By default, it will be the same
219property in `vim_resource`.
Hong Hui Xiao589deee2018-02-02 16:26:17 +0800220
Ethan Lynnb3e79cc2018-06-05 17:26:55 +0800221`action` of property means that current property will be build by using this
222action.
223By default, it will be `copy`, which means the data from property of VIM
224resource
Hong Hui Xiao589deee2018-02-02 16:26:17 +0800225is copied to property of Multi-Cloud resource. Other actions can be defined for
226different scenarios.
227
Ethan Lynnb3e79cc2018-06-05 17:26:55 +0800228`minimal` is one of the constraint of the property. It means the minimal
229possible
Hong Hui Xiao589deee2018-02-02 16:26:17 +0800230value of the property. If value of the property is less than minimal value. The
231request will fail.
232
233Swagger File generation
234-----------------------
235
Ethan Lynnb3e79cc2018-06-05 17:26:55 +0800236Multi-Cloud is using Swagger file to describe its API. It is maintained
237manually.
238Since this spec proposes to use YAML file to generate Multi-Cloud's API,
239Swagger
240file can also be generated from YAML file. The API generating framework will
241also
Hong Hui Xiao589deee2018-02-02 16:26:17 +0800242generate Swagger file.
243
244Implementation
245==============
246
247Work Items
248----------
249
250#. Add YAML parser for API and resource.
251#. Add REST client to call southbound VIM API.
252#. Add validator for resource.
253#. Add action for resouce.
254#. Add Swagger file generator.
255#. Migrate /{vimid}/{tenantid}/hosts/{hostid} as an example.