From 97bd43e80d6065a30edbcef0d4d92d580791ec65 Mon Sep 17 00:00:00 2001 From: Chris Rasmussen Date: Wed, 26 Jun 2024 12:29:00 +1000 Subject: [PATCH] Update to remove network security rules, add template example --- python/get_cluster_info_v3/.gitignore | 2 + .../get_cluster_info_v3.py | 44 +++-- python/get_cluster_info_v3/readme.rst | 9 +- python/get_cluster_info_v3/requirements.txt | 2 + .../templates/nutanixv3.html.example | 177 ++++++++++++++++++ 5 files changed, 220 insertions(+), 14 deletions(-) create mode 100644 python/get_cluster_info_v3/.gitignore create mode 100644 python/get_cluster_info_v3/requirements.txt create mode 100644 python/get_cluster_info_v3/templates/nutanixv3.html.example diff --git a/python/get_cluster_info_v3/.gitignore b/python/get_cluster_info_v3/.gitignore new file mode 100644 index 0000000..8a3e402 --- /dev/null +++ b/python/get_cluster_info_v3/.gitignore @@ -0,0 +1,2 @@ + venv/ +*.html diff --git a/python/get_cluster_info_v3/get_cluster_info_v3.py b/python/get_cluster_info_v3/get_cluster_info_v3.py index 3576200..35372b5 100755 --- a/python/get_cluster_info_v3/get_cluster_info_v3.py +++ b/python/get_cluster_info_v3/get_cluster_info_v3.py @@ -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): @@ -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] = '' @@ -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"] @@ -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"] @@ -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 @@ -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'{entity_name}' - '') + # 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'{entity_name}' + # '') + ######### # IMAGE # ######### elif json_result[0] == 'image': + print("Processing images ...") try: for image in json_result[1]['entities']: entity_name = image["status"]["name"] @@ -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']: @@ -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'] @@ -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"] @@ -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'] @@ -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: @@ -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']), @@ -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']), @@ -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 @@ -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', diff --git a/python/get_cluster_info_v3/readme.rst b/python/get_cluster_info_v3/readme.rst index 41f3611..cc4a88b 100755 --- a/python/get_cluster_info_v3/readme.rst +++ b/python/get_cluster_info_v3/readme.rst @@ -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 =================== @@ -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.** \ No newline at end of file +**Changes will be required before these scripts can be used in production environments.** diff --git a/python/get_cluster_info_v3/requirements.txt b/python/get_cluster_info_v3/requirements.txt new file mode 100644 index 0000000..491c9b3 --- /dev/null +++ b/python/get_cluster_info_v3/requirements.txt @@ -0,0 +1,2 @@ +urllib3==2.2.2 +requests==2.32.3 diff --git a/python/get_cluster_info_v3/templates/nutanixv3.html.example b/python/get_cluster_info_v3/templates/nutanixv3.html.example new file mode 100644 index 0000000..314bcbe --- /dev/null +++ b/python/get_cluster_info_v3/templates/nutanixv3.html.example @@ -0,0 +1,177 @@ + + + + + + Prism Central Details (API v3) + + + + + + + +
+ +

The Prism Central information shown in this page is intended for demo purposes only.

+

Please be aware that the totals shown in parentheses next to each entity type are accurate for each entity type, but includes deleted entities. This is particularly applicable to entities such as blueprints and apps.

+ +
+
Clusters ($cluster_total)
+
+ + + + + + + + + + $clusters + +
TypeNameIP addressSoftwareCE?
+
+
+ +
+
Hosts ($host_total)
+
+ + + + + + + + + + $hosts + +
NameS/NIPCVM IP# of VMs
+
+
+ +
+
VMs ($vm_total)
+
+ + + + + + + $vms + +
Cluster:NameDescription
+
+
+ +
+
Subnets ($subnet_total)
+
+ + + + + + + $subnets + +
NameCluster
+
+
+ +
+
Projects ($project_total)
+
+ + + + + + + + + + $projects + +
NameVMsvCPUsStorage (GB)RAM (GB)
+
+
+ +
+
Apps ($app_total)
+
+ + + + + + + + $apps + +
NameProjectStatus
+
+
+ +
+
Blueprints ($blueprint_total)
+
+ + + + + + + + $blueprints + +
NameProjectStatus
+
+
+ + + +
+
Images ($image_total)
+
+ + + + + + + $images + +
NameImage Type
+
+
+ +
+ + + + + +