- Small code cleanup. config_data_import <400 lines!

- Tested new version 6.5.8
- Added elapsed timer #31 (Courses only)
- Corrected version label in menus
- New splash screens (highly requested feature)
- Moved spash screens files to ./assets directory
- Correct colors for menu  options
This commit is contained in:
2025-10-15 11:05:36 +03:00
parent 339ba4c5df
commit d275f8d5e8
7 changed files with 117 additions and 184 deletions

View File

@@ -9,7 +9,7 @@ Written in python, uses [SpaceVM API](https://spacevm.ru/docs/6.5/api/) to colle
>[!NOTE] >[!NOTE]
>_This utility is focused on managing virtual disks_<br> >_This utility is focused on managing virtual disks_<br>
>_Works with SpaceVM 6.5.5 / 6.5.6 / 6.5.7_ <br> >_Works with SpaceVM 6.5.5 / 6.5.6 / 6.5.7 / 6.5.8_ <br>
> [:file_folder:_Repo Mirror Available Here_:clipboard:](https://gt.7fproject.com/OVERLORD/SVMU) > [:file_folder:_Repo Mirror Available Here_:clipboard:](https://gt.7fproject.com/OVERLORD/SVMU)
# Requirements # Requirements

View File

@@ -9,62 +9,62 @@ from rich.panel import Panel
from rich.console import Console , Align from rich.console import Console , Align
from rich.prompt import Prompt from rich.prompt import Prompt
console = Console() console = Console()
def config_menu(base_url, api_key, config_relative_path): def config_menu(base_url, api_key, config_relative_path):
cls() cls()
config_menu_options="[gold bold][1] [grey53 italic]Show current profile configuration\n[/]\ menu = (
\n[gold bold][2] [grey53 italic]Setup new profile[/]\n \ "[gold1 bold][1][/] [grey53 italic]Show current profile configuration[/grey53 italic]\n\n"
\n[gold bold][3] [grey53 italic]Switch profile[/]\n\ "[gold1 bold][2][/] [grey53 italic]Setup new profile[/]\n\n"
\n[gold bold][4] [grey53 italic]Delete profile[/]\n\ "[gold1 bold][3][/] [grey53 italic]Switch profile[/]\n\n"
\n[gold bold][5] [grey53 italic]Set default profile[/]\n\ "[gold1 bold][4][/] [grey53 italic]Delete profile[/]\n\n"
\n[gold bold][6] [grey53 italic]Change selected data pool[/]\n\ "[gold1 bold][5][/] [grey53 italic]Set default profile[/]\n\n"
\n[gold bold][7] [grey53 italic]Change selected VMs[/]\n\ "[gold1 bold][6][/] [grey53 italic]Change selected data pool[/]\n\n"
\n[gold bold][8] [grey53 italic]Change ISO UUID (auto-mount)[/]\n\ "[gold1 bold][7][/] [grey53 italic]Change selected VMs[/]\n\n"
\n[gold bold][9] [grey53 italic]Skip start-up splash[/]\n\ "[gold1 bold][8][/] [grey53 italic]Change ISO UUID (auto-mount)[/]\n\n"
\n\n[green_yellow bold]ENTER - return to Main Menu[/]" "[gold1 bold][9][/] [grey53 italic]Skip start-up splash[/]\n\n"
config_menu_options=Align.center(config_menu_options, vertical="middle") "[green_yellow bold]ENTER - return to Main Menu"
console = Console() )
console.print(Panel(config_menu_options, title="[gold bold]SpaceVM Utility - Utility Configuration" , border_style="magenta" , width=150 , padding = 2)) console.print(Panel(Align.center(menu, vertical="middle"), title="[gold bold]SpaceVM Utility - Utility Configuration", border_style="magenta", width=150, padding=2))
sub_choice = console.input("[bold yellow]\n>>> [/]") choice = console.input("[bold yellow]\n>>> [/]")
needs_reload = False new_profile = None #used for controlling profile switch / updating current profile
needs_reload = False
if sub_choice == "1":
config_show(config_relative_path)
return config_menu(base_url, api_key, config_relative_path)
if sub_choice == "2":
new_path = create_new_profile()
if new_path:
return new_path
if sub_choice == "3":
new_profile_path = switch_profile()
if new_profile_path: # If we got a new profile path
return new_profile_path # Return it to main.py
if sub_choice == "4":
delete_profile(config_relative_path)
if sub_choice == "5": if choice == "1":
set_default_profile() config_show(config_relative_path)
return new_profile, needs_reload
if choice == "2":
result = create_new_profile() # create_new_profile may return a profile path (to switch to)
if result:
new_profile = result
return new_profile, needs_reload
if choice == "3":
result = switch_profile() # switch_profile returns the selected profile path
if result:
new_profile = result
return new_profile, needs_reload
if choice == "4":
delete_profile(config_relative_path)
return new_profile, needs_reload
if choice == "5":
set_default_profile()
return new_profile, needs_reload
if choice == "6":
change_data_pool(base_url, api_key, config_relative_path)
needs_reload = True
return new_profile, needs_reload
if choice == "7":
change_vm_uuids(config_relative_path, base_url, api_key)
needs_reload = True
return new_profile, needs_reload
if choice == "8":
change_iso_uuid(config_relative_path)
needs_reload = True
return new_profile, needs_reload
if choice == "9":
change_startup_option(config_relative_path)
needs_reload = True
return new_profile, needs_reload
if sub_choice == "6": return new_profile, needs_reload
change_data_pool(base_url, api_key, config_relative_path)
needs_reload = True
if sub_choice == "7":
change_vm_uuids(config_relative_path, base_url, api_key)
needs_reload = True
if sub_choice == "8":
change_iso_uuid(config_relative_path)
needs_reload = True
if sub_choice == "9":
change_startup_option(config_relative_path)
needs_reload = True
return needs_reload
def config_show(config_relative_path): def config_show(config_relative_path):
cls() cls()
@@ -77,7 +77,6 @@ def config_show(config_relative_path):
def config_import(config_relative_path): def config_import(config_relative_path):
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(config_relative_path) config.read(config_relative_path)
skip_startup_splash = config.get('General', 'skip_startup_splash') skip_startup_splash = config.get('General', 'skip_startup_splash')
base_url = config.get('General', 'controller_ip') base_url = config.get('General', 'controller_ip')
api_key = "jwt " + config.get('General', 'api_key') #That was realy obvious DACOM >:C api_key = "jwt " + config.get('General', 'api_key') #That was realy obvious DACOM >:C
@@ -88,8 +87,7 @@ def config_import(config_relative_path):
for key, value in config['VM_List'].items(): for key, value in config['VM_List'].items():
vm_list.append(value) vm_list.append(value)
#importing VM_Options if config.has_section('VM_Options'): #importing VM_Options
if config.has_section('VM_Options'):
iso_uuid = config.get('VM_Options' , 'iso_uuid') iso_uuid = config.get('VM_Options' , 'iso_uuid')
disk_interface = config.get('VM_Options' , 'disk_interface') disk_interface = config.get('VM_Options' , 'disk_interface')
preallocation = config.get('VM_Options' , 'preallocation') preallocation = config.get('VM_Options' , 'preallocation')
@@ -101,35 +99,22 @@ def config_import(config_relative_path):
preallocation = "falloc" preallocation = "falloc"
iso_name= "none" iso_name= "none"
config = configparser.ConfigParser() #writing default values to config config = configparser.ConfigParser() #writing default values to config
config["VM_Options"] = { config["VM_Options"] = {"disk_interface": "virtio", "preallocation": "falloc", "iso_uuid": "none"}
"disk_interface": "virtio",
"preallocation": "falloc",
"iso_uuid": "none",
}
with open(config_relative_path, "a") as configfile: # appending to existing config file with open(config_relative_path, "a") as configfile: # appending to existing config file
config.write(configfile) config.write(configfile)
#importing disk sizes for SpaceVM courses if config.has_section('Courses-Space-VM'): #importing disk sizes for SpaceVM courses
if config.has_section('Courses-Space-VM'): disk1_size, disk2_size, disk3_size = config.get('Courses-Space-VM', 'disk1'), config.get('Courses-Space-VM', 'disk2'), config.get('Courses-Space-VM', 'disk3')
disk1_size = config.get('Courses-Space-VM', 'disk1')
disk2_size = config.get('Courses-Space-VM', 'disk2')
disk3_size = config.get('Courses-Space-VM', 'disk3')
else: else:
console.print("[bold yellow]Applying default values to Disk sizes for Courses") console.print("[bold yellow]Applying default values to Disk sizes for Courses")
disk1_size, disk2_size, disk3_size = 10, 20, 20 #applying default values for courses disk1_size, disk2_size, disk3_size = 10, 20, 20 #applying default values for courses
config = configparser.ConfigParser() #writing default values to config config = configparser.ConfigParser() #writing default values to config
config["Courses-Space-VM"] = { config["Courses-Space-VM"] = {"disk1": 10, "disk2": 20,"disk3": 20}
"disk1": 10,
"disk2": 20,
"disk3": 20,
}
with open(config_relative_path, "a") as configfile: # appending to existing config file with open(config_relative_path, "a") as configfile: # appending to existing config file
config.write(configfile) config.write(configfile)
#get pretty name for selected data pool data_pool_name = get_data_pool_name(base_url , api_key , data_pool_uuid) #get pretty name for selected data pool
data_pool_name = get_data_pool_name(base_url , api_key , data_pool_uuid) vm_names=[] #get pretty name for selected VMs
#get pretty name for selected VMs
vm_names=[]
for x in vm_list: for x in vm_list:
vm_names.append(get_vm_name(base_url, api_key, x)) vm_names.append(get_vm_name(base_url, api_key, x))
@@ -137,23 +122,16 @@ def config_import(config_relative_path):
def change_startup_option(config_relative_path): def change_startup_option(config_relative_path):
cls() cls()
# Ask the user once and normalize the answer
new_value = Prompt.ask("[yellow bold]Skip start-up splash ?[/]", choices=["Y", "N"], default="N", case_sensitive=False) new_value = Prompt.ask("[yellow bold]Skip start-up splash ?[/]", choices=["Y", "N"], default="N", case_sensitive=False)
if new_value.lower() == "y": if new_value.lower() == "y":
startup_option = "yes" startup_option = "yes"
else: else:
startup_option = "no" startup_option = "no"
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(config_relative_path) config.read(config_relative_path)
# Ensure General section exists so we can write the option
if not config.has_section('General'):
config.add_section('General')
config.set('General', 'skip_startup_splash', startup_option) config.set('General', 'skip_startup_splash', startup_option)
with open(config_relative_path, 'w') as config_file: with open(config_relative_path, 'w') as config_file:
config.write(config_file) config.write(config_file)
console.print(f"[green bold]Option set to: {new_value}") console.print(f"[green bold]Option set to: {new_value}")
def change_data_pool(base_url, api_key, config_relative_path): #change selected data pool in config def change_data_pool(base_url, api_key, config_relative_path): #change selected data pool in config
@@ -181,13 +159,12 @@ def change_iso_uuid(config_relative_path):
config.write(config_file) config.write(config_file)
else: else:
print("No 'VM_Options' section in config file..") print("No 'VM_Options' section in config file..")
config_show(config_relative_path) #config_show(config_relative_path)
def change_vm_uuids(config_relative_path, base_url, api_key): #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 = configparser.ConfigParser()
config.read(config_relative_path) config.read(config_relative_path)
# Remove old VM_List section if it exists, then add a fresh one if config.has_section('VM_List'): # Remove old VM_List section if it exists, then add a new one
if config.has_section('VM_List'):
config.remove_section('VM_List') config.remove_section('VM_List')
config.add_section('VM_List') config.add_section('VM_List')
cls() cls()
@@ -197,8 +174,7 @@ def change_vm_uuids(config_relative_path, base_url, api_key): #change selected V
vm_input = console.input("[bold yellow]>> [/]" ) vm_input = console.input("[bold yellow]>> [/]" )
if not vm_input: if not vm_input:
break break
# validate only the entered VM UUID via get_vm_name vm_name = get_vm_name(base_url, "jwt " + api_key, vm_input) # validate entered VM UUID via get_vm_name
vm_name = get_vm_name(base_url, "jwt " + api_key, vm_input)
if not vm_name: if not vm_name:
console.print("[red bold]Invalid VM UUID (not found)") console.print("[red bold]Invalid VM UUID (not found)")
continue continue
@@ -207,18 +183,13 @@ def change_vm_uuids(config_relative_path, base_url, api_key): #change selected V
with open(config_relative_path, 'w') as configfile: with open(config_relative_path, 'w') as configfile:
config.write(configfile) config.write(configfile)
console.print("[green bold]VM UUIDs have been updated in config :pencil:")
console.print("[green bold]VM UUIDs have been updated in config :pencil:")
Prompt.ask("[green_yellow bold]Press ENTER to proceed.. :right_arrow_curving_down:") Prompt.ask("[green_yellow bold]Press ENTER to proceed.. :right_arrow_curving_down:")
config_show(config_relative_path) config_show(config_relative_path)
def check_config(config_relative_path): # Check if config exists and is valid
def check_config(config_relative_path): if os.path.exists(config_relative_path) and os.path.getsize(config_relative_path) == 0: # Only check if the file is empty
"""Check if config exists and is valid"""
# Only check if the file is empty and needs to be removed
if os.path.exists(config_relative_path) and os.path.getsize(config_relative_path) == 0:
console.print("[red bold]Config file is empty!") console.print("[red bold]Config file is empty!")
os.remove(config_relative_path) # Remove empty file
def cls(): def cls():
os.system('cls' if os.name=='nt' else 'clear') os.system('cls' if os.name=='nt' else 'clear')
@@ -235,15 +206,13 @@ def check_ping(base_url):
else: else:
return False return False
def create_profiles_dir(): def create_profiles_dir(): #creates ./profiles directory if it does not exist
"""Create profiles directory if it doesn't exist"""
profiles_dir = os.path.join(os.getcwd(), 'profiles') profiles_dir = os.path.join(os.getcwd(), 'profiles')
if not os.path.exists(profiles_dir): if not os.path.exists(profiles_dir):
os.makedirs(profiles_dir) os.makedirs(profiles_dir)
return profiles_dir return profiles_dir
def get_available_profiles(): def get_available_profiles(): #Get list of available profile names
"""Get list of available profile names"""
profiles_dir = create_profiles_dir() profiles_dir = create_profiles_dir()
profiles = [] profiles = []
for filename in os.listdir(profiles_dir): for filename in os.listdir(profiles_dir):
@@ -251,14 +220,11 @@ def get_available_profiles():
profiles.append(filename[:-5]) # Remove .conf extension profiles.append(filename[:-5]) # Remove .conf extension
return profiles return profiles
def create_new_profile(): def create_new_profile(): # Create new profile. Returns profile_path
"""Create a new profile configuration"""
cls() cls()
profiles_dir = create_profiles_dir() profiles_dir = create_profiles_dir()
profile_name = Prompt.ask("[yellow bold]Enter new profile name") profile_name = Prompt.ask("[yellow bold]Enter new profile name")
profile_path = os.path.join(profiles_dir, f"{profile_name}.conf") profile_path = os.path.join(profiles_dir, f"{profile_name}.conf")
if os.path.exists(profile_path): if os.path.exists(profile_path):
console.print("[red bold]Profile already exists!") console.print("[red bold]Profile already exists!")
return return
@@ -275,11 +241,7 @@ def create_new_profile():
data_pool_uuid = console.input("[bold yellow]Type Data Pool UUID you wish to use: [/]") data_pool_uuid = console.input("[bold yellow]Type Data Pool UUID you wish to use: [/]")
config = configparser.ConfigParser() config = configparser.ConfigParser()
config["General"] = { config["General"] = {"controller_ip": base_url, "api_key": api_key, "skip_startup_splash": "no"}
"controller_ip": base_url,
"api_key": api_key,
"skip_startup_splash": "no",
}
config["Data_Pool"] = {"data_pool_uuid": data_pool_uuid} config["Data_Pool"] = {"data_pool_uuid": data_pool_uuid}
with open(profile_path, "w") as configfile: with open(profile_path, "w") as configfile:
@@ -293,8 +255,7 @@ def create_new_profile():
vm_input = console.input("[bold yellow]>> [/]") vm_input = console.input("[bold yellow]>> [/]")
if not vm_input: if not vm_input:
break break
# validate only the vm_input by fetching VM name vm_name = get_vm_name(base_url, "jwt " + api_key, vm_input) # validate entered VM UUID via get_vm_name
vm_name = get_vm_name(base_url, "jwt " + api_key, vm_input)
if not vm_name: if not vm_name:
console.print("[red bold]Invalid VM UUID (not found)") console.print("[red bold]Invalid VM UUID (not found)")
continue continue
@@ -302,13 +263,10 @@ def create_new_profile():
file.write(f"uuid_{x} = {vm_input}\n") file.write(f"uuid_{x} = {vm_input}\n")
console.print("[green bold]Configuration completed! :white_check_mark:") console.print("[green bold]Configuration completed! :white_check_mark:")
# Prompt to switch to the newly created profile now
switch_now = Prompt.ask("[yellow bold]Switch to new profile now?", choices=["Y", "N"] , default="Y", case_sensitive=False) switch_now = Prompt.ask("[yellow bold]Switch to new profile now?", choices=["Y", "N"] , default="Y", case_sensitive=False)
if switch_now.lower() == "y" or switch_now.lower() == "Y": if switch_now.lower() == "y" or switch_now.lower() == "Y":
# Also ask if user wants to set this profile as default
set_default = Prompt.ask("[yellow bold]Set new profile as default?", choices=["Y", "N"], default="N", case_sensitive=False) set_default = Prompt.ask("[yellow bold]Set new profile as default?", choices=["Y", "N"], default="N", case_sensitive=False)
if set_default.lower() == "y" or set_default.lower() == "Y": if set_default.lower() == "y" or set_default.lower() == "Y":
# Use existing set_default_profile logic: mark this profile as default
profiles_dir = create_profiles_dir() profiles_dir = create_profiles_dir()
profiles = get_available_profiles() profiles = get_available_profiles()
for p in profiles: for p in profiles:
@@ -320,8 +278,7 @@ def create_new_profile():
with open(p_path, 'w') as f: with open(p_path, 'w') as f:
cfg.write(f) cfg.write(f)
# set new profile as default cfg = configparser.ConfigParser() # set new profile as default
cfg = configparser.ConfigParser()
cfg.read(profile_path) cfg.read(profile_path)
if not cfg.has_section('General'): if not cfg.has_section('General'):
cfg.add_section('General') cfg.add_section('General')
@@ -330,11 +287,9 @@ def create_new_profile():
cfg.write(f) cfg.write(f)
return profile_path return profile_path
def switch_profile(): def switch_profile(): # switch to different profile
"""Switch to a different profile."""
cls() cls()
profiles = get_available_profiles() profiles = get_available_profiles()
if not profiles: if not profiles:
console.print("[red bold]No profiles found!") console.print("[red bold]No profiles found!")
return return
@@ -342,26 +297,20 @@ def switch_profile():
console.print("[yellow bold]Available profiles:") console.print("[yellow bold]Available profiles:")
for i, profile in enumerate(profiles, 1): for i, profile in enumerate(profiles, 1):
console.print(f"[grey53]{i}. {profile}") console.print(f"[grey53]{i}. {profile}")
choice = Prompt.ask("[yellow bold]Select profile number: ", choices=[str(i) for i in range(1, len(profiles) + 1)]) choice = Prompt.ask("[yellow bold]Select profile number: ", choices=[str(i) for i in range(1, len(profiles) + 1)])
selected_profile = profiles[int(choice) - 1] selected_profile = profiles[int(choice) - 1]
# Get the path for the selected profile selected_profile_path = os.path.join(create_profiles_dir(), f"{selected_profile}.conf") # Get the path for the selected profile
selected_profile_path = os.path.join(create_profiles_dir(), f"{selected_profile}.conf")
if not os.path.exists(selected_profile_path): if not os.path.exists(selected_profile_path):
console.print(f"[red bold]Profile '{selected_profile}' does not exist!") console.print(f"[red bold]Profile '{selected_profile}' does not exist!")
return return
# Return the new profile path to update in main.py console.print(f"[green bold]Switched to profile: {selected_profile}") # Return the new profile path to update in main.py
console.print(f"[green bold]Switched to profile: {selected_profile}")
return selected_profile_path # Return the new path instead of True return selected_profile_path # Return the new path instead of True
def delete_profile(current_profile_path): def delete_profile(current_profile_path): #Delete existing profile
"""Delete an existing profile"""
cls() cls()
profiles = get_available_profiles() profiles = get_available_profiles()
if not profiles: if not profiles:
console.print("[red bold]No profiles found!") console.print("[red bold]No profiles found!")
return return
@@ -372,11 +321,10 @@ def delete_profile(current_profile_path):
choice = Prompt.ask("[yellow bold]Select profile to delete", choices=[str(i) for i in range(1, len(profiles)+1)]) choice = Prompt.ask("[yellow bold]Select profile to delete", choices=[str(i) for i in range(1, len(profiles)+1)])
selected_profile = profiles[int(choice)-1] selected_profile = profiles[int(choice)-1]
selected_profile_path = os.path.join(create_profiles_dir(), f"{selected_profile}.conf") selected_profile_path = os.path.join(create_profiles_dir(), f"{selected_profile}.conf")
if os.path.normpath(selected_profile_path) == os.path.normpath(current_profile_path): if os.path.normpath(selected_profile_path) == os.path.normpath(current_profile_path):
console.print("[red bold]Cannot delete the currently active profile!") console.print("[red bold]Cannot delete currently active profile!")
Prompt.ask("[green_yellow bold]Press ENTER to return.. :right_arrow_curving_down:") Prompt.ask("[green_yellow bold]Press ENTER to return.. :right_arrow_curving_down:")
return return
@@ -385,11 +333,9 @@ def delete_profile(current_profile_path):
os.remove(os.path.join(os.getcwd(), 'profiles', f"{selected_profile}.conf")) os.remove(os.path.join(os.getcwd(), 'profiles', f"{selected_profile}.conf"))
console.print(f"[green bold]Profile {selected_profile} deleted!") console.print(f"[green bold]Profile {selected_profile} deleted!")
def set_default_profile(): def set_default_profile(): # Set selected profile as default
"""Set the selected profile as the default profile."""
cls() cls()
profiles = get_available_profiles() profiles = get_available_profiles()
if not profiles: if not profiles:
console.print("[red bold]No profiles found!") console.print("[red bold]No profiles found!")
return return
@@ -400,9 +346,8 @@ def set_default_profile():
choice = Prompt.ask("[yellow bold]Select profile number to set as default", choices=[str(i) for i in range(1, len(profiles) + 1)]) choice = Prompt.ask("[yellow bold]Select profile number to set as default", choices=[str(i) for i in range(1, len(profiles) + 1)])
selected_profile = profiles[int(choice) - 1] selected_profile = profiles[int(choice) - 1]
# Set all other profiles' default flag to false profiles_dir = create_profiles_dir() #Fuck you there could be only ONE default ! (all other profiles deafult flags set to false)
profiles_dir = create_profiles_dir()
for profile in profiles: for profile in profiles:
profile_path = os.path.join(profiles_dir, f"{profile}.conf") profile_path = os.path.join(profiles_dir, f"{profile}.conf")
config = configparser.ConfigParser() config = configparser.ConfigParser()
@@ -411,9 +356,8 @@ def set_default_profile():
config.set('General', 'load_by_default', 'false') config.set('General', 'load_by_default', 'false')
with open(profile_path, 'w') as f: with open(profile_path, 'w') as f:
config.write(f) config.write(f)
# Set the selected profile as default selected_profile_path = os.path.join(profiles_dir, f"{selected_profile}.conf") # Set the selected profile as default
selected_profile_path = os.path.join(profiles_dir, f"{selected_profile}.conf")
config = configparser.ConfigParser() config = configparser.ConfigParser()
config.read(selected_profile_path) config.read(selected_profile_path)
if not config.has_section('General'): if not config.has_section('General'):
@@ -424,8 +368,7 @@ def set_default_profile():
console.print(f"[green bold]Profile '{selected_profile}' set as default!") console.print(f"[green bold]Profile '{selected_profile}' set as default!")
def get_default_config_path(): def get_default_config_path(): # Retrieve the path of the default profile. If none, promt user to select one
"""Retrieve the path of the default profile configuration or prompt the user to select one."""
profiles_dir = create_profiles_dir() profiles_dir = create_profiles_dir()
profiles = get_available_profiles() profiles = get_available_profiles()
@@ -437,25 +380,20 @@ def get_default_config_path():
if config.getboolean('General', 'load_by_default'): if config.getboolean('General', 'load_by_default'):
return profile_path return profile_path
# If no default profile is found, prompt the user to select one if profiles: # no default profile is found, prompt to select one
if profiles:
console.print("[yellow bold]No default profile found. Please select a profile to load:") console.print("[yellow bold]No default profile found. Please select a profile to load:")
for i, profile in enumerate(profiles, 1): for i, profile in enumerate(profiles, 1):
console.print(f"[grey53]{i}. {profile}") console.print(f"[grey53]{i}. {profile}")
choice = Prompt.ask("[yellow bold]Select profile number", choices=[str(i) for i in range(1, len(profiles) + 1)]) choice = Prompt.ask("[yellow bold]Select profile number", choices=[str(i) for i in range(1, len(profiles) + 1)])
selected_profile = profiles[int(choice) - 1] selected_profile = profiles[int(choice) - 1]
return os.path.join(profiles_dir, f"{selected_profile}.conf") return os.path.join(profiles_dir, f"{selected_profile}.conf")
console.print("[red bold]No profiles available. Please create a new profile.") console.print("[red bold]No profiles available. Please create a new profile.")
create_new_profile() create_new_profile()
# Refresh the profiles list and directly return the newly created profile profiles = get_available_profiles() # Refresh the profiles list and return new one
profiles = get_available_profiles()
if profiles: if profiles:
new_profile_path = os.path.join(profiles_dir, f"{profiles[-1]}.conf") new_profile_path = os.path.join(profiles_dir, f"{profiles[-1]}.conf")
console.print(f"[green bold]Loaded newly created profile: {profiles[-1]}") console.print(f"[green bold]Loaded newly created profile: {profiles[-1]}")
return new_profile_path return new_profile_path
raise RuntimeError("Failed to create or load a profile.") raise RuntimeError("Failed to create or load a profile.")
# config_relative_path will be set when passed from main.py

View File

@@ -1,4 +1,4 @@
import os, sys import os, sys, time
import requests import requests
from domain_api import * from domain_api import *
from rich.prompt import Prompt from rich.prompt import Prompt
@@ -7,10 +7,10 @@ from rich.panel import Panel
def disk_edit_mode(base_url , api_key , data_pool_uuid , vm_uuids, disk1_size, disk2_size, disk3_size, disk_interface, preallocation, iso_uuid): def disk_edit_mode(base_url , api_key , data_pool_uuid , vm_uuids, disk1_size, disk2_size, disk3_size, disk_interface, preallocation, iso_uuid):
os.system('cls' if os.name=='nt' else 'clear') os.system('cls' if os.name=='nt' else 'clear')
diks_edit_menu_options="[gold bold][1] [grey53 italic]Delete vDisk by UUID\n[/grey53 italic] \ diks_edit_menu_options="[gold1 bold][1] [grey53 italic]Delete vDisk by UUID\n[/grey53 italic] \
\n[gold bold][2] [grey53 italic]Delete ALL vDisks on selected Virtual Machine[/grey53 italic]\n \ \n[gold1 bold][2] [grey53 italic]Delete ALL vDisks on selected Virtual Machine[/grey53 italic]\n \
\n[gold bold][3] [grey53 italic]Create Disk[/grey53 italic]\n \ \n[gold1 bold][3] [grey53 italic]Create Disk[/grey53 italic]\n \
\n[gold bold][4] [grey53 italic]Prepare VMs for Courses™[/grey53 italic]\n \ \n[gold1 bold][4] [grey53 italic]Prepare VMs for Courses™[/grey53 italic]\n \
\n\n[green_yellow bold]ENTER - return to Main Menu" \n\n[green_yellow bold]ENTER - return to Main Menu"
diks_edit_menu_options = Align.center(diks_edit_menu_options, vertical="middle") diks_edit_menu_options = Align.center(diks_edit_menu_options, vertical="middle")
console = Console() console = Console()
@@ -44,6 +44,7 @@ def disk_edit_mode(base_url , api_key , data_pool_uuid , vm_uuids, disk1_size, d
for y in vm_uuids: #power-on check for y in vm_uuids: #power-on check
domain_uuid = y.strip('\n') domain_uuid = y.strip('\n')
vm_check_power(base_url , api_key , domain_uuid) vm_check_power(base_url , api_key , domain_uuid)
start_time = time.perf_counter() #after power-on check passed, starting timer
for x in vm_uuids: # only for removing disks for x in vm_uuids: # only for removing disks
domain_uuid = x.strip('\n') domain_uuid = x.strip('\n')
domain_info = get_domain_info(base_url , api_key , domain_uuid) domain_info = get_domain_info(base_url , api_key , domain_uuid)
@@ -70,7 +71,7 @@ def disk_edit_mode(base_url , api_key , data_pool_uuid , vm_uuids, disk1_size, d
console.print("[grey53 italic]iso_uuid was not specified. Skipping ISO auto-mount..[/]") console.print("[grey53 italic]iso_uuid was not specified. Skipping ISO auto-mount..[/]")
else: else:
attach_iso(base_url, api_key, domain_uuid, iso_uuid) attach_iso(base_url, api_key, domain_uuid, iso_uuid)
end_time = time.perf_counter() # timer end
console.print("[bold green]\nDone. Happy virtualization :thumbs_up::thumbs_up:") console.print(f"[bold gold1]\nOperation completed. Elapsed time {end_time - start_time:.1f} seconds \n[bold green]Happy virtualization :thumbs_up::thumbs_up:")
Prompt.ask("[green_yellow bold]ENTER - return to Main Menu.. :right_arrow_curving_down:") Prompt.ask("[green_yellow bold]ENTER - return to Main Menu.. :right_arrow_curving_down:")
os.system('cls' if os.name=='nt' else 'clear') os.system('cls' if os.name=='nt' else 'clear')

View File

@@ -317,9 +317,9 @@ def attach_iso(base_url, api_key, vm_id, iso_uuid):
def vm_menu(base_url, api_key, vm_uuids, config_relative_path): def vm_menu(base_url, api_key, vm_uuids, config_relative_path):
os.system('cls' if os.name=='nt' else 'clear') 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 \ config_menu_options="[gold1 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[gold1 bold][2] [grey53 italic]Show VMs Name / UUID[/grey53 italic]\n \
\n[gold bold][3] [grey53 italic]Select VMs by tag / UUID[/grey53 italic]\n \ \n[gold1 bold][3] [grey53 italic]Select VMs by tag / UUID[/grey53 italic]\n \
\n\n[green_yellow bold]ENTER - return to Main Menu[/]" \n\n[green_yellow bold]ENTER - return to Main Menu[/]"
config_menu_options=Align.center(config_menu_options, vertical="middle") config_menu_options=Align.center(config_menu_options, vertical="middle")
console = Console() console = Console()

39
main.py
View File

@@ -7,29 +7,24 @@ from data_pools_api import *
from disk_edit_mode import * from disk_edit_mode import *
from rich.panel import Panel from rich.panel import Panel
from rich.console import Console , Align from rich.console import Console , Align
SVMU_ver="0.4-dev" SVMU_ver="v0.4.4" # pls dont forget to change before uploading release (lol)
# Initialize console and clear screen console = Console() # Initialize console and clear screen
console = Console()
os.system('cls' if os.name=='nt' else 'clear') os.system('cls' if os.name=='nt' else 'clear')
config_relative_path = get_default_config_path() # Get config path + necessery checks
# Initialize config path and ensure it points to a valid profile skip_startup_splash = get_skip_startup_splash(config_relative_path) #check profile for skip startup. Profile is not imported at this point (!)
config_relative_path = get_default_config_path() show_startup_logo(skip_startup_splash, SVMU_ver) #shows / skips startup splash (ASCII art)
# Get initial configuration and show startup screen
skip_startup_splash = get_skip_startup_splash(config_relative_path)
show_startup_logo(skip_startup_splash, SVMU_ver) #shows startup splash (ASCII art)
menu_choice=0 menu_choice=0
while(menu_choice != ""): #main menu loop while(menu_choice != ""): #main menu loop
profile_name = os.path.basename(os.path.splitext(config_relative_path)[0]) #converting full path to pretty file name profile_name = os.path.basename(os.path.splitext(config_relative_path)[0]) #converting full path to pretty file name
skip_startup_splash, base_url, api_key, data_pool_uuid, data_pool_name, vm_uuids, vm_names, disk1_size, disk2_size, disk3_size, disk_interface, preallocation, iso_uuid, iso_name = config_import(config_relative_path) #importing API-KEY / IP / DATA POOL UUID / VM-UUIDs from config skip_startup_splash, base_url, api_key, data_pool_uuid, data_pool_name, vm_uuids, vm_names, disk1_size, disk2_size, disk3_size, disk_interface, preallocation, iso_uuid, iso_name = config_import(config_relative_path) #importing API-KEY / IP / DATA POOL UUID / VM-UUIDs from config
vm_pretty_names = ', '.join(vm_names) vm_pretty_names = ', '.join(vm_names)
menu_options=f"[gold bold][1] [grey53 italic]Utiliy Configuration / Profiles\n[/grey53 italic] \ menu_options=f"[gold1 bold][1] [grey53 italic]Utiliy Configuration / Profiles\n[/grey53 italic] \
\n[gold bold][2] [grey53 italic]Enter disk edit mode[/grey53 italic]\n \ \n[gold1 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[gold1 bold][3] [grey53 italic]Show breif cluster overview[/grey53 italic]\n \
\n[gold bold][4] [grey53 italic]Enter VM menu[/grey53 italic]\n \ \n[gold1 bold][4] [grey53 italic]Enter VM menu[/grey53 italic]\n \
\n[gold bold][5] [grey53 italic]Show data pools[/grey53 italic]\n \ \n[gold1 bold][5] [grey53 italic]Show data pools[/grey53 italic]\n \
\n\n[green_yellow bold]ENTER - exit Utility[/]\n\n \ \n\n[green_yellow bold]ENTER - exit Utility[/]\n\n \
[underline bold grey53]Current profile:[/] [bold green]{profile_name}[/]\n \ [underline bold grey53]Current profile:[/] [bold green]{profile_name}[/]\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_pretty_names}[/]\n Auto-mount ISO: [bright_cyan]{iso_name}[/]" [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_pretty_names}[/]\n Auto-mount ISO: [bright_cyan]{iso_name}[/]"
@@ -39,16 +34,14 @@ while(menu_choice != ""): #main menu loop
menu_choice = console.input("[bold yellow]\n>>> [/]") menu_choice = console.input("[bold yellow]\n>>> [/]")
if menu_choice == "1": if menu_choice == "1":
result = config_menu(base_url, api_key, config_relative_path) new_profile, needs_reload = config_menu(base_url, api_key, config_relative_path)
# Check if we got a new profile path # If a new profile path was returned, switch to it
if isinstance(result, str): if new_profile:
# Update config path and reload config_relative_path = new_profile
config_relative_path = result
os.system('cls' if os.name=='nt' else 'clear') os.system('cls' if os.name=='nt' else 'clear')
continue continue
# Check if we need to reload config # If menu indicated that config changes require a reload, go back to main menu
elif isinstance(result, bool) and result: if needs_reload:
# Clear screen and continue to reload config
os.system('cls' if os.name=='nt' else 'clear') os.system('cls' if os.name=='nt' else 'clear')
continue continue
if menu_choice == "2": if menu_choice == "2":

View File

@@ -22,9 +22,10 @@ def get_skip_startup_splash(config_path):
def show_startup_logo(skip_startup_splash, SVMU_ver): def show_startup_logo(skip_startup_splash, SVMU_ver):
if skip_startup_splash == "yes": if skip_startup_splash == "yes":
return return
splash_file = os.path.join(os.path.dirname(__file__), "splash-screens.txt") splash_dir = os.path.dirname(__file__) # Assume splash file lives in the assets/ directory
splash_file = os.path.join(splash_dir, "assets", "splash-screens.txt")
if not os.path.exists(splash_file): if not os.path.exists(splash_file):
console.print("[bold red]Splash screens file not found![/bold red]") console.print(f"[bold red]No splash file fouond at: {splash_file}[/bold red]")
return return
with open(splash_file, "r", encoding="utf-8") as f: with open(splash_file, "r", encoding="utf-8") as f: