Removing committers
[ric-plt/appmgr.git] / xapp_orchestrater / dev / xapp_onboarder / xapp_onboarder / api / endpoints / onboard_ep.py
1 ################################################################################
2 #   Copyright (c) 2020 AT&T Intellectual Property.                             #
3 #                                                                              #
4 #   Licensed under the Apache License, Version 2.0 (the "License");            #
5 #   you may not use this file except in compliance with the License.           #
6 #   You may obtain a copy of the License at                                    #
7 #                                                                              #
8 #       http://www.apache.org/licenses/LICENSE-2.0                             #
9 #                                                                              #
10 #   Unless required by applicable law or agreed to in writing, software        #
11 #   distributed under the License is distributed on an "AS IS" BASIS,          #
12 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   #
13 #   See the License for the specific language governing permissions and        #
14 #   limitations under the License.                                             #
15 ################################################################################
16
17 import logging
18 from flask import request
19 from flask_restplus import Resource
20 from xapp_onboarder.api.models import request_models
21 from xapp_onboarder.api.api_reference import api
22 from xapp_onboarder.api.models.response_models import status_message_model, error_message_model
23 from xapp_onboarder.api.onboard import onboard, download_config_and_schema_and_onboard
24
25 log = logging.getLogger(__name__)
26 ns = api.namespace('onboard', description='onboard xApps')
27
28
29 @ns.route('')
30 class OnboardxApps(Resource):
31
32     # @api.response(200, 'Everything is fine')
33     # @api.response(500, 'temp is not ready')
34     # def get(self):
35     #     """
36     #     Return a list of xApp that have been onboarded and their versions.
37     #     """
38     #     if not repo_manager.is_repo_ready():
39     #         return {'status': 'not ready'}, 500
40     #     return {'status': 'OK'}, 200
41
42     @api.response(201, 'xApp onboard successfully.', status_message_model)
43     @api.response(400, 'xApp descriptor format error', error_message_model)
44     @api.response(500, 'xApp onboarder is not ready', error_message_model)
45     @api.expect(request_models.xapp_descriptor_post, validate=True)
46     def post(self):
47         """
48         Onboard xApp using the xApp descriptor and schema in the request body.
49         """
50         config_file = request.json.get('config-file.json')
51         controls_schema_file = request.json.get('controls-schema.json')
52
53         return onboard(config_file, controls_schema_file)
54
55
56 @ns.route('/download')
57 class OnboardxAppsDownload(Resource):
58
59     @api.response(201, 'xApp onboard successfully.', status_message_model)
60     @api.response(400, 'xApp descriptor format error', error_message_model)
61     @api.response(500, 'xApp onboarder is not ready', error_message_model)
62     @api.expect(request_models.xapp_descriptor_download_post, validate=True)
63     def post(self):
64         """
65         Onboard xApp after downloading the xApp descriptor and schema from the URLs.
66         """
67         config_file_url = request.json.get('config-file.json_url')
68         controls_schema_url = request.json.get('controls-schema.json_url')
69
70         return download_config_and_schema_and_onboard(config_file_url, controls_schema_url)