def home(): """ home page function """ listx = lxc.listx() containers_all = [] for status in ('RUNNING', 'FROZEN', 'STOPPED'): containers_by_status = [] for container in listx[status]: container_info = { 'name': container, 'settings': lwp.get_container_settings(container, status), 'memusg': 0, 'bucket': get_bucket_token(container) } containers_by_status.append(container_info) containers_all.append({ 'status': status.lower(), 'containers': containers_by_status }) return render_template('index.html', containers=lxc.ls(), containers_all=containers_all, dist=lwp.check_ubuntu(), host=socket.gethostname(), templates=lwp.get_templates_list(), storage_repos=storage_repos, auth=AUTH)
def home(): """ home page function """ listx = lxc.listx() containers_all = [] for status in ('RUNNING', 'FROZEN', 'STOPPED'): containers_by_status = [] for container in listx[status]: container_info = { 'name': container, 'settings': lwp.get_container_settings(container, status), 'memusg': 0, 'bucket': get_bucket_token(container) } containers_by_status.append(container_info) containers_all.append({ 'status': status.lower(), 'containers': containers_by_status }) return render_template('index.html', containers=lxc.ls(), containers_all=containers_all, dist=lwp.name_distro(), host=socket.gethostname(), templates=lwp.get_templates_list(), storage_repos=storage_repos, auth=AUTH)
def home(self): listx = lxc.listx() # return all containers sorted by status # memory usage is excluded in this as it slows down the homepage # quite a bit, they are retrieved later using AJAX. all_containers = [] for status in ('RUNNING', 'FROZEN', 'STOPPED'): all_containers.append({ 'status': status.lower(), 'containers': [{ 'name': container, 'memory_usage': 0, # I prefer to cache this one day 'settings': get_container_settings(container), 'bucket': get_bucket_token(container) } for container in listx[status]] }) return { 'all_containers': all_containers, 'dist': check_ubuntu(), 'host': socket.gethostname(), 'templates': get_templates_list(), 'storage_repos': self.settings['storage_repos'], 'auth': self.settings['auth.backend'] }
def home(): """ home page function """ listx = lxc.listx() containers_all = [] for status in ("RUNNING", "FROZEN", "STOPPED"): containers_by_status = [] for container in listx[status]: container_info = { "name": container, "settings": lwp.get_container_settings(container, status), "memusg": 0, "bucket": get_bucket_token(container), } containers_by_status.append(container_info) containers_all.append({"status": status.lower(), "containers": containers_by_status}) clonable_containers = listx["STOPPED"] return render_template( "index.html", containers=lxc.ls(), containers_all=containers_all, dist=lwp.name_distro(), host=socket.gethostname(), templates=lwp.get_templates_list(), storage_repos=storage_repos, auth=AUTH, clonable_containers=clonable_containers, )
def edit(container=None): """ edit containers page and actions if form post request """ host_memory = lwp.host_memory_usage() cfg = lwp.get_container_settings(container) if request.method == "POST": form = request.form.copy() if form["bucket"] != get_bucket_token(container): g.db.execute("INSERT INTO machine(machine_name, bucket_token) VALUES (?, ?)", [container, form["bucket"]]) g.db.commit() flash(u"Bucket config for %s saved" % container, "success") # convert boolean in correct value for lxc, if checkbox is inset value is not submitted inside POST form["flags"] = "up" if "flags" in form else "down" form["start_auto"] = "1" if "start_auto" in form else "0" # if memlimits/memswlimit is at max values unset form values if int(form["memlimit"]) == host_memory["total"]: form["memlimit"] = "" if int(form["swlimit"]) == host_memory["total"] * 2: form["swlimit"] = "" for option in form.keys(): # if the key is supported AND is different if option in cfg.keys() and form[option] != cfg[option]: # validate value with regex if re.match(cgroup_ext[option][1], form[option]): lwp.push_config_value(cgroup_ext[option][0], form[option], container=container) flash(cgroup_ext[option][2], "success") else: flash("Cannot validate value for option {}. Unsaved!".format(option), "error") # we should re-read container configuration now to be coherent with the newly saved values cfg = lwp.get_container_settings(container) info = lxc.info(container) infos = {"status": info["state"], "pid": info["pid"], "memusg": lwp.memory_usage(container)} # prepare a regex dict from cgroups_ext definition regex = {} for k, v in cgroup_ext.items(): regex[k] = v[1] return render_template( "edit.html", containers=lxc.ls(), container=container, infos=infos, settings=cfg, host_memory=host_memory, storage_repos=storage_repos, regex=regex, clonable_containers=lxc.listx()["STOPPED"], )
def edit(container=None): """ edit containers page and actions if form post request """ host_memory = lwp.host_memory_usage() cfg = lwp.get_container_settings(container) if request.method == 'POST': form = request.form.copy() if form['bucket'] != get_bucket_token(container): g.db.execute("INSERT INTO machine(machine_name, bucket_token) VALUES (?, ?)", [container, form['bucket']]) g.db.commit() flash(u'Bucket config for %s saved' % container, 'success') # convert boolean in correct value for lxc, if checkbox is inset value is not submitted inside POST form['flags'] = 'up' if 'flags' in form else 'down' form['start_auto'] = '1' if 'start_auto' in form else '0' # if memlimits/memswlimit is at max values unset form values if int(form['memlimit']) == host_memory['total']: form['memlimit'] = '' if int(form['swlimit']) == host_memory['total'] * 2: form['swlimit'] = '' for option in form.keys(): # if the key is supported AND is different if option in cfg.keys() and form[option] != cfg[option]: # validate value with regex if re.match(cgroup_ext[option][1], form[option]): lwp.push_config_value(cgroup_ext[option][0], form[option], container=container) flash(cgroup_ext[option][2], 'success') else: flash('Cannot validate value for option {}. Unsaved!'.format(option), 'error') # we should re-read container configuration now to be coherent with the newly saved values cfg = lwp.get_container_settings(container) info = lxc.info(container) infos = {'status': info['state'], 'pid': info['pid'], 'memusg': lwp.memory_usage(container)} # prepare a regex dict from cgroups_ext definition regex = {} for k, v in cgroup_ext.items(): regex[k] = v[1] return render_template('edit.html', containers=lxc.ls(), container=container, infos=infos, settings=cfg, host_memory=host_memory, storage_repos=storage_repos, regex=regex, clonable_containers=lxc.listx()['STOPPED'])