/
aci-dashboard-tutorial.py
80 lines (57 loc) · 1.63 KB
/
aci-dashboard-tutorial.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from flask import Flask, render_template
import os
from acitoolkit.acitoolkit import Session, Tenant
from acitoolkit.aciHealthScore import HealthScore
import json
# initialize ACI toolkit session
APIC_URL = os.getenv("APIC_URL")
APIC_LOGIN = os.getenv("APIC_LOGIN")
APIC_PASSWORD = os.getenv("APIC_PASSWORD")
SESSION = Session(APIC_URL, APIC_LOGIN, APIC_PASSWORD)
SESSION.login()
# Eliminate Trailing slash
if APIC_URL.endswith('/'):
APIC_URL = APIC_URL[:-1]
app = Flask(__name__)
def get_tenants():
"""
return a list of ACIToolkit tenant objects
"""
# your code goes here
pass
def get_tenant_healthscore(obj):
"""
Returns a healthscore for a particular tenants
:param obj: acitoolkit Tenant object
:return: current health score
"""
# your code replaces the following line
return 100
def get_tenant_faultcounts(obj):
"""
return fault counts for a tenant
"""
# your code replaces the following line
pass
@app.route('/')
def react():
# This view doesn't actually send any data to the template, the client
#will retrieve it via API calls (and eventually websockets)
return render_template('react.html')
@app.route('/api/tenants')
def dash():
"""
API which returns tenant list with additional information we've created
"""
data = list()
tenants = get_tenants()
for t in tenants:
score = get_tenant_healthscore(t)
i = {"name": t.name,
"dn": t.dn,
"score": score,
}
data.append(i)
return json.dumps(data)
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)