This commit is contained in:
TooY 2023-03-27 16:26:03 +08:00
parent 85d3ca23a1
commit 21b3995690
2 changed files with 98 additions and 64 deletions

View File

@ -39,6 +39,7 @@ def get_app_detail(app_id):
ret['message'] = 'App query failed!'
ret['data'] = None
if docker.check_app_id(app_id):
# get all info
cmd = "docker compose ls -a --format json"
output = shell_execute.execute_command_output_all(cmd)
@ -62,6 +63,8 @@ def get_app_detail(app_id):
ret['code'] = const.RETURN_SUCCESS
ret['message'] = "The app query is successful."
ret['data'] = app_info
else:
ret['message'] = "AppID is not legal!"
return ret
@ -95,6 +98,7 @@ def install_app(app_name, customer_app_name, app_version):
def start_app(app_id):
ret = Response(code=const.RETURN_FAIL, message="")
if docker.check_app_id(app_id):
app_name = split_app_id(app_id)
if if_app_exits(app_id, app_name):
docker.check_app_compose(app_name)
@ -107,12 +111,15 @@ def start_app(app_id):
ret.message = "The app failed to start!"
else:
ret.message = "The app is not installed!"
else:
ret.message = "AppID is not legal!"
ret = ret.dict()
return ret
def stop_app(app_id):
ret = Response(code=const.RETURN_FAIL, message="")
if docker.check_app_id(app_id):
app_name = split_app_id(app_id)
if if_app_exits(app_id, app_name):
cmd = "docker compose -f /data/apps/" + app_name + "/docker-compose.yml stop"
@ -124,12 +131,15 @@ def stop_app(app_id):
ret.message = "App stop failed!"
else:
ret.message = "The app is not installed!"
else:
ret.message = 'AppID is not legal!'
ret = ret.dict()
return ret
def restart_app(app_id):
ret = Response(code=const.RETURN_FAIL, message="")
if docker.check_app_id(app_id):
app_name = split_app_id(app_id)
if if_app_exits(app_id, app_name):
cmd = "docker compose -f /data/apps/" + app_name + "/docker-compose.yml restart"
@ -141,12 +151,15 @@ def restart_app(app_id):
ret.message = "App restart failed!"
else:
ret.message = "The app is not installed!"
else:
ret.message = 'AppID is not legal!'
ret = ret.dict()
return ret
def uninstall_app(app_id):
ret = Response(code=const.RETURN_FAIL, message="")
if docker.check_app_id(app_id):
if_stopped = stop_app(app_id) # stop_app
app_name = split_app_id(app_id)
real_name = app_id.split("_")[0]
@ -162,6 +175,8 @@ def uninstall_app(app_id):
ret.message = "App deletion failed!"
else:
ret.message = if_stopped["message"]
else:
ret.message = 'AppID is not legal!'
ret = ret.dict()
return ret

View File

@ -38,6 +38,25 @@ def if_app_exits(app_name):
return True
def check_app_id(app_id):
myLogger.info_logger("Checking app id ...")
if app_id == None:
myLogger.info_logger("Check complete: AppID is none!")
return False
if re.match('^[a-zA-Z0-9]+_[a-z0-9]+$', app_id) == None:
myLogger.info_logger("Check complete: AppID is not compliant")
return False
app_name = app_id.split('_')[0]
customer_name = app_id.split('_')[1]
path1 = '/data/apps/' + customer_name
path2 = '/data/library/apps/' + app_name
if not check_directory(path1) or not check_directory(path2):
myLogger.info_logger("Check complete: AppID does not exist!")
return False
myLogger.info_logger("Check complete.")
return True
def check_vm_resource(app_name):
myLogger.info_logger("Checking virtual memory resource ...")
var_path = "/data/library/apps/" + app_name + "/variables.json"