Skip to content

Commit 0fa7185

Browse files
Merge pull request #19 from nutanixdev/add_template
Update to remove network security rules, add template example
2 parents b4e3a4f + 97bd43e commit 0fa7185

File tree

5 files changed

+220
-14
lines changed

5 files changed

+220
-14
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
venv/
2+
*.html

python/get_cluster_info_v3/get_cluster_info_v3.py

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ def __init__(self):
5757
self.read_timeout = 10
5858
self.entity_response_length = 20
5959
# these are the supported entities for this environment
60+
# self.supported_entities = ['vm', 'subnet', 'cluster', 'project',
61+
# 'network_security_rule', 'image',
62+
# 'host', 'blueprint', 'app']
6063
self.supported_entities = ['vm', 'subnet', 'cluster', 'project',
61-
'network_security_rule', 'image',
64+
'image',
6265
'host', 'blueprint', 'app']
6366

6467
def __repr__(self):
@@ -239,8 +242,11 @@ def generate_template(json_results):
239242
it should be a relatively simple task to update this list
240243
to support those entities
241244
'''
245+
# supported_entities = [
246+
# 'vm', 'subnet', 'cluster', 'project', 'network_security_rule',
247+
# 'image', 'host', 'blueprint', 'app']
242248
supported_entities = [
243-
'vm', 'subnet', 'cluster', 'project', 'network_security_rule',
249+
'vm', 'subnet', 'cluster', 'project',
244250
'image', 'host', 'blueprint', 'app']
245251
for row_label in supported_entities:
246252
HTML_ROWS[row_label] = ''
@@ -269,6 +275,7 @@ def generate_template(json_results):
269275
# VM #
270276
##########
271277
if json_result[0] == 'vm':
278+
print("Processing VMs ...")
272279
try:
273280
for vm in json_result[1]['entities']:
274281
entity_name = vm["spec"]["cluster_reference"]["name"]
@@ -290,6 +297,7 @@ def generate_template(json_results):
290297
# SUBNET #
291298
##########
292299
elif json_result[0] == 'subnet':
300+
print("Processing subnets ...")
293301
try:
294302
for subnet in json_result[1]['entities']:
295303
entity_name = subnet["spec"]["cluster_reference"]["name"]
@@ -306,6 +314,7 @@ def generate_template(json_results):
306314
# PROJECT #
307315
###########
308316
elif json_result[0] == 'project':
317+
print("Processing projects ...")
309318
vm_total = 0
310319
cpu_total = 0
311320
storage_total = 0
@@ -358,16 +367,20 @@ def generate_template(json_results):
358367

359368
#########################
360369
# NETWORK_SECURITY_RULE #
370+
# NO LONGER SUPPORTED #
361371
#########################
362-
elif json_result[0] == 'network_security_rule':
363-
for network_security_rule in json_result[1]['entities']:
364-
entity_name = network_security_rule['spec']['name']
365-
HTML_ROWS['network_security_rule'] += (f'<tr><td>{entity_name}'
366-
'</td></tr>')
372+
# elif json_result[0] == 'network_security_rule':
373+
# print("Processing network security rules ...")
374+
# for network_security_rule in json_result[1]['entities']:
375+
# entity_name = network_security_rule['spec']['name']
376+
# HTML_ROWS['network_security_rule'] += (f'<tr><td>{entity_name}'
377+
# '</td></tr>')
378+
367379
#########
368380
# IMAGE #
369381
#########
370382
elif json_result[0] == 'image':
383+
print("Processing images ...")
371384
try:
372385
for image in json_result[1]['entities']:
373386
entity_name = image["status"]["name"]
@@ -384,6 +397,7 @@ def generate_template(json_results):
384397
# HOST #
385398
########
386399
elif json_result[0] == 'host':
400+
print("Processing hosts ...")
387401
try:
388402
for host in json_result[1]['entities']:
389403
if 'name' in host['status']:
@@ -425,6 +439,7 @@ def generate_template(json_results):
425439
# CLUSTER #
426440
###########
427441
elif json_result[0] == 'cluster':
442+
print("Processing clusters ...")
428443
for cluster in json_result[1]['entities']:
429444
try:
430445
cluster_ip = ((cluster['spec']['resources']['network']
@@ -461,6 +476,7 @@ def generate_template(json_results):
461476
# BLUEPRINT #
462477
#############
463478
elif json_result[0] == 'blueprint':
479+
print("Processing blueprints ...")
464480
try:
465481
for blueprint in json_result[1]['entities']:
466482
entity_name = blueprint["status"]["name"]
@@ -486,6 +502,7 @@ def generate_template(json_results):
486502
# APP #
487503
#######
488504
elif json_result[0] == 'app':
505+
print("Processing apps ...")
489506
for app in json_result[1]['entities']:
490507
try:
491508
entity_name = app['status']['name']
@@ -508,8 +525,8 @@ def generate_template(json_results):
508525
specify the HTML page template
509526
'''
510527

