Skip to content

Commit 21d9653

Browse files
committed
Repo creation
0 parents  commit 21d9653

38 files changed

+16633
-0
lines changed

.gitignore

Whitespace-only changes.

MANIFEST.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
graft lab/static
2+
graft lab/templates
3+
global-exclude *.pyc

config.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import os
2+
3+
class Config(object):
4+
SECRET_KEY = os.environ.get('SECRET_KEY') or 'some strong secret string'
5+

lab/__init__.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import os
2+
3+
from flask import Flask
4+
from flask_assets import Environment, Bundle
5+
6+
from .util import apiclient
7+
from config import Config
8+
9+
def create_app(test_config=None):
10+
# create and configure the app
11+
app = Flask(__name__, instance_relative_config=True)
12+
13+
assets = Environment(app)
14+
15+
home_css = Bundle(
16+
'css/lib/reset.css',
17+
'css/lib/built-in.css',
18+
'css/lib/jquery-ui-custom.css',
19+
'css/lib/jq.gridster.css',
20+
'css/lib/jq.jqplot.css',
21+
'css/ntnx.css'
22+
)
23+
24+
home_js = Bundle(
25+
'js/lib/jquery-2.1.3.min.js',
26+
'js/lib/classie.min.js',
27+
'js/lib/ntnx-bootstrap.min.js',
28+
'js/lib/modernizr.custom.min.js',
29+
'js/lib/jquery.jqplot.min.js',
30+
'js/lib/jqplot.logAxisRenderer.js',
31+
'js/lib/jqplot.categoryAxisRenderer.js',
32+
'js/lib/jqplot.canvasAxisLabelRenderer.js',
33+
'js/lib/jqplot.canvasTextRenderer.js',
34+
'js/lib/jquery.gridster.min.js',
35+
'js/ntnx.js'
36+
)
37+
38+
assets.register('home_css',home_css)
39+
assets.register('home_js',home_js)
40+
41+
app.config.from_object(Config)
42+
43+
if test_config is None:
44+
# load the instance config, if it exists, when not testing
45+
app.config.from_pyfile('config.py', silent=True)
46+
else:
47+
# load the test config if passed in
48+
app.config.from_mapping(test_config)
49+
50+
# ensure the instance folder exists
51+
try:
52+
os.makedirs(app.instance_path)
53+
except OSError:
54+
pass
55+
56+
from . import index
57+
app.register_blueprint(index.bp)
58+
59+
from . import ajax
60+
app.register_blueprint(ajax.bp)
61+
62+
return app
63+

lab/ajax.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
import os
2+
import json
3+
import base64
4+
import sys
5+
from datetime import datetime
6+
from datetime import timedelta
7+
import time
8+
9+
from flask import (
10+
Blueprint, flash, g, redirect, render_template, request, session, url_for, jsonify
11+
)
12+
from werkzeug.security import check_password_hash, generate_password_hash
13+
14+
from .util import apiclient
15+
16+
bp = Blueprint('ajax', __name__, url_prefix='/ajax')
17+
18+
"""
19+
get the form POST data provided by the user
20+
"""
21+
def get_form():
22+
global form_data
23+
global cvmAddress
24+
global username
25+
global password
26+
form_data = request.form
27+
cvmAddress = form_data['_cvmAddress']
28+
username = form_data['_username']
29+
password = form_data['_password']
30+
31+
"""
32+
load the default layout at app startup
33+
"""
34+
@bp.route('/load-layout',methods=['POST'])
35+
def load_layout():
36+
site_root = os.path.realpath(os.path.dirname(__file__))
37+
layout_path = 'static/layouts'
38+
dashboard_file = 'dashboard.json'
39+
with open( f'{site_root}/{layout_path}/{dashboard_file}','r') as f:
40+
raw_json = json.loads(f.read())
41+
return base64.b64decode(raw_json['layout']).decode('utf-8')
42+
43+
"""
44+
get some high level cluster info
45+
"""
46+
@bp.route('/cluster-info',methods=['POST'])
47+
def cluster_info():
48+
# get the request's POST data
49+
get_form()
50+
client = apiclient.ApiClient('post', cvmAddress,'clusters/list','{"kind":"cluster"}',username,password)
51+
results = client.get_info()
52+
return jsonify(results)
53+
54+
"""
55+
get the vm count
56+
"""
57+
@bp.route('/vm-info',methods=['GET','POST'])
58+
def vm_info():
59+
# get the request's POST data
60+
get_form()
61+
client = apiclient.ApiClient('get', cvmAddress,'vms','',username,password,'v2.0')
62+
results = client.get_info()
63+
return jsonify(results)
64+
65+
"""
66+
get the cluster's physical info e.g. # of hosts, host serial numbers
67+
"""
68+
@bp.route('/physical-info',methods=['POST'])
69+
def physical_info():
70+
# get the request's POST data
71+
get_form()
72+
client = apiclient.ApiClient('get', cvmAddress,'hosts','',username,password,'v2.0')
73+
results = client.get_info()
74+
return jsonify(results)
75+
76+
"""
77+
get the cluster's storage performance
78+
"""
79+
@bp.route('/storage-performance',methods=['POST'])
80+
def storage_performance():
81+
# get the request's POST data
82+
get_form()
83+
84+
# get the current time then substract 4 hours
85+
# this is used for the storage performance chart
86+
endTime = datetime.now()
87+
delta = timedelta(hours=-4)
88+
startTime = endTime + delta
89+
endTime = round(time.mktime(endTime.timetuple()) * 1000 * 1000)
90+
startTime = round(time.mktime(startTime.timetuple()) * 1000 * 1000)
91+
92+
client = apiclient.ApiClient('get',cvmAddress,f'cluster/stats/?metrics=controller_avg_io_latency_usecs&startTimeInUsecs={startTime}&endTimeInUsecs={endTime}&intervalInSecs=30','',username,password,'v1','PrismGateway/services/rest')
93+
results = client.get_info()
94+
return jsonify(results)
95+
96+
"""
97+
get the container info e.g. # of containers
98+
"""
99+
@bp.route('/container-info',methods=['POST'])
100+
def containers():
101+
# get the request's POST data
102+
get_form()
103+
client = apiclient.ApiClient('get',cvmAddress,f'storage_containers','',username,password,'v2.0')
104+
results = client.get_info()
105+
return jsonify(results)
106+

lab/forms.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from flask_wtf import FlaskForm
2+
from wtforms import StringField, PasswordField, BooleanField, SubmitField
3+
from wtforms.validators import DataRequired
4+
5+
"""
6+
The clusterForm class is used to identify the properties used when submitted cluster details
7+
"""
8+
class clusterForm(FlaskForm):
9+
cvmAddress = StringField('cvmAddress', validators=[DataRequired()])
10+
username = StringField('username', validators=[DataRequired()])
11+
password = PasswordField('password', validators=[DataRequired()])
12+
submit = SubmitField('Go!', id="goButton")
13+

lab/index.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from lab.forms import clusterForm
2+
3+
from flask import (
4+
Blueprint, flash, g, redirect, render_template, request, session, url_for
5+
)
6+
from werkzeug.security import check_password_hash, generate_password_hash
7+
8+
bp = Blueprint('index', __name__, url_prefix='/')
9+
10+
@bp.route('/')
11+
def index():
12+
# make sure we are using the form that's been generated in forms.py
13+
form = clusterForm()
14+
return render_template('index.html', form=form)
15+
19.9 KB
Binary file not shown.

0 commit comments

Comments
 (0)