def instances(): apps = [] systemd = Systemd() db_apps = AppInstance.query.order_by(AppInstance.repository_id) for a in db_apps: status = a.status if status == "installed": unit = systemd.load(a.label) unit_info = unit.get_status() status = unit_info['status'] if a.repository_id: repo = Repository.query.get(a.repository_id) else: repo = Bunch() repo.label = 'Deleted repository' apps.append({ 'status': status, 'label': a.label, 'repository': repo.label, 'platform': a.platform, 'port': a.port, 'mountpoint': a.mountpoint, 'id': a.id }) return render_template('instances.html', apps=apps)
def index(): db.create_all() if not os.path.isfile('/opt/platform/platform.db') or os.path.getsize( '/opt/platform/platform.db') == 0: return redirect(url_for('setup')) if 'user' not in session: return redirect(url_for('login')) units = Systemd().list_all() platform_units = Systemd().list() return render_template('index.html', units=units, platform_units=platform_units)
def instance_detail(label): instance = AppInstance.query.filter_by(label=label).first() systemd = Systemd() unit = systemd.load(instance.label) journal = unit.get_journal() priority = { "0": "emerg", "1": "alert", "2": "crit", "3": "err", "4": "warning", "5": "notice", "6": "info", "7": "debug" } running = unit.is_running() resource_usage = unit.get_usage() return render_template('instance_detail.html', instance=instance, journal=journal, priority=priority, running=running, usage=resource_usage)
def instance_systemd_command(id, command): instance = AppInstance.query.get(id) label = instance.label unit = Systemd().load(label) unit.command(command) return redirect(url_for('instance_detail', label=label))