def _create_container(): if session.get('login_in',None): if session.get('username',None): if request.method == 'POST': uuid = session['uuid'] username = session['username'] engine = models.Engine.query.filter_by(uuid = uuid, user_name = username).first() base_url = "tcp://" + engine.host + ":" + engine.port docker = DOCKER(base_url = base_url, timeout = 5, version = "auto") image = request.form.get('image',) name = request.form.get('name',None) hostname = request.form.get('name',None) int_port = request.form.get('int_port',None) ext_port = request.form.get('ext_port',None) int_path = request.form.get('int_path',None) ext_path = request.form.get('ext_path',None) command = request.form.get('command',None) docker.new_container(image = image, name = name, hostname = hostname, int_port = int_port, ext_port = ext_port, int_path = int_path, ext_path = ext_path, command = command ) return redirect('/container') else: return "Error 401, Authentication failed", 401 else: return redirect('/login')
def _container_detail(): if session.get('login_in',None): if session.get('username',None): uuid = session['uuid'] username = session['username'] container_id = request.values['id'] engine = models.Engine.query.filter_by(uuid = uuid, user_name = username).first() base_url = "tcp://" + engine.host + ":" + engine.port docker = DOCKER(base_url = base_url, timeout = 5, version = "auto") html = docker.get_container_detail(container_id) return jsonify(result = html) else: return "Error 401, Authentication failed", 401 else: return redirect('/login')
def _del_image(): if session.get('login_in',None): if session.get('username',None): if request.method == 'POST': uuid = session['uuid'] username = session['username'] engine = models.Engine.query.filter_by(uuid = uuid, user_name = username).first() base_url = "tcp://" + engine.host + ":" + engine.port docker = DOCKER(base_url = base_url, timeout = 5, version = "auto") repotag = request.form.get('repotag') docker.delete_image(repotag) return redirect("/image") else: return "Error 401, Authentication failed", 401 else: return redirect('/login')
def container(): if session.get('login_in',None): if session.get('username',None): try: uuid = session['uuid'] username = session['username'] engine = models.Engine.query.filter_by(uuid = uuid, user_name = username).first() base_url = "tcp://" + engine.host + ":" + engine.port docker = DOCKER(base_url = base_url, timeout = 5, version = "auto") return render_template('container.html', container_list = docker.get_containers()) except: return "操作失败,服务无法完成你的请求", 503 else: return "Error 401, Authentication failed", 401 else: return redirect('/login')
def engine(): if session.get('login_in',None): if session.get('username',None): if request.values.get('uuid',None): uuid = request.values['uuid'] session['uuid'] = uuid else: uuid = session['uuid'] username = session['username'] try: engine = models.Engine.query.filter_by(uuid = uuid, user_name = username).first() base_url = "tcp://" + engine.host + ":" + engine.port docker = DOCKER(base_url = base_url, timeout = 5, version = "auto") return render_template('engine.html', host_info = docker.get_info(), usage = docker.monitor()) except: return "操作失败,服务无法完成你的请求", 503 else: return "Error 401, Authentication failed", 401 else: return redirect('/login')
def engine(): if session.get('login_in', None): if session.get('username', None): if request.values.get('uuid', None): uuid = request.values['uuid'] session['uuid'] = uuid else: uuid = session['uuid'] username = session['username'] try: engine = models.Engine.query.filter_by( uuid=uuid, user_name=username).first() base_url = "tcp://" + engine.host + ":" + engine.port docker = DOCKER(base_url=base_url, timeout=5, version="auto") return render_template('engine.html', host_info=docker.get_info(), usage=docker.monitor()) except Exception as msg: return str(msg), 503 else: return "Error 401, Authentication failed", 401 else: return redirect('/login')
def _container_action(): if session.get('login_in',None): if session.get('username',None): uuid = session['uuid'] username = session['username'] container_id = request.values['id'] action = request.values['action'] engine = models.Engine.query.filter_by(uuid = uuid, user_name = username).first() base_url = "tcp://" + engine.host + ":" + engine.port docker = DOCKER(base_url = base_url, timeout = 10, version = "auto") try: if action == 'boot': docker.start_container(container_id) elif action == 'stop': docker.stop_container(container_id) elif action == 'reboot': docker.reboot_container(container_id) elif action == 'pause': docker.pause_container(container_id) elif action == 'unpause': docker.recover_container(container_id) elif action == 'kill': docker.kill_container(container_id) elif action == 'delete': docker.delete_container(container_id) return redirect('/container') except: return "请求超时,timeout", 408 else: return "Error 401, Authentication failed", 401 else: return redirect('/login')