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 ################################################################################
24 from xapp_onboarder.api.charts import get_charts_list, download_chart_package, download_values_yaml
25 from xapp_onboarder.repo_manager.repo_manager import repo_manager
26 from xapp_onboarder.api.onboard import onboard, download_config_and_schema_and_onboard
28 log = logging.getLogger(__name__)
32 """This is the cli tool for xapp_onboarder."""
34 def get_charts_list(self, xapp_chart_name=''):
35 """Get the list of all onboarded xApps. To show all version of an xApp, use --xapp_chart_name to
37 message, status = get_charts_list(xapp_chart_name=xapp_chart_name)
39 return json.dumps(message, indent=4, sort_keys=True)
41 def download_helm_chart(self, xapp_chart_name, version, output_path="."):
42 """Download the helm chart package of an xApp. Specify xApp name with --xapp_chart_name, version with
43 --version. Optionally use --output_path to specify the path to save the file."""
44 content, status = download_chart_package(xapp_chart_name=xapp_chart_name, version=version)
47 return json.dumps(content, indent=4, sort_keys=True)
50 if os.path.isabs(output_path):
51 path = output_path + '/' + xapp_chart_name + '-' + version + '.tgz'
53 path = os.getcwd() + '/' + output_path + '/' + xapp_chart_name + '-' + version + '.tgz'
55 if not os.path.exists(os.path.dirname(path)):
56 os.makedirs(os.path.dirname(path))
58 with open(path, 'wb') as outputfile:
59 outputfile.write(content)
60 except Exception as err:
62 return {"status": "OK"}
64 def download_values_yaml(self, xapp_chart_name, version, output_path="."):
65 """Download the values.yaml file that can be used to override parameters at runtime. Specify xApp name with
66 --xapp_chart_name, version with --version. Optionally use --output_path to specify the path to save the file.
68 content, status = download_values_yaml(xapp_chart_name=xapp_chart_name, version=version)
71 return json.dumps(content, indent=4, sort_keys=True)
74 if os.path.isabs(output_path):
75 path = output_path + '/values.yaml'
77 path = os.getcwd() + '/' + output_path + '/values.yaml'
79 if not os.path.exists(os.path.dirname(path)):
80 os.makedirs(os.path.dirname(path))
82 with open(path, 'wb') as outputfile:
83 outputfile.write(content)
84 except Exception as err:
86 return {"status": "OK"}
89 """Health check. If xapp onboarder is not ready, it return false."""
90 return repo_manager.is_repo_ready()
92 def onboard(self, config_file_path, shcema_file_path):
93 """Onboard an xApp with local descriptor files. Use --config_file_path to specify the path to
94 config-file.json file, --shcema_file_path to specify the path to schema.json file. """
96 with open(config_file_path, 'r') as inputfile:
97 config_file = json.load(inputfile)
99 with open(shcema_file_path, 'r') as inputfile:
100 schema_file = json.load(inputfile)
102 except Exception as err:
105 message, status = onboard(config_file, schema_file)
106 return json.dumps(message, indent=4, sort_keys=True)
108 def download_and_onboard(self, config_file_url, schema_file_url):
109 """Onboard an xApp with URLs pointing to the xApp descriptor files. Use --config_file_url to specify the
110 config-file.json URL, --schema_file_url to specify the schema.json URL. """
111 message, status = download_config_and_schema_and_onboard(config_file_url, schema_file_url)
112 return json.dumps(message, indent=4, sort_keys=True)
115 logger_config = pkg_resources.resource_filename("xapp_onboarder", 'logging.conf')
116 logging.config.fileConfig(logger_config)
117 fire.Fire(cli(), name='xapp_onboarder')
119 if __name__ == "__main__":