Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions python/get_cluster_info_v3/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
venv/
*.html
44 changes: 31 additions & 13 deletions python/get_cluster_info_v3/get_cluster_info_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,11 @@ def __init__(self):
self.read_timeout = 10
self.entity_response_length = 20
# these are the supported entities for this environment
# self.supported_entities = ['vm', 'subnet', 'cluster', 'project',
# 'network_security_rule', 'image',
# 'host', 'blueprint', 'app']
self.supported_entities = ['vm', 'subnet', 'cluster', 'project',
'network_security_rule', 'image',
'image',
'host', 'blueprint', 'app']

def __repr__(self):
Expand Down Expand Up @@ -239,8 +242,11 @@ def generate_template(json_results):
it should be a relatively simple task to update this list
to support those entities
'''
# supported_entities = [
# 'vm', 'subnet', 'cluster', 'project', 'network_security_rule',
# 'image', 'host', 'blueprint', 'app']
supported_entities = [
'vm', 'subnet', 'cluster', 'project', 'network_security_rule',
'vm', 'subnet', 'cluster', 'project',
'image', 'host', 'blueprint', 'app']
for row_label in supported_entities:
HTML_ROWS[row_label] = ''
Expand Down Expand Up @@ -269,6 +275,7 @@ def generate_template(json_results):
# VM #
##########
if json_result[0] == 'vm':
print("Processing VMs ...")
try:
for vm in json_result[1]['entities']:
entity_name = vm["spec"]["cluster_reference"]["name"]
Expand All @@ -290,6 +297,7 @@ def generate_template(json_results):
# SUBNET #
##########
elif json_result[0] == 'subnet':
print("Processing subnets ...")
try:
for subnet in json_result[1]['entities']:
entity_name = subnet["spec"]["cluster_reference"]["name"]
Expand All @@ -306,6 +314,7 @@ def generate_template(json_results):
# PROJECT #
###########
elif json_result[0] == 'project':
print("Processing projects ...")
vm_total = 0
cpu_total = 0
storage_total = 0
Expand Down Expand Up @@ -358,16 +367,20 @@ def generate_template(json_results):

#########################
# NETWORK_SECURITY_RULE #
# NO LONGER SUPPORTED #
#########################
elif json_result[0] == 'network_security_rule':
for network_security_rule in json_result[1]['entities']:
entity_name = network_security_rule['spec']['name']
HTML_ROWS['network_security_rule'] += (f'<tr><td>{entity_name}'
'</td></tr>')
# elif json_result[0] == 'network_security_rule':
# print("Processing network security rules ...")
# for network_security_rule in json_result[1]['entities']:
# entity_name = network_security_rule['spec']['name']
# HTML_ROWS['network_security_rule'] += (f'<tr><td>{entity_name}'
# '</td></tr>')

#########
# IMAGE #
#########
elif json_result[0] == 'image':
print("Processing images ...")
try:
for image in json_result[1]['entities']:
entity_name = image["status"]["name"]
Expand All @@ -384,6 +397,7 @@ def generate_template(json_results):
# HOST #
########
elif json_result[0] == 'host':
print("Processing hosts ...")
try:
for host in json_result[1]['entities']:
if 'name' in host['status']:
Expand Down Expand Up @@ -425,6 +439,7 @@ def generate_template(json_results):
# CLUSTER #
###########
elif json_result[0] == 'cluster':
print("Processing clusters ...")
for cluster in json_result[1]['entities']:
try:
cluster_ip = ((cluster['spec']['resources']['network']
Expand Down Expand Up @@ -461,6 +476,7 @@ def generate_template(json_results):
# BLUEPRINT #
#############
elif json_result[0] == 'blueprint':
print("Processing blueprints ...")
try:
for blueprint in json_result[1]['entities']:
entity_name = blueprint["status"]["name"]
Expand All @@ -486,6 +502,7 @@ def generate_template(json_results):
# APP #
#######
elif json_result[0] == 'app':
print("Processing apps ...")
for app in json_result[1]['entities']:
try:
entity_name = app['status']['name']
Expand All @@ -508,8 +525,8 @@ def generate_template(json_results):
specify the HTML page template
'''

current_path = os.path.dirname(sys.argv[0])

