From 95923829663a9fffa405cd5ac8485eaf246e04ce Mon Sep 17 00:00:00 2001 From: OVERLORD7F Date: Thu, 25 Sep 2025 16:12:52 +0300 Subject: [PATCH] fixed #30 --- config_data_import.py | 64 ++++++++----------------------------------- 1 file changed, 12 insertions(+), 52 deletions(-) diff --git a/config_data_import.py b/config_data_import.py index aeeb96f..11a658b 100644 --- a/config_data_import.py +++ b/config_data_import.py @@ -53,7 +53,7 @@ def config_menu(base_url, api_key, config_relative_path): needs_reload = True if sub_choice == "7": - change_vm_uuids(config_relative_path) + change_vm_uuids(config_relative_path, base_url, api_key) needs_reload = True if sub_choice == "8": @@ -183,7 +183,7 @@ def change_iso_uuid(config_relative_path): print("No 'VM_Options' section in config file..") config_show(config_relative_path) -def change_vm_uuids(config_relative_path): #change selected VM uuids in config +def change_vm_uuids(config_relative_path, base_url, api_key): #change selected VM uuids in config config = configparser.ConfigParser() config.read(config_relative_path) # Remove old VM_List section if it exists, then add a fresh one @@ -197,6 +197,11 @@ def change_vm_uuids(config_relative_path): #change selected VM uuids in config vm_input = console.input("[bold yellow]>> [/]" ) if not vm_input: break + # validate only the entered VM UUID via get_vm_name + vm_name = get_vm_name(base_url, "jwt " + api_key, vm_input) + if not vm_name: + console.print("[red bold]Invalid VM UUID (not found)") + continue x += 1 config.set('VM_List', f'uuid_{x}', vm_input) @@ -208,56 +213,6 @@ def change_vm_uuids(config_relative_path): #change selected VM uuids in config config_show(config_relative_path) -def config_edit(config_relative_path): - read_input = Prompt.ask("[bold yellow]Create new config file?[/]", choices=["Y", "N"], default="N", case_sensitive=False) - menu_choice = str(read_input) - if menu_choice == "Y" or menu_choice == "y": - base_url = input("Type SpaceVM Controller IP: ") - while check_ping(base_url) != True: - base_url = console.input("[bold red]No response.\nCheck and type SpaceVM Controller IP again: [/]") - - api_key = input("Type your API Key: ") - while check_api_key(base_url, "jwt " + api_key) != 200: - api_key = console.input("[bold red]Check and type SpaceVM Controller API Key again: [/]") - show_data_pools(base_url, "jwt " + api_key) - data_pool_uuid = input("Type Data Pool UUID you wish to use: ") - - config = configparser.ConfigParser() - config["General"] = { - "controller_ip": base_url, - "api_key": api_key, - "skip_startup_splash": "no", - } - config["Data_Pool"] = {"data_pool_uuid": data_pool_uuid} - - #disk_interface=input("Specify preffered disk interface (virtio / ide / scsi / sata): ") - #preallocation=input("Specify allocation type for virtual disks (none / falloc / full / metadata): ") - #iso_uuid=input("Specify ISO uuid you wish to auto-mount during operations(none - skip this step): ") - #config["VM_Options"] = { - # "disk_interface": disk_interface, - # "preallocation": preallocation, - # "iso_uuid": iso_uuid - #} - - with open(config_relative_path, "w") as configfile: #writing everything from above to config file - config.write(configfile) - - print("Type VM UUIDs one by one (input ENTER to stop)") - with open(config_relative_path, "a") as file: - file.write("[VM_List]\n") #manually writing section for VMs - vm_input = [] - x = 0 - while vm_input != "": - vm_input = input(">> ") - if vm_input: - x += 1 - file.write(f"uuid_{x} = {vm_input}\n") - - console.print("[green bold]VM UUIDs have been written in config :pencil:") - console.print("[green bold]Configuration completed ! :white_check_mark:") - Prompt.ask("[green_yellow bold]Press ENTER to proceed.. :right_arrow_curving_down:") - cls() - def check_config(config_relative_path): """Check if config exists and is valid""" # Only check if the file is empty and needs to be removed @@ -338,6 +293,11 @@ def create_new_profile(): vm_input = console.input("[bold yellow]>> [/]") if not vm_input: break + # validate only the vm_input by fetching VM name + vm_name = get_vm_name(base_url, "jwt " + api_key, vm_input) + if not vm_name: + console.print("[red bold]Invalid VM UUID (not found)") + continue x += 1 file.write(f"uuid_{x} = {vm_input}\n")