-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathapp.py
More file actions
53 lines (46 loc) · 1.84 KB
/
app.py
File metadata and controls
53 lines (46 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from flask import Flask, render_template, redirect, request, url_for, jsonify, session
from flask_assets import Bundle, Environment
import requests
from base64 import b64encode
app = Flask(__name__)
app.secret_key = "super secret key"
env = Environment(app)
js = Bundle('js/clarity-icons.min.js', 'js/clarity-icons-api.js',
'js/clarity-icons-element.js', 'js/custom-elements.min.js')
env.register('js_all', js)
css = Bundle('css/clarity-ui.min.css', 'css/clarity-icons.min.css')
env.register('css_all', css)
@app.route('/', methods=["GET", "POST"])
def homepage():
if request.method == "POST":
attempted_username = request.form['username']
print(attempted_username)
attempted_password = request.form['password']
print(attempted_password)
if attempted_username == "admin" and attempted_password == "password":
session['logged_in'] = True
session['wrong_pass'] = False
session['username'] = request.form['username']
return redirect(url_for('homepage'))
else:
session['logged_in'] = False
session['wrong_pass'] = True
return render_template('index.html')
@app.route('/vms')
def vmlist():
req = requests.get('https://pyva.humblelab.com/rest/vcenter/vms')
req_json = req.json()
return render_template('vms.html', vms = req_json)
@app.route('/workflows')
def workflows():
url = 'https://hlcloud.humblelab.com'
value = b64encode(b"username:password").decode("ascii")
headers = {
'Authorization': 'Basic '+ value,
'content-type': 'application/json',
'accept' : 'application/json'
}
req = requests.get('{}/vco/api/workflows/'.format(url), verify=False, headers=headers)
return render_template('workflows.html', flows=req.json()['link'])
if __name__ == '__main__':
app.run(debug=True)