511-
current_path = os.path.dirname(sys.argv[0])
512-
528+
current_path = os.path.dirname(os.path.realpath(__file__))
529+
513530
if os.path.isfile(f'{current_path}/templates/nutanixv3.html'):
514531
template_name = f'{current_path}/templates/nutanixv3.html'
515532
else:
@@ -529,7 +546,7 @@ def generate_template(json_results):
529546
vms=str(HTML_ROWS['vm']),
530547
subnets=str(HTML_ROWS['subnet']),
531548
projects=str(HTML_ROWS['project']),
532-
network_security_rules=str(HTML_ROWS['network_security_rule']),
549+
# network_security_rules=str(HTML_ROWS['network_security_rule']),
533550
images=str(HTML_ROWS['image']),
534551
hosts=str(HTML_ROWS['host']),
535552
blueprints=str(HTML_ROWS['blueprint']),
@@ -539,8 +556,8 @@ def generate_template(json_results):
539556
vm_total=str(ENTITY_TOTALS['vm']),
540557
subnet_total=str(ENTITY_TOTALS['subnet']),
541558
project_total=str(ENTITY_TOTALS['project']),
542-
network_security_rule_total=str(
543-
ENTITY_TOTALS['network_security_rule']),
559+
# network_security_rule_total=str(
560+
# ENTITY_TOTALS['network_security_rule']),
544561
image_total=str(ENTITY_TOTALS['image']),
545562
host_total=str(ENTITY_TOTALS['host']),
546563
blueprint_total=str(ENTITY_TOTALS['blueprint']),
@@ -600,7 +617,7 @@ def main():
600617
practices
601618
'''
602619

603-
current_path = os.path.dirname(sys.argv[0])
620+
current_path = os.path.dirname(os.path.realpath(__file__))
604621

605622
'''
606623
make sure our template exists
@@ -656,6 +673,7 @@ def main():
656673
print('Iterating over all supported endpoints ...\n')
657674

