def delete_balancer(balancer_id): balancer = Balancer.get(balancer_id) if not balancer: abort(404) if g.user.id != balancer.user_id: return {'msg': 'forbidden'}, 403 eru.remove_containers([balancer.container_id]) balancer.delete() log = OPLog.create(g.user.id, OPLOG_ACTION.delete_balancer) log.balancer_id = balancer_id log.container_id = balancer.container_id
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}
def records(balancer_id): balancer = Balancer.get(balancer_id) if not balancer: abort(404) if request.method == 'GET': return render_template('lb/balancer.html', b=balancer) appname = request.form['appname'] domain = request.form['domain'] entrypoint = request.form['entrypoint'] r = balancer.add_record(appname, entrypoint, domain) if r: log = OPLog.create(g.user.id, OPLOG_ACTION.create_lb_record) log.balancer_id = balancer_id log.record_id = r.id log.data = {'domain': domain, 'appname': appname, 'entrypoint': entrypoint} return redirect(url_for('lb.records', balancer_id=balancer_id))
def index(): balancers = Balancer.get_by_group(g.user.group) return render_template('lb/index.html', balancers=balancers)