def start_container(): cid = request.form['id'] name = eru.get_container(cid)['appname'] p = Project.get_by_name(name) if not p.is_accessible(g.user): return {'reason': '你没有操作这个项目的权限'}, 403 eru.start_container(cid) log = OPLog.create(g.user.id, OPLOG_ACTION.start_container) log.container_id = cid
def stop_container(): cid = request.form['id'] name = eru.get_container(cid)['appname'] if name == APPNAME_ERU_LB: raise ValueError('Unable to stop eru-lb, do it on load balance page') p = Project.get_by_name(name) if not p.is_accessible(g.user): return {'reason': '你没有操作这个项目的权限'}, 403 eru.stop_container(cid) log = OPLog.create(g.user.id, OPLOG_ACTION.stop_container) log.container_id = cid
def _create_lb_container(pod, host): if not g.user.group: raise ValueError('you are not in a group') version = LB_IMAGE.split(':')[1] env = request.form['type'] entry = '%s-host' % env ncore = request.form.get('ncore', type=float, default=1) container_id = deploy_container(g.user.group, pod, entry, version, env, host, ncore) container = eru.get_container(container_id) b = Balancer.create(container['host'], g.user.group, g.user.id, container_id) log = OPLog.create(g.user.id, OPLOG_ACTION.create_balancer) log.container_id = container_id log.balancer_id = b.id log.data = {'host': host, 'pod': pod}