From b2e361f032cc3f2c47997e26d2eac5b40ea034c4 Mon Sep 17 00:00:00 2001 From: Seting-dev Date: Tue, 13 May 2025 17:41:42 +0300 Subject: [PATCH 1/4] =?UTF-8?q?=D0=A5=D1=83=D0=B9=D0=BD=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data_pools_api.py | 26 ++++++++++++++++++++++++++ main.py | 7 +++++++ vm_info_short.py | 22 ++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 data_pools_api.py create mode 100644 vm_info_short.py diff --git a/data_pools_api.py b/data_pools_api.py new file mode 100644 index 0000000..bb45d7b --- /dev/null +++ b/data_pools_api.py @@ -0,0 +1,26 @@ + +#from main import base_url , api_key , requests +import requests + +def data_pools(base_url , api_key): #output data pool info + url= f"http://{base_url}//api/data-pools/" + response = requests.get(url , headers={'Authorization' : api_key}) + + if response.status_code == 200: + data_pools = response.json() + results_data_pools_info = data_pools['results'] + + print("\nData pools overview:") + print(f"\nData pools total: {data_pools['count']}") + print("-" * 44) + for x in results_data_pools_info: + print(" "*14,"Data pool info") + print(f"\nName: {x['verbose_name']}") + print(f"\nUID: {x['id']}") + print(f"\ntype: {x['type']}") + print(f"\nstatus: {x['status']}") + print(f"\nsize: {round((x['size'] / 1024), 1)}Gb") + print("-" * 44) + + else: + print(f"Failed to retrieve data {response.status_code}") \ No newline at end of file diff --git a/main.py b/main.py index 2655221..ce06db7 100644 --- a/main.py +++ b/main.py @@ -2,6 +2,8 @@ import sys import os from cluster_api import * from domain_api import * +from data_pools_api import * +from vm_info_short import * power_state = ["Unknown" , "Off" , "Suspend" , "On"] #3 - on; 2 - suspend; 1 - off; 0 - unknown @@ -120,6 +122,11 @@ while(menu_choice != ""): #main menu loop for x in vm_uuids: vm_info(base_url , api_key , x) + if menu_choice == "5": + data_pools(base_url , api_key) + + if menu_choice == "6": + vm_info_short(base_url , api_key) print("Exiting Utility..") sys.exit() diff --git a/vm_info_short.py b/vm_info_short.py new file mode 100644 index 0000000..f9b4d10 --- /dev/null +++ b/vm_info_short.py @@ -0,0 +1,22 @@ + +#from main import base_url , api_key , requests +import requests + +def vm_info_short(base_url , api_key): #output data pool info + url= f"http://{base_url}//api/domains/" + response = requests.get(url , headers={'Authorization' : api_key}) + + if response.status_code == 200: + vm_info_short = response.json() + results_vm_info_short = vm_info_short['results'] + + print("\nShort VM overview") + print(f"\nVM total: {vm_info_short['count']}") + print("-" * 41) + for x in results_vm_info_short: + print(" "*16,f"VM {x['verbose_name']}") + print(f"UID: {x['id']}") + print("-" * 41) + + else: + print(f"Failed to retrieve data {response.status_code}") \ No newline at end of file From 2f7a0826bff1135ccba0ba5923fcdc394085d346 Mon Sep 17 00:00:00 2001 From: Seting-dev Date: Thu, 15 May 2025 10:48:51 +0300 Subject: [PATCH 2/4] test1 test2 test3 --- data_pools_api.py | 8 ++++---- domain_api.py | 1 - vm_info_short.py | 1 + 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/data_pools_api.py b/data_pools_api.py index bb45d7b..43cc7ff 100644 --- a/data_pools_api.py +++ b/data_pools_api.py @@ -16,10 +16,10 @@ def data_pools(base_url , api_key): #output data pool info for x in results_data_pools_info: print(" "*14,"Data pool info") print(f"\nName: {x['verbose_name']}") - print(f"\nUID: {x['id']}") - print(f"\ntype: {x['type']}") - print(f"\nstatus: {x['status']}") - print(f"\nsize: {round((x['size'] / 1024), 1)}Gb") + print(f"UID: {x['id']}") + print(f"type: {x['type']}") + print(f"status: {x['status']}") + print(f"size: {round((x['size'] / 1024), 1)}Gb") print("-" * 44) else: diff --git a/domain_api.py b/domain_api.py index b3931e7..a72039f 100644 --- a/domain_api.py +++ b/domain_api.py @@ -111,7 +111,6 @@ def vm_info(base_url , api_key , vm_uuids): get_disk_info(domain_all_content) - def create_and_attach_disk(base_url , api_key , vm_id, data_pool_uuid, vdisk_size, preallocation): domain_name=get_domain_info(base_url , api_key , vm_id) disk_name=domain_name["verbose_name"]+"_"+secrets.token_hex(5) #generates unique hex id. this method can generate ~million unique ids diff --git a/vm_info_short.py b/vm_info_short.py index f9b4d10..60246f6 100644 --- a/vm_info_short.py +++ b/vm_info_short.py @@ -17,6 +17,7 @@ def vm_info_short(base_url , api_key): #output data pool info print(" "*16,f"VM {x['verbose_name']}") print(f"UID: {x['id']}") print("-" * 41) + # else: print(f"Failed to retrieve data {response.status_code}") \ No newline at end of file From e7d2e0e82993ee45b5a078c8e0b22dc622a1d611 Mon Sep 17 00:00:00 2001 From: Seting-dev Date: Thu, 15 May 2025 10:53:03 +0300 Subject: [PATCH 3/4] check --- data_pools_api.py | 2 +- main.py | 2 +- vm_info_short.py | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/data_pools_api.py b/data_pools_api.py index 43cc7ff..2e5e6ce 100644 --- a/data_pools_api.py +++ b/data_pools_api.py @@ -20,7 +20,7 @@ def data_pools(base_url , api_key): #output data pool info print(f"type: {x['type']}") print(f"status: {x['status']}") print(f"size: {round((x['size'] / 1024), 1)}Gb") - print("-" * 44) + print("-" * 44) else: print(f"Failed to retrieve data {response.status_code}") \ No newline at end of file diff --git a/main.py b/main.py index 06f6fe6..7dacf48 100644 --- a/main.py +++ b/main.py @@ -130,7 +130,7 @@ while(menu_choice != ""): #main menu loop cluster_info(base_url , api_key) if menu_choice == "4": - print("\033[H\033[2J", end="") + print("\033[H\033[2J", end="") for x in vm_uuids: vm_info(base_url , api_key , x) diff --git a/vm_info_short.py b/vm_info_short.py index 60246f6..f9b4d10 100644 --- a/vm_info_short.py +++ b/vm_info_short.py @@ -17,7 +17,6 @@ def vm_info_short(base_url , api_key): #output data pool info print(" "*16,f"VM {x['verbose_name']}") print(f"UID: {x['id']}") print("-" * 41) - # else: print(f"Failed to retrieve data {response.status_code}") \ No newline at end of file From 9525c4e2db343b414c74dcc17b5bd1987b8604c1 Mon Sep 17 00:00:00 2001 From: Seting-dev <77554471+Seting-dev@users.noreply.github.com> Date: Thu, 15 May 2025 10:58:07 +0300 Subject: [PATCH 4/4] Update main.py test --- main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/main.py b/main.py index 7dacf48..f102425 100644 --- a/main.py +++ b/main.py @@ -138,6 +138,7 @@ while(menu_choice != ""): #main menu loop data_pools(base_url , api_key) if menu_choice == "6": + vm_info_short(base_url , api_key) print("Exiting Utility..")