diff --git a/domain_api.py b/domain_api.py index daa5dc3..764edb6 100644 --- a/domain_api.py +++ b/domain_api.py @@ -2,6 +2,7 @@ import requests import secrets #for generating unique names import os +from config_data_import import * from rich.console import Console , Align from rich.columns import Columns from rich.panel import Panel @@ -136,6 +137,9 @@ def vm_info_short(base_url, api_key): if response.status_code == 200: vm_info_short = response.json() results_vm_info_short = vm_info_short['results'] + tag = vm_info_short['results'][0]['tags'][0] + print(tag) + #print(results_vm_info_short) os.system('cls' if os.name=='nt' else 'clear') console.print(Align.center(Panel(f"[bold magenta]Short VM overview | Total: {vm_info_short['count']}", expand=True , border_style="yellow") , vertical="middle")) console.rule(style="grey53") @@ -190,4 +194,49 @@ def vm_check_power(base_url , api_key , vm_uuids): raise Exception(f"VM - {vm_uuids} is UNAVAILABLE! \n Have fun figuring that out D:") if domain_info['user_power_state'] == 1: pass - #print(f"VM - {vm_uuids} Power check passed!") \ No newline at end of file + +def vm_tags(base_url, api_key): + url = f"http://{base_url}/api/domains/" + response = requests.get(url, headers={'Authorization': api_key}) + if response.status_code == 200: + verbose_name_input = input("Write tag:") + output_renderables = [] + vm_info_short = response.json() + y= vm_info_short + vm_id_list = [] + for y in vm_info_short['results']: + for x in y['tags']: + if x['verbose_name'] == verbose_name_input: + vm_id_list.append(y['id']) + output_string = f"VM: [bold]{y['verbose_name']} [bold yellow]#{x['verbose_name']}[/]" + f"\nUUID: [italic]{y['id']}" + output_renderable = Panel(output_string, expand=False, border_style="magenta") + output_renderables.append(output_renderable) #adds current renderable + console.print(Columns(output_renderables)) #print renderables by columns + else: + print(f"Failed to retrieve data {response.status_code}") + console.rule(style="grey53") + Prompt.ask("[green_yellow bold]ENTER - return to Main Menu.... :right_arrow_curving_down:") + os.system('cls' if os.name=='nt' else 'clear') + return(vm_id_list) + +def vm_menu(base_url, api_key, vm_uuids): + os.system('cls' if os.name=='nt' else 'clear') + config_menu_options="[gold bold][1] [grey53 italic]Show VM info \n (for selected VMs in config)[/grey53 italic]\n \ +\n[gold bold][2] [grey53 italic]Show VMs Name / UUID[/grey53 italic]\n \ +\n[gold bold][3] [grey53 italic]Show VMs by tags / UUID[/grey53 italic]\n \ +\n\n[green_yellow bold]ENTER - return to Main Menu[/]" + config_menu_options=Align.center(config_menu_options, vertical="middle") + console = Console() + console.print(Panel(config_menu_options, title="[gold bold]Show VM info" , border_style="magenta" , width=150 , padding = 2)) + sub_choice=str(input("\n>>> ")) + if sub_choice == "1": + os.system('cls' if os.name=='nt' else 'clear') + for x in vm_uuids: + vm_info(base_url , api_key , x) + Prompt.ask("[green_yellow bold]Press ENTER to proceed.. :right_arrow_curving_down:") + if sub_choice == "2": + os.system('cls' if os.name=='nt' else 'clear') + vm_info_short(base_url , api_key) + if sub_choice == "3": + os.system('cls' if os.name=='nt' else 'clear') + vm_tags(base_url , api_key) \ No newline at end of file diff --git a/main.py b/main.py index 3c3413f..b714635 100644 --- a/main.py +++ b/main.py @@ -22,9 +22,8 @@ while(menu_choice != ""): #main menu loop menu_options=f"[gold bold][1] [grey53 italic]Manage utility config\n[/grey53 italic] \ \n[gold bold][2] [grey53 italic]Enter disk edit mode[/grey53 italic]\n \ \n[gold bold][3] [grey53 italic]Show breif cluster overview[/grey53 italic]\n \ -\n[gold bold][4] [grey53 italic]Show VM info \n (for selected VMs in config)[/grey53 italic]\n \ +\n[gold bold][4] [grey53 italic]Show VM info[/grey53 italic]\n \ \n[gold bold][5] [grey53 italic]Show data pools[/grey53 italic]\n \ -\n[gold bold][6] [grey53 italic]Show VMs Name / UUID[/grey53 italic]\n \ \n\n[green_yellow bold]ENTER - exit Utility[/]\n\n \ [underline bold grey53]Currently imported config:[/]\n \ [bold grey53]Connected to Controller: [bright_yellow]{base_url}[/]\n Selected Data Pool: [bright_yellow]{data_pool_name}[/]\n Selected VMs:\n [bright_yellow]{vm_names}" @@ -39,15 +38,8 @@ while(menu_choice != ""): #main menu loop if menu_choice == "3": cluster_info(base_url , api_key) if menu_choice == "4": - os.system('cls' if os.name=='nt' else 'clear') - for x in vm_uuids: - vm_info(base_url , api_key , x) - Prompt.ask("[green_yellow bold]Press ENTER to proceed.. :right_arrow_curving_down:") + vm_menu(base_url , api_key, vm_uuids) if menu_choice == "5": show_data_pools(base_url , api_key) - if menu_choice == "6": - vm_info_short(base_url , api_key) - if menu_choice == "7": - check_api_key(base_url, api_key) os.system('cls' if os.name=='nt' else 'clear') #clears screen before looping back to main menu -console.print("[red bold]Exiting Utility ") \ No newline at end of file +console.print("[red bold]Exiting Utility ")