658675
for endpoint in endpoints:
676+
print(f"Processing {endpoint['name_plural']} ...")
659677
client = ApiClient(
660678
environment_options.cluster_ip,
661679
f'{endpoint["name_plural"]}/list',

python/get_cluster_info_v3/readme.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ All the steps below assume you have a terminal session running with the current
6969
- **self.entity_response_length** - Dictates how many entities are returned from a single request. **Maximum** value can be **500**.
7070
- **self.read_timeout** - Increase or decrease depending on the desired timeout delay (in seconds) for each request
7171

72+
Templates
73+
=========
74+
75+
An example template has been included with this repository.
76+
77+
- Rename `templates/nutanixv3.html.example` to `templates/nutnixv3.html`, if required.
78+
7279
Script Command Line
7380
===================
7481

@@ -160,4 +167,4 @@ These scripts are *unofficial* and are not supported or maintained by Nutanix in
160167

161168
In addition, please also be advised that these scripts may run and operate in ways that do not follow best practices. Please check through each script to ensure it meets your requirements.
162169

163-
**Changes will be required before these scripts can be used in production environments.**
170+
**Changes will be required before these scripts can be used in production environments.**
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
urllib3==2.2.2
2+
requests==2.32.3
Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
<!doctype html>
2+
3+
<html lang="en-us">
4+
5+
<head>
6+
<title>Prism Central Details (API v3)</title>
7+
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
8+
<link href="https://fonts.googleapis.com/css?family=Open+Sans&display=swap" rel="stylesheet">
9+
<style type="text/css">
10+
body { font-family: 'Open Sans', sans-serif; margin: 10px !important; }
11+
.pc_card { width: 80%; margin: 20px auto; }
12+
</style>
13+
</head>
14+
15+
<body>
16+
17+
<div id="main_content">
18+
19+
<p>The Prism Central information shown in this page is intended for demo purposes only.</p>
20+
<p>Please be aware that the totals shown in parentheses next to each entity type are accurate for each entity type, but <strong>includes deleted entities</strong>. This is particularly applicable to entities such as blueprints and apps.</p>
21+
22+
<div class="card pc_card">
23+
<div class="card-header">Clusters ($cluster_total)</div>
24+
<div class="card-body">
25+
<table class="table">
26+
<tr class="tr_header">
27+
<td>Type</td>
28+
<td>Name</td>
29+
<td>IP address</td>
30+
<td>Software</td>
31+
<td>CE?</td>
32+
</tr>
33+
<tr class="final">
34+
$clusters
35+
</tr>
36+
</table>
37+
</div>
38+
</div>
39+
40+
<div class="card pc_card">
41+
<div class="card-header">Hosts ($host_total)</div>
42+
<div class="card-body">
43+
<table class="table">
44+
<tr class="tr_header">
45+
<td>Name</td>
46+
<td>S/N</td>
47+
<td>IP</td>
48+
<td>CVM IP</td>
49+
<td># of VMs</td>
50+
</tr>
51+
<tr class="final">
52+
$hosts
53+
</tr>
54+
</table>
55+
</div>
56+
</div>
57+
58+
<div class="card pc_card">
59+
<div class="card-header">VMs ($vm_total)</div>
60+
<div class="card-body">
61+
<table class="table">
62+
<tr class="tr_header">
63+
<td>Cluster:Name</td>
64+
<td>Description</td>
65+
</tr>
66+
<tr class="final">
67+
$vms
68+
</tr>
69+
</table>
70+
</div>
71+
</div>
72+
73+
<div class="card pc_card">
74+
<div class="card-header">Subnets ($subnet_total)</div>
75+
<div class="card-body">
76+
<table class="table">
77+
<tr class="tr_header">
78+
<td>Name</td>
79+
<td>Cluster</td>
80+
</tr>
81+
<tr class="final">
82+
$subnets
83+
</tr>
84+
</table>
85+
</div>
86+
</div>
87+
88+
<div class="card pc_card">
89+
<div class="card-header">Projects ($project_total)</div>
90+
<div class="card-body">
91+
<table class="table">
92+
<tr class="tr_header">
93+
<td>Name</td>
94+
<td>VMs</td>
95+
<td>vCPUs</td>
96+
<td>Storage (GB)</td>
97+
<td>RAM (GB)</td>
98+
</tr>
99+
<tr class="final">
100+
$projects
101+
</tr>
102+
</table>
103+
</div>
104+
</div>
105+
106+
<div class="card pc_card">
107+
<div class="card-header">Apps ($app_total)</div>
108+
<div class="card-body">
109+
<table class="table">
110+
<tr class="tr_header">
111+
<td>Name</td>
112+
<td>Project</td>
113+
<td>Status</td>
114+
</tr>
115+
<tr class="final">
116+
$apps
117+
</tr>
118+
</table>
119+
</div>
120+
</div>
121+
122+
<div class="card pc_card">
123+
<div class="card-header">Blueprints ($blueprint_total)</div>
124+
<div class="card-body">
125+
<table class="table">
126+
<tr class="tr_header">
127+
<td>Name</td>
128+
<td>Project</td>
129+
<td>Status</td>
130+
</tr>
131+
<tr class="final">
132+
$blueprints
133+
</tr>
134+
</table>
135+
</div>
136+
</div>
137+
138+
<!--
139+
<div class="card pc_card">
140+
<div class="card-header">Network Security Rules ($network_security_rule_total)</div>
141+
<div class="card-body">
142+
<table class="table">
143+
<tr class="tr_header">
144+
<td>Name</td>
145+
</tr>
146+
<tr class="final">
147+
$network_security_rules
148+
</tr>
149+
</table>
150+
</div>
151+
</div>
152+
-->
153+
154+
<div class="card pc_card">
155+
<div class="card-header">Images ($image_total)</div>
156+
<div class="card-body">
157+
<table class="table">
158+
<tr class="tr_header">
159+
<td>Name</td>
160+
<td>Image Type</td>
161+
</tr>
162+
<tr class="final">
163+
$images
164+
</tr>
165+
</table>
166+
</div>
167+
</div>
168+
169+
</div>
170+
171+
<div id="footer_content">
172+
Nutanix cluster details generated on <strong>$day</strong> at <strong>$now</strong> by <strong>$username</strong> on <strong>$computer_name</strong>
173+
</div>
174+
175+
</body>
176+
177+
</html>

0 commit comments

Comments
 (0)