From 6fdcc52787d13834abb6b3ea259270ed3234a416 Mon Sep 17 00:00:00 2001 From: FELD Boris Date: Thu, 17 Dec 2015 11:52:39 +0100 Subject: [PATCH 01/22] Get rid of the old code --- _requirements.txt | 7 - examples/Vagrantfile.template | 31 - examples/minions_configurations/minimum | 2 - examples/minions_configurations/sample_grains | 10 - requirements.txt | 2 - run.py | 15 - saltpad/__init__.py | 6 - saltpad/_returners/mongo_saltpad_return.py | 154 - saltpad/app.py | 453 -- saltpad/core.py | 227 - saltpad/default_settings.py | 7 - saltpad/local_settings.sample.py | 20 - saltpad/settings.py | 6 - saltpad/static/css/bootstrap.css | 7118 ----------------- saltpad/static/css/dataTables.bootstrap.css | 312 - saltpad/static/css/jsontree.css | 65 - saltpad/static/css/saltpad.css | 52 - saltpad/static/css/sb-admin.css | 224 - .../static/font-awesome/css/font-awesome.css | 1672 ---- .../font-awesome/css/font-awesome.min.css | 4 - .../static/font-awesome/fonts/FontAwesome.otf | Bin 85908 -> 0 bytes .../fonts/fontawesome-webfont.eot | Bin 56006 -> 0 bytes .../fonts/fontawesome-webfont.svg | 520 -- .../fonts/fontawesome-webfont.ttf | Bin 112160 -> 0 bytes .../fonts/fontawesome-webfont.woff | Bin 65452 -> 0 bytes .../font-awesome/less/bordered-pulled.less | 16 - saltpad/static/font-awesome/less/core.less | 11 - .../static/font-awesome/less/fixed-width.less | 6 - .../font-awesome/less/font-awesome.less | 17 - saltpad/static/font-awesome/less/icons.less | 552 -- saltpad/static/font-awesome/less/larger.less | 13 - saltpad/static/font-awesome/less/list.less | 19 - saltpad/static/font-awesome/less/mixins.less | 25 - saltpad/static/font-awesome/less/path.less | 14 - .../font-awesome/less/rotated-flipped.less | 20 - .../static/font-awesome/less/spinning.less | 29 - saltpad/static/font-awesome/less/stacked.less | 20 - .../static/font-awesome/less/variables.less | 561 -- .../font-awesome/scss/_bordered-pulled.scss | 16 - saltpad/static/font-awesome/scss/_core.scss | 11 - .../font-awesome/scss/_fixed-width.scss | 6 - saltpad/static/font-awesome/scss/_icons.scss | 552 -- saltpad/static/font-awesome/scss/_larger.scss | 13 - saltpad/static/font-awesome/scss/_list.scss | 19 - saltpad/static/font-awesome/scss/_mixins.scss | 25 - saltpad/static/font-awesome/scss/_path.scss | 14 - .../font-awesome/scss/_rotated-flipped.scss | 20 - .../static/font-awesome/scss/_spinning.scss | 29 - .../static/font-awesome/scss/_stacked.scss | 20 - .../static/font-awesome/scss/_variables.scss | 561 -- .../font-awesome/scss/font-awesome.scss | 17 - saltpad/static/images/Sorting icons.psd | Bin 27490 -> 0 bytes saltpad/static/images/back_disabled.png | Bin 1361 -> 0 bytes saltpad/static/images/back_enabled.png | Bin 1379 -> 0 bytes saltpad/static/images/back_enabled_hover.png | Bin 1375 -> 0 bytes saltpad/static/images/favicon.ico | Bin 894 -> 0 bytes saltpad/static/images/forward_disabled.png | Bin 1363 -> 0 bytes saltpad/static/images/forward_enabled.png | Bin 1380 -> 0 bytes .../static/images/forward_enabled_hover.png | Bin 1379 -> 0 bytes saltpad/static/images/sort_asc.png | Bin 1118 -> 0 bytes saltpad/static/images/sort_asc_disabled.png | Bin 2916 -> 0 bytes saltpad/static/images/sort_both.png | Bin 1136 -> 0 bytes saltpad/static/images/sort_desc.png | Bin 1127 -> 0 bytes saltpad/static/images/sort_desc_disabled.png | Bin 1045 -> 0 bytes saltpad/static/js/bootstrap.js | 2006 ----- saltpad/static/js/dataTables.bootstrap.js | 186 - saltpad/static/js/flot/chart-data-flot.js | 237 - saltpad/static/js/flot/excanvas.min.js | 1 - saltpad/static/js/flot/jquery.flot.js | 2599 ------ saltpad/static/js/flot/jquery.flot.pie.js | 750 -- saltpad/static/js/flot/jquery.flot.resize.js | 60 - .../static/js/flot/jquery.flot.tooltip.min.js | 12 - saltpad/static/js/jquery-1.10.2.js | 6 - saltpad/static/js/jquery.dataTables.min.js | 157 - saltpad/static/js/jsontree.js | 135 - saltpad/static/js/morris/chart-data-morris.js | 128 - .../js/tablesorter/jquery.tablesorter.js | 1031 --- saltpad/static/js/tablesorter/tables.js | 3 - saltpad/templates/add_template.html | 180 - saltpad/templates/base.html | 47 - saltpad/templates/base_logged.html | 130 - saltpad/templates/dashboard.html | 259 - saltpad/templates/debug.html | 58 - saltpad/templates/debug_minion.html | 35 - saltpad/templates/job_result.html | 52 - saltpad/templates/job_result_aggregate.html | 49 - saltpad/templates/job_result_highstate.html | 120 - saltpad/templates/job_result_raw.html | 60 - saltpad/templates/jobs.html | 68 - saltpad/templates/login.html | 49 - saltpad/templates/macros.jinja | 103 - saltpad/templates/minion_details.html | 71 - saltpad/templates/minions.html | 77 - saltpad/templates/minions_deployments.html | 77 - saltpad/templates/minions_keys.html | 70 - saltpad/templates/run.html | 178 - saltpad/templates/templates.html | 63 - saltpad/templates/wip.html | 17 - saltpad/utils.py | 287 - screenshots/dashboard.png | Bin 62405 -> 0 bytes screenshots/debug.png | Bin 28574 -> 0 bytes screenshots/debug_grains.png | Bin 68314 -> 0 bytes screenshots/debug_highstate.png | Bin 52113 -> 0 bytes screenshots/debug_pillar.png | Bin 39505 -> 0 bytes screenshots/debug_state.png | Bin 36708 -> 0 bytes screenshots/deployments_filtered.png | Bin 79463 -> 0 bytes .../highstate_output_changes_details.png | Bin 72239 -> 0 bytes .../highstate_output_errors_details.png | Bin 52592 -> 0 bytes .../highstate_output_success_details.png | Bin 72575 -> 0 bytes screenshots/highstate_result.png | Bin 68233 -> 0 bytes screenshots/job_history.png | Bin 75418 -> 0 bytes screenshots/job_history_filtered.png | Bin 90193 -> 0 bytes screenshots/job_result_aggregate.png | Bin 43458 -> 0 bytes screenshots/job_result_raw.png | Bin 55704 -> 0 bytes screenshots/job_result_raw_details.png | Bin 49077 -> 0 bytes screenshots/job_result_redone.png | Bin 58306 -> 0 bytes screenshots/login.png | Bin 12492 -> 0 bytes screenshots/minion_details.png | Bin 71703 -> 0 bytes screenshots/minion_keys.png | Bin 79968 -> 0 bytes screenshots/minion_keys_pending.png | Bin 72409 -> 0 bytes screenshots/minions.png | Bin 79539 -> 0 bytes screenshots/minions_filtered.png | Bin 47660 -> 0 bytes screenshots/run.png | Bin 22810 -> 0 bytes screenshots/run_1.png | Bin 60943 -> 0 bytes screenshots/run_2.png | Bin 54423 -> 0 bytes screenshots/run_3.png | Bin 53961 -> 0 bytes screenshots/run_4.png | Bin 35678 -> 0 bytes screenshots/template_add.png | Bin 69950 -> 0 bytes screenshots/template_added.png | Bin 78429 -> 0 bytes screenshots/template_list.png | Bin 70711 -> 0 bytes screenshots/template_runned.png | Bin 54486 -> 0 bytes setup.cfg | 2 - setup.py | 57 - tox.ini | 8 - windows-requirements.txt | 2 - 135 files changed, 22943 deletions(-) delete mode 100644 _requirements.txt delete mode 100644 examples/Vagrantfile.template delete mode 100644 examples/minions_configurations/minimum delete mode 100644 examples/minions_configurations/sample_grains delete mode 100644 requirements.txt delete mode 100644 run.py delete mode 100644 saltpad/__init__.py delete mode 100644 saltpad/_returners/mongo_saltpad_return.py delete mode 100644 saltpad/app.py delete mode 100644 saltpad/core.py delete mode 100644 saltpad/default_settings.py delete mode 100644 saltpad/local_settings.sample.py delete mode 100644 saltpad/settings.py delete mode 100644 saltpad/static/css/bootstrap.css delete mode 100644 saltpad/static/css/dataTables.bootstrap.css delete mode 100644 saltpad/static/css/jsontree.css delete mode 100644 saltpad/static/css/saltpad.css delete mode 100644 saltpad/static/css/sb-admin.css delete mode 100644 saltpad/static/font-awesome/css/font-awesome.css delete mode 100644 saltpad/static/font-awesome/css/font-awesome.min.css delete mode 100644 saltpad/static/font-awesome/fonts/FontAwesome.otf delete mode 100644 saltpad/static/font-awesome/fonts/fontawesome-webfont.eot delete mode 100644 saltpad/static/font-awesome/fonts/fontawesome-webfont.svg delete mode 100644 saltpad/static/font-awesome/fonts/fontawesome-webfont.ttf delete mode 100644 saltpad/static/font-awesome/fonts/fontawesome-webfont.woff delete mode 100644 saltpad/static/font-awesome/less/bordered-pulled.less delete mode 100644 saltpad/static/font-awesome/less/core.less delete mode 100644 saltpad/static/font-awesome/less/fixed-width.less delete mode 100644 saltpad/static/font-awesome/less/font-awesome.less delete mode 100644 saltpad/static/font-awesome/less/icons.less delete mode 100644 saltpad/static/font-awesome/less/larger.less delete mode 100644 saltpad/static/font-awesome/less/list.less delete mode 100644 saltpad/static/font-awesome/less/mixins.less delete mode 100644 saltpad/static/font-awesome/less/path.less delete mode 100644 saltpad/static/font-awesome/less/rotated-flipped.less delete mode 100644 saltpad/static/font-awesome/less/spinning.less delete mode 100644 saltpad/static/font-awesome/less/stacked.less delete mode 100644 saltpad/static/font-awesome/less/variables.less delete mode 100644 saltpad/static/font-awesome/scss/_bordered-pulled.scss delete mode 100644 saltpad/static/font-awesome/scss/_core.scss delete mode 100644 saltpad/static/font-awesome/scss/_fixed-width.scss delete mode 100644 saltpad/static/font-awesome/scss/_icons.scss delete mode 100644 saltpad/static/font-awesome/scss/_larger.scss delete mode 100644 saltpad/static/font-awesome/scss/_list.scss delete mode 100644 saltpad/static/font-awesome/scss/_mixins.scss delete mode 100644 saltpad/static/font-awesome/scss/_path.scss delete mode 100644 saltpad/static/font-awesome/scss/_rotated-flipped.scss delete mode 100644 saltpad/static/font-awesome/scss/_spinning.scss delete mode 100644 saltpad/static/font-awesome/scss/_stacked.scss delete mode 100644 saltpad/static/font-awesome/scss/_variables.scss delete mode 100644 saltpad/static/font-awesome/scss/font-awesome.scss delete mode 100644 saltpad/static/images/Sorting icons.psd delete mode 100644 saltpad/static/images/back_disabled.png delete mode 100644 saltpad/static/images/back_enabled.png delete mode 100644 saltpad/static/images/back_enabled_hover.png delete mode 100644 saltpad/static/images/favicon.ico delete mode 100644 saltpad/static/images/forward_disabled.png delete mode 100644 saltpad/static/images/forward_enabled.png delete mode 100644 saltpad/static/images/forward_enabled_hover.png delete mode 100644 saltpad/static/images/sort_asc.png delete mode 100644 saltpad/static/images/sort_asc_disabled.png delete mode 100644 saltpad/static/images/sort_both.png delete mode 100644 saltpad/static/images/sort_desc.png delete mode 100644 saltpad/static/images/sort_desc_disabled.png delete mode 100644 saltpad/static/js/bootstrap.js delete mode 100644 saltpad/static/js/dataTables.bootstrap.js delete mode 100644 saltpad/static/js/flot/chart-data-flot.js delete mode 100644 saltpad/static/js/flot/excanvas.min.js delete mode 100644 saltpad/static/js/flot/jquery.flot.js delete mode 100644 saltpad/static/js/flot/jquery.flot.pie.js delete mode 100644 saltpad/static/js/flot/jquery.flot.resize.js delete mode 100644 saltpad/static/js/flot/jquery.flot.tooltip.min.js delete mode 100644 saltpad/static/js/jquery-1.10.2.js delete mode 100644 saltpad/static/js/jquery.dataTables.min.js delete mode 100644 saltpad/static/js/jsontree.js delete mode 100644 saltpad/static/js/morris/chart-data-morris.js delete mode 100644 saltpad/static/js/tablesorter/jquery.tablesorter.js delete mode 100644 saltpad/static/js/tablesorter/tables.js delete mode 100644 saltpad/templates/add_template.html delete mode 100644 saltpad/templates/base.html delete mode 100644 saltpad/templates/base_logged.html delete mode 100644 saltpad/templates/dashboard.html delete mode 100644 saltpad/templates/debug.html delete mode 100644 saltpad/templates/debug_minion.html delete mode 100644 saltpad/templates/job_result.html delete mode 100644 saltpad/templates/job_result_aggregate.html delete mode 100644 saltpad/templates/job_result_highstate.html delete mode 100644 saltpad/templates/job_result_raw.html delete mode 100644 saltpad/templates/jobs.html delete mode 100644 saltpad/templates/login.html delete mode 100644 saltpad/templates/macros.jinja delete mode 100644 saltpad/templates/minion_details.html delete mode 100644 saltpad/templates/minions.html delete mode 100644 saltpad/templates/minions_deployments.html delete mode 100644 saltpad/templates/minions_keys.html delete mode 100644 saltpad/templates/run.html delete mode 100644 saltpad/templates/templates.html delete mode 100644 saltpad/templates/wip.html delete mode 100644 saltpad/utils.py delete mode 100644 screenshots/dashboard.png delete mode 100644 screenshots/debug.png delete mode 100644 screenshots/debug_grains.png delete mode 100644 screenshots/debug_highstate.png delete mode 100644 screenshots/debug_pillar.png delete mode 100644 screenshots/debug_state.png delete mode 100644 screenshots/deployments_filtered.png delete mode 100644 screenshots/highstate_output_changes_details.png delete mode 100644 screenshots/highstate_output_errors_details.png delete mode 100644 screenshots/highstate_output_success_details.png delete mode 100644 screenshots/highstate_result.png delete mode 100644 screenshots/job_history.png delete mode 100644 screenshots/job_history_filtered.png delete mode 100644 screenshots/job_result_aggregate.png delete mode 100644 screenshots/job_result_raw.png delete mode 100644 screenshots/job_result_raw_details.png delete mode 100644 screenshots/job_result_redone.png delete mode 100644 screenshots/login.png delete mode 100644 screenshots/minion_details.png delete mode 100644 screenshots/minion_keys.png delete mode 100644 screenshots/minion_keys_pending.png delete mode 100644 screenshots/minions.png delete mode 100644 screenshots/minions_filtered.png delete mode 100644 screenshots/run.png delete mode 100644 screenshots/run_1.png delete mode 100644 screenshots/run_2.png delete mode 100644 screenshots/run_3.png delete mode 100644 screenshots/run_4.png delete mode 100644 screenshots/template_add.png delete mode 100644 screenshots/template_added.png delete mode 100644 screenshots/template_list.png delete mode 100644 screenshots/template_runned.png delete mode 100644 setup.cfg delete mode 100644 setup.py delete mode 100644 tox.ini delete mode 100644 windows-requirements.txt diff --git a/_requirements.txt b/_requirements.txt deleted file mode 100644 index a8afaee..0000000 --- a/_requirements.txt +++ /dev/null @@ -1,7 +0,0 @@ -wheel==0.22.0 -jinja2 -flask -flask-wtf -requests -pymongo -six diff --git a/examples/Vagrantfile.template b/examples/Vagrantfile.template deleted file mode 100644 index 57504c4..0000000 --- a/examples/Vagrantfile.template +++ /dev/null @@ -1,31 +0,0 @@ -## This Vagrantfile is ready for Vagrant v1.2.2 - -Vagrant.configure("2") do |config| - config.vm.box = "ubuntu_13.04_cloud" - config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/raring/current/raring-server-cloudimg-amd64-vagrant-disk1.box" - - # Create a private network, which allows host-only access to the machine - # using a specific IP. - config.vm.network :private_network, ip: "33.33.33.10" - - config.vm.hostname = "{{project_name}}" - - config.vm.provider :virtualbox do |vb| - # Use VBoxManage to customize the VM. For example to change memory: - vb.customize ["modifyvm", :id, "--memory", "{{ram}}"] - vb.customize ["modifyvm", :id, "--cpus", "{{cpus}}"] - vb.customize ["modifyvm", :id, "--vram", "{{vram}}"] - end - - config.vm.provision :salt do |salt| - - salt.minion_config = "minion" - salt.verbose = true - salt.minion_key = "{{project_name}}.pem" - salt.minion_pub = "{{project_name}}.pub" - - end - - config.ssh.forward_agent = false - -end diff --git a/examples/minions_configurations/minimum b/examples/minions_configurations/minimum deleted file mode 100644 index 3a3ae91..0000000 --- a/examples/minions_configurations/minimum +++ /dev/null @@ -1,2 +0,0 @@ -id: minimum -master: 127.0.0.1 diff --git a/examples/minions_configurations/sample_grains b/examples/minions_configurations/sample_grains deleted file mode 100644 index e5c2035..0000000 --- a/examples/minions_configurations/sample_grains +++ /dev/null @@ -1,10 +0,0 @@ -id: sample_grains -grains: - roles: - - webserver - - memcache - deployment: datacenter4 - cabinet: 13 - cab_u: 14-15 - -master: 127.0.0.1 diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index a290bd3..0000000 --- a/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ --r _requirements.txt -werkzeug diff --git a/run.py b/run.py deleted file mode 100644 index bbb4af6..0000000 --- a/run.py +++ /dev/null @@ -1,15 +0,0 @@ -import sys -from saltpad.app import app - -host = app.config['HOST'] - -if host == '0.0.0.0' and not '--insecure-debug-run' in sys.argv: - print ("You try to run saltpad in debug mode, please confirm by adding --insecure-debug-run option") - sys.exit(1) - -if host == '0.0.0.0': - print ("""Please be adviced that saltpad is running in debug mode and """ - """listening to 0.0.0.0 which is very dangerous. If you're not """ - """100% hundred sure of what to do, exit now.""") - -app.run(debug=True, host=app.config['HOST']) diff --git a/saltpad/__init__.py b/saltpad/__init__.py deleted file mode 100644 index 85a7dd6..0000000 --- a/saltpad/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -__author__ = 'Boris FELD' -__email__ = 'boris.feld@tinyclues.com' -__version__ = '0.0.1' diff --git a/saltpad/_returners/mongo_saltpad_return.py b/saltpad/_returners/mongo_saltpad_return.py deleted file mode 100644 index 0c21f3a..0000000 --- a/saltpad/_returners/mongo_saltpad_return.py +++ /dev/null @@ -1,154 +0,0 @@ -''' -Return data to a mongodb server - -Required python modules: pymongo - - -This returner will send data from the minions to a MongoDB server. To -configure the settings for your MongoDB server, add the following lines -to the minion config files:: - - mongo.db: - mongo.host: - mongo.user: - mongo.password: - mongo.port: 27017 - -This mongo returner is being developed to replace the default mongodb returner -in the future and should not be considered api stable yet. - -''' - -# Import python libs -import logging - -# Import third party libs -try: - import pymongo - HAS_PYMONGO = True -except ImportError: - HAS_PYMONGO = False - - -log = logging.getLogger(__name__) - - -def __virtual__(): - if not HAS_PYMONGO: - return False - return 'mongo_saltpad' - - -def _remove_dots(src): - output = {} - for key, val in src.items(): - if isinstance(val, dict): - val = _remove_dots(val) - output[key.replace('.', '-')] = val - return output - - -def _get_conn(): - ''' - Return a mongodb connection object - ''' - conn = pymongo.Connection( - __salt__['config.option']('mongo.host'), - __salt__['config.option']('mongo.port')) - mdb = conn[__salt__['config.option']('mongo.db')] - - user = __salt__['config.option']('mongo.user') - password = __salt__['config.option']('mongo.password') - - if user and password: - mdb.authenticate(user, password) - return conn, mdb - - -def returner(ret): - ''' - Return data to a mongodb server - ''' - conn, mdb = _get_conn() - col = mdb[ret.pop('id')] - - if isinstance(ret['return'], dict): - ret['return'] = _remove_dots(ret['return']) - - col.update({'jid': ret['jid']}, {"$set": ret}, upsert=True) - - -def save_load(jid, load): - ''' - Save the load for a given job id - ''' - conn, mdb = _get_conn() - col = mdb[jid] - col.insert(load) - - -def get_load(jid): - ''' - Returnt he load asociated with a given job id - ''' - conn, mdb = _get_conn() - return mdb[jid].find_one() - - -def get_jid(jid): - ''' - Return the return information associated with a jid - ''' - conn, mdb = _get_conn() - ret = {} - for collection in mdb.collection_names(): - rdata = mdb[collection].find_one({jid: {'$exists': 'true'}}) - if rdata: - ret[collection] = rdata - return ret - - -def get_fun(fun): - ''' - Return the most recent jobs that have executed the named function - ''' - conn, mdb = _get_conn() - ret = {} - for collection in mdb.collection_names(): - rdata = mdb[collection].find_one({'fun': fun}) - if rdata: - ret[collection] = rdata - return ret - - -def get_minions(): - ''' - Return a list of minions - ''' - conn, mdb = _get_conn() - ret = [] - for name in mdb.collection_names(): - if len(name) == 20: - try: - int(name) - continue - except ValueError: - pass - ret.append(name) - return ret - - -def get_jids(): - ''' - Return a list of job ids - ''' - conn, mdb = _get_conn() - ret = [] - for name in mdb.collection_names(): - if len(name) == 20: - try: - int(name) - ret.append(name) - except ValueError: - pass - return ret diff --git a/saltpad/app.py b/saltpad/app.py deleted file mode 100644 index 264875c..0000000 --- a/saltpad/app.py +++ /dev/null @@ -1,453 +0,0 @@ -import sys - -from functools import wraps -from six import string_types -from os.path import join, dirname - -from flask import Flask, redirect, render_template, url_for, session, request, flash, jsonify -from .core import HTTPSaltStackClient, ExpiredToken, Unauthorized, JobNotStarted -from .utils import login_url, parse_highstate, NotHighstateOutput, parse_argspec -from .utils import format_arguments, Call, validate_permissions, REQUIRED_PERMISSIONS -from .utils import get_filtered_post_arguments - -from . import settings - -# Init app - -class FlaskHTTPSaltStackClient(HTTPSaltStackClient): - - def get_token(self): - return session.get('user_token') - -template_folder = join(dirname(__file__), 'templates') -static_folder = join(dirname(__file__), 'static') -app = Flask("SaltPad", template_folder=template_folder, static_folder=static_folder) -app.config.from_object(settings) - -# Setup logging -if not app.debug: - from logging import FileHandler - app.logger.addHandler(FileHandler(app.config['LOG_FILE'])) - -# Setup sentry -try: - from raven.contrib.flask import Sentry - if app.config.get('SENTRY_DSN'): - sentry = Sentry(app, dsn=app.config['SENTRY_DSN']) -except ImportError: - if app.config.get('SENTRY_DSN'): - install_cmd = "pip install raven[flask]" - print("Couldn't import raven, please install it with '%s'" % install_cmd) - sys.exit(1) - - -client = FlaskHTTPSaltStackClient(app.config['API_URL'], - app.config.get('VERIFY_SSL', True)) - -from flask_wtf import Form -from wtforms import StringField, PasswordField, TextAreaField -from wtforms.validators import DataRequired - -class LoginForm(Form): - username = StringField('username', validators=[DataRequired()]) - password = PasswordField('password', validators=[DataRequired()]) - - -def login_required(view): - @wraps(view) - def wrapper(*args, **kwargs): - if not session.get('user_token'): - return redirect(login_url('login', request.url)) - - try: - return view(*args, **kwargs) - except (ExpiredToken, Unauthorized): - return redirect(login_url('login', request.url)) - - return wrapper - - -@app.route('/login', methods=["GET", "POST"]) -def login(): - form = LoginForm() - if form.validate_on_submit(): - try: - user_token = client.login(form['username'].data, form['password'].data) - if not validate_permissions(user_token['perms']): - perms = REQUIRED_PERMISSIONS - msg = 'Invalid permissions, saltpad needs {0} for user {1}'.format(perms, form['username'].data) - flash(msg, 'error') - else: - session['username'] = form['username'].data - session['user_token'] = user_token['token'] - flash('Hi {0}'.format(form['username'].data)) - return redirect(request.args.get("next") or url_for("index")) - except Unauthorized: - flash('Invalid credentials', 'error') - - return render_template("login.html", form=form) - -@app.route('/logout', methods=["GET"]) -def logout(): - session.clear() - flash('Bye!') - return redirect(url_for('login')) - - -@app.route("/") -@login_required -def index(): - minions = client.minions_status() - sync_status = {} - sync_number = 0 - # for minion in (minions['up'] + minions['down']): - # status = get_latest_job_status(client.get_multiple_job_status(minion, - # "state_hightest_test", max=2)) - # if status == 'success': - # ok_status += 1 - for minion in minions['up']: - if sync_status.get(minion) is True: - sync_number += 1 - - jobs = sorted(list(client.jobs().items()), reverse=True)[:10] - - return render_template('dashboard.html', minions=minions, - ok_status=sync_number, jobs=jobs) - -@app.route("/minions") -@login_required -def minions_status(): - minions = client.minions() - minions_status = client.minions_status() - - for minion in minions_status['up']: - minions.setdefault(minion, {})['state'] = 'up' - - for minion in minions_status['down']: - minions.setdefault(minion, {})['state'] = 'down' - - jobs = client.select_jobs('state.highstate', minions, with_details=True, - test=True, default_arguments_values={'test': False}) - - return render_template('minions.html', minions=minions, jobs=jobs) - -@app.route("/minions_deployments") -@login_required -def minions_deployments(): - minions = client.minions() - minions_status = client.minions_status() - - for minion in minions_status['up']: - minions.setdefault(minion, {})['state'] = 'up' - - for minion in minions_status['down']: - minions.setdefault(minion, {})['state'] = 'down' - - jobs = client.select_jobs('state.highstate', minions, with_details=True, - test=False, default_arguments_values={'test': False}) - - return render_template('minions_deployments.html', minions=minions, jobs=jobs) - - -@app.route("/minions//do_deploy") -@login_required -def minions_do_deploy(minion): - jid = client.run('state.highstate', client="local_async", - tgt=minion)['jid'] - return redirect(url_for('job_result', minion=minion, jid=jid, renderer='highstate')) - - -@app.route("/minions//do_check_sync") -@login_required -def minions_do_check_sync(minion): - jid = client.run('state.highstate', client="local_async", - tgt=minion, args=Call(test=True))['jid'] - return redirect(url_for('job_result', minion=minion, jid=jid, renderer='highstate')) - -@app.route("/jobs") -@login_required -def jobs(): - jobs = sorted(list(client.jobs().items()), reverse=True) - return render_template('jobs.html', jobs=jobs) - -@app.route("/job_result/") -@login_required -def job_result(jid): - minion = request.args.get('minion', None) - renderer = request.args.get('renderer', 'raw') - job = client.job(jid) - - context = {} - - if renderer == 'highstate': - try: - job = parse_highstate(job) - except NotHighstateOutput: - return redirect(url_for('job_result', jid=jid, minion=minion, - renderer='raw')) - elif renderer == 'aggregate': - aggregate_result = {} - - for minion, minion_return in job['return'].items(): - aggregate_result.setdefault(str(minion_return), []).append(minion) - - missing_minions = set(job['info']['Minions']) - set(job['return'].keys()) - if missing_minions: - aggregate_result['Missing results'] = missing_minions - job['aggregate_return'] = aggregate_result - context['total_minions'] = sum(len(minions) for minions in aggregate_result.values()) - - if not job: - return "Unknown jid", 404 - return render_template('job_result_{0}.html'.format(renderer), job=job, minion=minion, - renderer=renderer, **context) - -@app.route("/templates") -@login_required -def templates(): - master_config = client.run('config.values', client="wheel")['data']['return'] - if not master_config.get('templates'): - master_config['templates'] = {} - return render_template("templates.html", templates=master_config['templates']) - -@app.route("/templates/run/