mirror of
https://github.com/Websoft9/websoft9.git
synced 2025-01-24 18:30:23 +08:00
update
This commit is contained in:
parent
85d3ca23a1
commit
21b3995690
@ -39,6 +39,7 @@ def get_app_detail(app_id):
|
|||||||
ret['message'] = 'App query failed!'
|
ret['message'] = 'App query failed!'
|
||||||
ret['data'] = None
|
ret['data'] = None
|
||||||
|
|
||||||
|
if docker.check_app_id(app_id):
|
||||||
# get all info
|
# get all info
|
||||||
cmd = "docker compose ls -a --format json"
|
cmd = "docker compose ls -a --format json"
|
||||||
output = shell_execute.execute_command_output_all(cmd)
|
output = shell_execute.execute_command_output_all(cmd)
|
||||||
@ -62,6 +63,8 @@ def get_app_detail(app_id):
|
|||||||
ret['code'] = const.RETURN_SUCCESS
|
ret['code'] = const.RETURN_SUCCESS
|
||||||
ret['message'] = "The app query is successful."
|
ret['message'] = "The app query is successful."
|
||||||
ret['data'] = app_info
|
ret['data'] = app_info
|
||||||
|
else:
|
||||||
|
ret['message'] = "AppID is not legal!"
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
@ -95,6 +98,7 @@ def install_app(app_name, customer_app_name, app_version):
|
|||||||
|
|
||||||
def start_app(app_id):
|
def start_app(app_id):
|
||||||
ret = Response(code=const.RETURN_FAIL, message="")
|
ret = Response(code=const.RETURN_FAIL, message="")
|
||||||
|
if docker.check_app_id(app_id):
|
||||||
app_name = split_app_id(app_id)
|
app_name = split_app_id(app_id)
|
||||||
if if_app_exits(app_id, app_name):
|
if if_app_exits(app_id, app_name):
|
||||||
docker.check_app_compose(app_name)
|
docker.check_app_compose(app_name)
|
||||||
@ -107,12 +111,15 @@ def start_app(app_id):
|
|||||||
ret.message = "The app failed to start!"
|
ret.message = "The app failed to start!"
|
||||||
else:
|
else:
|
||||||
ret.message = "The app is not installed!"
|
ret.message = "The app is not installed!"
|
||||||
|
else:
|
||||||
|
ret.message = "AppID is not legal!"
|
||||||
ret = ret.dict()
|
ret = ret.dict()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def stop_app(app_id):
|
def stop_app(app_id):
|
||||||
ret = Response(code=const.RETURN_FAIL, message="")
|
ret = Response(code=const.RETURN_FAIL, message="")
|
||||||
|
if docker.check_app_id(app_id):
|
||||||
app_name = split_app_id(app_id)
|
app_name = split_app_id(app_id)
|
||||||
if if_app_exits(app_id, app_name):
|
if if_app_exits(app_id, app_name):
|
||||||
cmd = "docker compose -f /data/apps/" + app_name + "/docker-compose.yml stop"
|
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!"
|
ret.message = "App stop failed!"
|
||||||
else:
|
else:
|
||||||
ret.message = "The app is not installed!"
|
ret.message = "The app is not installed!"
|
||||||
|
else:
|
||||||
|
ret.message = 'AppID is not legal!'
|
||||||
ret = ret.dict()
|
ret = ret.dict()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def restart_app(app_id):
|
def restart_app(app_id):
|
||||||
ret = Response(code=const.RETURN_FAIL, message="")
|
ret = Response(code=const.RETURN_FAIL, message="")
|
||||||
|
if docker.check_app_id(app_id):
|
||||||
app_name = split_app_id(app_id)
|
app_name = split_app_id(app_id)
|
||||||
if if_app_exits(app_id, app_name):
|
if if_app_exits(app_id, app_name):
|
||||||
cmd = "docker compose -f /data/apps/" + app_name + "/docker-compose.yml restart"
|
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!"
|
ret.message = "App restart failed!"
|
||||||
else:
|
else:
|
||||||
ret.message = "The app is not installed!"
|
ret.message = "The app is not installed!"
|
||||||
|
else:
|
||||||
|
ret.message = 'AppID is not legal!'
|
||||||
ret = ret.dict()
|
ret = ret.dict()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def uninstall_app(app_id):
|
def uninstall_app(app_id):
|
||||||
ret = Response(code=const.RETURN_FAIL, message="")
|
ret = Response(code=const.RETURN_FAIL, message="")
|
||||||
|
if docker.check_app_id(app_id):
|
||||||
if_stopped = stop_app(app_id) # stop_app
|
if_stopped = stop_app(app_id) # stop_app
|
||||||
app_name = split_app_id(app_id)
|
app_name = split_app_id(app_id)
|
||||||
real_name = app_id.split("_")[0]
|
real_name = app_id.split("_")[0]
|
||||||
@ -162,6 +175,8 @@ def uninstall_app(app_id):
|
|||||||
ret.message = "App deletion failed!"
|
ret.message = "App deletion failed!"
|
||||||
else:
|
else:
|
||||||
ret.message = if_stopped["message"]
|
ret.message = if_stopped["message"]
|
||||||
|
else:
|
||||||
|
ret.message = 'AppID is not legal!'
|
||||||
ret = ret.dict()
|
ret = ret.dict()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
@ -38,6 +38,25 @@ def if_app_exits(app_name):
|
|||||||
return True
|
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):
|
def check_vm_resource(app_name):
|
||||||
myLogger.info_logger("Checking virtual memory resource ...")
|
myLogger.info_logger("Checking virtual memory resource ...")
|
||||||
var_path = "/data/library/apps/" + app_name + "/variables.json"
|
var_path = "/data/library/apps/" + app_name + "/variables.json"
|
||||||
|
Loading…
Reference in New Issue
Block a user