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 ################################################################################
20 from xapp_onboarder.repo_manager.repo_manager import repo_manager, RepoManagerError
21 from xapp_onboarder.api.models.response_models import error_message_model, response
23 log = logging.getLogger(__name__)
26 def get_charts_list(xapp_chart_name=None):
28 if not repo_manager.is_repo_ready():
29 response_message = response(model=error_message_model, status_code=500,
30 error_source="xapp_onboarder",
31 error_message="Cannot connect to local helm repo.",
32 status="Service not ready.")
33 return response_message.get_return()
36 content = repo_manager.get_xapp_list(xapp_chart_name=xapp_chart_name)
37 except RepoManagerError as err:
39 response_message = response(model=error_message_model, status_code=err.status_code,
40 error_source="charts_fetcher",
41 error_message=str(err),
42 status="Fetching helm chart list failed")
43 return response_message.get_return()
47 def download_chart_package(xapp_chart_name, version):
49 if not repo_manager.is_repo_ready():
50 response_message = response(model=error_message_model, status_code=500,
51 error_source="xapp_onboarder",
52 error_message="Cannot connect to local helm repo.",
53 status="Service not ready.")
54 return response_message.get_return()
56 content = repo_manager.download_xapp_chart(xapp_chart_name=xapp_chart_name, version=version)
57 except RepoManagerError as err:
59 response_message = response(model=error_message_model, status_code=err.status_code,
60 error_source="charts_fetcher",
61 error_message=str(err),
62 status="Downloading helm chart package failed")
63 return response_message.get_return()
67 def download_values_yaml(xapp_chart_name, version):
69 content, status = download_chart_package(xapp_chart_name=xapp_chart_name, version=version)
72 return content, status
74 file_stream = io.BytesIO(content)
76 with tarfile.open(fileobj=file_stream) as tar:
77 values_yaml_file = tar.extractfile(xapp_chart_name + '/values.yaml')
78 return_response = values_yaml_file.read()
80 return return_response, 200