raise xAppError( "xApp " + self.chart_name + '-' + self.chart_version + " distribution failed. (Caused by: " + str(err) + ")" , err.status_code)
def install_chart_package(xapp_chart_name, version, namespace, overridefile):
+ dirTomove = "/tmp/helm_template"
try:
tar = tarfile.open(xapp_chart_name + "-" + version + ".tgz")
tar.extractall()
except Exception as err:
print(err)
status = 0
- subprocess.run(["rm", "-rf", xapp_chart_name ])
- subprocess.run(["rm", "-rf", xapp_chart_name + "-" + version + ".tgz" ])
+ if (os.getcwd() != dirTomove):
+ subprocess.run(["mv", xapp_chart_name, dirTomove])
+ PATH=xapp_chart_name + "-" + version + ".tgz"
+ if os.path.isfile(PATH):
+ subprocess.run(["mv", xapp_chart_name + "-" + version + ".tgz", dirTomove ])
return status
- def uninstall_chart_package(xapp_chart_name, namespace):
-
+ def uninstall_chart_package(xapp_chart_name, namespace, version):
+ dirTomove = "/tmp/helm_template/"
try:
+ subprocess.run(["rm", "-rf", dirTomove + xapp_chart_name])
+ if version != "" :
+ subprocess.run(["rm", "-rf", dirTomove+xapp_chart_name + "-" + version + ".tgz"])
process = subprocess.run(["helm", "delete", xapp_chart_name, "--namespace=" + namespace], stdout=PIPE, stderr=PIPE, check=True)
status = 1
content, status = download_chart_package(xapp_chart_name=xapp_chart_name, version=version)
if status != 200:
- return json.dumps(content, indent=4, sort_keys=True)
-
+ #return json.dumps(content, indent=4, sort_keys=True)
+ return {"status": "NOT_OK"}
try:
if os.path.isabs(output_path):
path = output_path + '/' + xapp_chart_name + '-' + version + '.tgz'
"""Installing the xapp using the charts name and version,optionally can provide the yaml file to override"""
resp = self.download_helm_chart(xapp_chart_name, version)
+ if resp['status'] == "NOT_OK":
+ return {"status": "Not OK"}
status = xApp.install_chart_package(xapp_chart_name=xapp_chart_name, version=version, namespace=namespace,overridefile=overridefile)
if status == 1:
return {"status": "OK"}
else:
return {"status": "NOT_OK"}
- def uninstall(self, xapp_chart_name ,namespace):
- """Uninstalling the xapp using the charts name"""
- status = xApp.uninstall_chart_package(xapp_chart_name=xapp_chart_name, namespace=namespace)
+ def uninstall(self, xapp_chart_name, namespace, version=""):
+ """Uninstalling the xapp using the charts name, --version can be provided optionally"""
+ status = xApp.uninstall_chart_package(xapp_chart_name=xapp_chart_name, namespace=namespace, version=version)
if status == 1:
return {"status": "OK"}
else:
def upgrade(self, xapp_chart_name, old_version , new_version, namespace):
"""Upgrading the xapp to the new version specified"""
- resp = self.uninstall(xapp_chart_name, namespace)
+ resp = self.uninstall(xapp_chart_name, namespace,old_version)
if resp["status"] == "OK":
status = self.install(xapp_chart_name, new_version, namespace)
if status["status"] == "OK":
return {"status": "OK"}
else:
- self.uninstall(xapp_chart_name, namespace)
+ self.uninstall(xapp_chart_name, namespace,new_version)
self.install(xapp_chart_name, old_version, namespace)
return {"status": "NOT_OK"}
else: