diff --git a/plugins/docker/index.py b/plugins/docker/index.py index 72c19df80..0eecf1b76 100755 --- a/plugins/docker/index.py +++ b/plugins/docker/index.py @@ -233,6 +233,44 @@ def dockerLogCon(): return mw.returnJson(False, 'Get Logs failed') +def dockerRunCon(): + # 启动容器 + args = getArgs() + data = checkArgs(args, ['Hostname']) + if not data[0]: + return data[1] + + Hostname = args['Hostname'] + c = getDClient() + try: + conFind = c.containers.get(Hostname) + if not conFind: + return mw.returnJson(False, 'The specified container does not exist!') + conFind.start() + return mw.returnJson(True, '启动成功!') + except docker.errors.APIError as ex: + return mw.returnJson(False, '启动失败!' + str(ex)) + + +def dockerStopCon(): + # 停止容器 + args = getArgs() + data = checkArgs(args, ['Hostname']) + if not data[0]: + return data[1] + + Hostname = args['Hostname'] + c = getDClient() + try: + conFind = c.containers.get(Hostname) + if not conFind: + return mw.returnJson(False, 'The specified container does not exist!') + conFind.stop() + return mw.returnJson(True, '停止成功!') + except docker.errors.APIError as ex: + return mw.returnJson(False, '停止失败!' + str(ex)) + + def imageList(): imageList = [] c = getDClient() @@ -428,6 +466,10 @@ if __name__ == "__main__": print(dockerLogCon()) elif func == 'docker_remove_con': print(dockerRemoveCon()) + elif func == 'docker_run_con': + print(dockerRunCon()) + elif func == 'docker_stop_con': + print(dockerStopCon()) elif func == 'image_list': print(imageListData()) elif func == 'docker_remove_image': diff --git a/plugins/docker/js/docker.js b/plugins/docker/js/docker.js index 2605ec956..afc90a81c 100755 --- a/plugins/docker/js/docker.js +++ b/plugins/docker/js/docker.js @@ -94,9 +94,29 @@ function deleteCon(Hostname){ }); } + +function startCon(Hostname){ + dPost('docker_run_con','',{Hostname:Hostname},function(rdata){ + var rdata = $.parseJSON(rdata.data); + layer.msg(rdata.msg,{icon:rdata.status?1:2}); + if(rdata.status) { + dockerConListRender(); + } + }); +} + +function stopCon(Hostname){ + dPost('docker_stop_con','',{Hostname:Hostname},function(rdata){ + var rdata = $.parseJSON(rdata.data); + layer.msg(rdata.msg,{icon:rdata.status?1:2}); + if(rdata.status) { + dockerConListRender(); + } + }); +} + function dockerConListRender(){ dPost('con_list', '', {}, function(rdata){ - // console.log(rdata); var rdata = $.parseJSON(rdata.data); console.log(rdata); if (!rdata.status){ @@ -109,8 +129,10 @@ function dockerConListRender(){ var rlist = rdata.data; for (var i = 0; i < rlist.length; i++) { + var docker_status = 'stop'; var status = ''; if (rlist[i]['State']['Status'] == 'running'){ + docker_status = 'start'; status = ''; } @@ -119,12 +141,17 @@ function dockerConListRender(){ op += '日志 | '; op += '删除'; - list += '