11import os
22import json
33import base64
4- import sys
54from datetime import datetime
65from datetime import timedelta
76import time
87import urllib3
98
109from flask import (
11- Blueprint , flash , g , redirect , render_template , request , session , url_for , jsonify
10+ Blueprint ,
11+ request ,
12+ jsonify ,
1213)
13- from werkzeug .security import check_password_hash , generate_password_hash
1414
1515from .util import apiclient
1616
17- bp = Blueprint (' ajax' , __name__ , url_prefix = ' /ajax' )
17+ bp = Blueprint (" ajax" , __name__ , url_prefix = " /ajax" )
1818
1919"""
2020disable insecure connection warnings
2323"""
2424urllib3 .disable_warnings (urllib3 .exceptions .InsecureRequestWarning )
2525
26+
2627"""
2728get the form POST data provided by the user
2829"""
30+
31+
2932def get_form ():
3033 global form_data
3134 global cvmAddress
3235 global username
3336 global password
37+ global entity
3438 form_data = request .form
35- cvmAddress = form_data ['_cvmAddress' ]
36- username = form_data ['_username' ]
37- password = form_data ['_password' ]
39+ cvmAddress = form_data ["_cvmAddress" ]
40+ username = form_data ["_username" ]
41+ password = form_data ["_password" ]
42+ entity = form_data ["_entity" ]
43+
3844
3945"""
4046load the default layout at app startup
4147"""
42- @bp .route ('/load-layout' ,methods = ['POST' ])
48+
49+
50+ @bp .route ("/load-layout" , methods = ["POST" ])
4351def load_layout ():
4452 site_root = os .path .realpath (os .path .dirname (__file__ ))
45- layout_path = ' static/layouts'
46- dashboard_file = ' dashboard.json'
47- with open ( f' { site_root } /{ layout_path } /{ dashboard_file } ' , 'r' ) as f :
53+ layout_path = " static/layouts"
54+ dashboard_file = " dashboard.json"
55+ with open (f" { site_root } /{ layout_path } /{ dashboard_file } " , "r" ) as f :
4856 raw_json = json .loads (f .read ())
49- return base64 .b64decode (raw_json [' layout' ]).decode (' utf-8' )
57+ return base64 .b64decode (raw_json [" layout" ]).decode (" utf-8" )
5058
51- """
52- get some high level cluster info
53- """
54- @bp .route ('/cluster-info' ,methods = ['POST' ])
55- def cluster_info ():
56- # get the request's POST data
57- get_form ()
58- client = apiclient .ApiClient ('post' , cvmAddress ,'clusters/list' ,'{"kind":"cluster"}' ,username ,password )
59- results = client .get_info ()
60- return jsonify (results )
6159
6260"""
63- get the vm count
61+ connect to prism central and collect details about a specific type of entity
6462"""
65- @bp .route ('/vm-info' ,methods = ['GET' ,'POST' ])
66- def vm_info ():
67- # get the request's POST data
68- get_form ()
69- client = apiclient .ApiClient ('get' , cvmAddress ,'vms' ,'' ,username ,password ,'v2.0' )
70- results = client .get_info ()
71- return jsonify (results )
7263
73- """
74- get the cluster's physical info e.g. # of hosts, host serial numbers
75- """
76- @bp .route ('/physical-info' ,methods = ['POST' ])
77- def physical_info ():
64+
65+ @bp .route ("/pc-list-entities" , methods = ["POST" ])
66+ def pc_list_entities ():
7867 # get the request's POST data
7968 get_form ()
80- client = apiclient .ApiClient ('get' , cvmAddress ,'hosts' ,'' ,username ,password ,'v2.0' )
69+ client = apiclient .ApiClient (
70+ method = "post" ,
71+ cluster_ip = cvmAddress ,
72+ request = f"{ entity } s/list" ,
73+ entity = entity ,
74+ body = f'{{"kind": "{ entity } "}}' ,
75+ username = username ,
76+ password = password ,
77+ )
8178 results = client .get_info ()
8279 return jsonify (results )
8380
81+
8482"""
85- get the cluster's storage performance
83+ get storage performance stats for the first storage container in a cluster
8684"""
87- @bp .route ('/storage-performance' ,methods = ['POST' ])
85+
86+
87+ @bp .route ("/storage-performance" , methods = ["POST" ])
8888def storage_performance ():
8989 # get the request's POST data
9090 get_form ()
@@ -97,17 +97,49 @@ def storage_performance():
9797 endTime = round (time .mktime (endTime .timetuple ()) * 1000 * 1000 )
9898 startTime = round (time .mktime (startTime .timetuple ()) * 1000 * 1000 )
9999
100- 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' )
101- results = client .get_info ()
102- return jsonify (results )
100+ # first, get the external IP address of the first cluster registered to this Prism Central instance
101+ entity = "cluster"
102+ client = apiclient .ApiClient (
103+ method = "post" ,
104+ cluster_ip = cvmAddress ,
105+ request = f"{ entity } s/list" ,
106+ entity = entity ,
107+ body = f'{{"kind": "{ entity } "}}' ,
108+ username = username ,
109+ password = password ,
110+ )
111+ cluster_ip = client .get_info ()["entities" ][0 ]["status" ]["resources" ]["network" ][
112+ "external_ip"
113+ ]
103114
104- """
105- get the container info e.g. # of containers
106- """
107- @bp .route ('/container-info' ,methods = ['POST' ])
108- def containers ():
109- # get the request's POST data
110- get_form ()
111- client = apiclient .ApiClient ('get' ,cvmAddress ,f'storage_containers' ,'' ,username ,password ,'v2.0' )
112- results = client .get_info ()
113- return jsonify (results )
115+ # next, get the UUID of the first storage container in the cluster found in our previous request
116+ entity = "storage_containers"
117+ client = apiclient .ApiClient (
118+ method = "get" ,
119+ cluster_ip = cluster_ip ,
120+ request = entity ,
121+ entity = "" ,
122+ body = "" ,
123+ username = username ,
124+ password = password ,
125+ version = "v2.0" ,
126+ )
127+ storage_container_uuid = client .get_info ()["entities" ][0 ]["id" ]
128+
129+ # finally, get the performance stats for the storage container found in our previous request
130+ entity = "storage_containers"
131+ full_request = f"storage_containers/{ storage_container_uuid } /stats/?metrics=controller_avg_io_latency_usecs&start_time_in_usecs={ startTime } &end_time_in_usecs={ endTime } "
132+ client = apiclient .ApiClient (
133+ method = "get" ,
134+ cluster_ip = cluster_ip ,
135+ request = full_request ,
136+ entity = "" ,
137+ body = "" ,
138+ username = username ,
139+ password = password ,
140+ version = "v2.0" ,
141+ )
142+ stats = client .get_info ()
143+
144+ # return the JSON array containing storage container performance info for the last 4 hours
145+ return jsonify (stats )
0 commit comments