1 ################################################################################
2 # Copyright (c) 2020 AT&T Intellectual Property. #
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 #
8 # http://www.apache.org/licenses/LICENSE-2.0 #
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 ################################################################################
18 from flask import request
19 from flask_restx 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
25 log = logging.getLogger(__name__)
26 ns = api.namespace('onboard', description='onboard xApps')
30 class OnboardxApps(Resource):
32 # @api.response(200, 'Everything is fine')
33 # @api.response(500, 'temp is not ready')
36 # Return a list of xApp that have been onboarded and their versions.
38 # if not repo_manager.is_repo_ready():
39 # return {'status': 'not ready'}, 500
40 # return {'status': 'OK'}, 200
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)
48 Onboard xApp using the xApp descriptor and schema in the request body.
50 config_file = request.json.get('config-file.json')
51 controls_schema_file = request.json.get('controls-schema.json')
53 return onboard(config_file, controls_schema_file)
56 @ns.route('/download')
57 class OnboardxAppsDownload(Resource):
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)
65 Onboard xApp after downloading the xApp descriptor and schema from the URLs.
67 config_file_url = request.json.get('config-file.json_url')
68 controls_schema_url = request.json.get('controls-schema.json_url')
70 return download_config_and_schema_and_onboard(config_file_url, controls_schema_url)