current_path = os.path.dirname(os.path.realpath(__file__))
if os.path.isfile(f'{current_path}/templates/nutanixv3.html'):
template_name = f'{current_path}/templates/nutanixv3.html'
else:
Expand All @@ -529,7 +546,7 @@ def generate_template(json_results):
vms=str(HTML_ROWS['vm']),
subnets=str(HTML_ROWS['subnet']),
projects=str(HTML_ROWS['project']),
network_security_rules=str(HTML_ROWS['network_security_rule']),
# network_security_rules=str(HTML_ROWS['network_security_rule']),
images=str(HTML_ROWS['image']),
hosts=str(HTML_ROWS['host']),
blueprints=str(HTML_ROWS['blueprint']),
Expand All @@ -539,8 +556,8 @@ def generate_template(json_results):
vm_total=str(ENTITY_TOTALS['vm']),
subnet_total=str(ENTITY_TOTALS['subnet']),
project_total=str(ENTITY_TOTALS['project']),
network_security_rule_total=str(
ENTITY_TOTALS['network_security_rule']),
# network_security_rule_total=str(
# ENTITY_TOTALS['network_security_rule']),
image_total=str(ENTITY_TOTALS['image']),
host_total=str(ENTITY_TOTALS['host']),
blueprint_total=str(ENTITY_TOTALS['blueprint']),
Expand Down Expand Up @@ -600,7 +617,7 @@ def main():
practices
'''

current_path = os.path.dirname(sys.argv[0])
current_path = os.path.dirname(os.path.realpath(__file__))

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

for endpoint in endpoints:
print(f"Processing {endpoint['name_plural']} ...")
client = ApiClient(
environment_options.cluster_ip,
f'{endpoint["name_plural"]}/list',
Expand Down
9 changes: 8 additions & 1 deletion python/get_cluster_info_v3/readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ All the steps below assume you have a terminal session running with the current
- **self.entity_response_length** - Dictates how many entities are returned from a single request. **Maximum** value can be **500**.
- **self.read_timeout** - Increase or decrease depending on the desired timeout delay (in seconds) for each request

Templates
=========

An example template has been included with this repository.

- Rename `templates/nutanixv3.html.example` to `templates/nutnixv3.html`, if required.

Script Command Line
===================

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

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.

**Changes will be required before these scripts can be used in production environments.**
**Changes will be required before these scripts can be used in production environments.**
2 changes: 2 additions & 0 deletions python/get_cluster_info_v3/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
urllib3==2.2.2
requests==2.32.3
177 changes: 177 additions & 0 deletions python/get_cluster_info_v3/templates/nutanixv3.html.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
<!doctype html>

<html lang="en-us">

<head>
<title>Prism Central Details (API v3)</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link href="https://fonts.googleapis.com/css?family=Open+Sans&display=swap" rel="stylesheet">
<style type="text/css">
body { font-family: 'Open Sans', sans-serif; margin: 10px !important; }
.pc_card { width: 80%; margin: 20px auto; }
</style>
</head>

<body>

<div id="main_content">

<p>The Prism Central information shown in this page is intended for demo purposes only.</p>
<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>

<div class="card pc_card">
<div class="card-header">Clusters ($cluster_total)</div>
<div class="card-body">
<table class="table">
<tr class="tr_header">
<td>Type</td>
<td>Name</td>
<td>IP address</td>
<td>Software</td>
<td>CE?</td>
</tr>
<tr class="final">
$clusters
</tr>
</table>
</div>
</div>

<div class="card pc_card">
<div class="card-header">Hosts ($host_total)</div>
<div class="card-body">
<table class="table">
<tr class="tr_header">
<td>Name</td>
<td>S/N</td>
<td>IP</td>
<td>CVM IP</td>
<td># of VMs</td>
</tr>
<tr class="final">
$hosts
</tr>
</table>
</div>
</div>

<div class="card pc_card">
<div class="card-header">VMs ($vm_total)</div>
<div class="card-body">
<table class="table">
<tr class="tr_header">
<td>Cluster:Name</td>
<td>Description</td>
</tr>
<tr class="final">
$vms
</tr>
</table>
</div>
</div>

<div class="card pc_card">
<div class="card-header">Subnets ($subnet_total)</div>
<div class="card-body">
<table class="table">
<tr class="tr_header">
<td>Name</td>
<td>Cluster</td>
</tr>
<tr class="final">
$subnets
</tr>
</table>
</div>
</div>

<div class="card pc_card">
<div class="card-header">Projects ($project_total)</div>
<div class="card-body">
<table class="table">
<tr class="tr_header">
<td>Name</td>
<td>VMs</td>
<td>vCPUs</td>
<td>Storage (GB)</td>
<td>RAM (GB)</td>
</tr>
<tr class="final">
$projects
</tr>
</table>
</div>
</div>

<div class="card pc_card">
<div class="card-header">Apps ($app_total)</div>
<div class="card-body">
<table class="table">
<tr class="tr_header">
<td>Name</td>
<td>Project</td>
<td>Status</td>
</tr>
<tr class="final">
$apps
</tr>
</table>
</div>
</div>

<div class="card pc_card">
<div class="card-header">Blueprints ($blueprint_total)</div>
<div class="card-body">
<table class="table">
<tr class="tr_header">
<td>Name</td>
<td>Project</td>
<td>Status</td>
</tr>
<tr class="final">
$blueprints
</tr>
</table>
</div>
</div>

<!--
<div class="card pc_card">
<div class="card-header">Network Security Rules ($network_security_rule_total)</div>
<div class="card-body">
<table class="table">
<tr class="tr_header">
<td>Name</td>
</tr>
<tr class="final">
$network_security_rules
</tr>
</table>
</div>
</div>
-->

<div class="card pc_card">
<div class="card-header">Images ($image_total)</div>
<div class="card-body">
<table class="table">
<tr class="tr_header">
<td>Name</td>
<td>Image Type</td>
</tr>
<tr class="final">
$images
</tr>
</table>
</div>
</div>

</div>

<div id="footer_content">
Nutanix cluster details generated on <strong>$day</strong> at <strong>$now</strong> by <strong>$username</strong> on <strong>$computer_name</strong>
</div>

</body>

</html>