|
| 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 | + |
0 commit comments