mirror of
https://github.com/OVERLORD7F/SVMU.git
synced 2025-10-01 21:52:47 +03:00
Expanding config-related functions
- New function change_vm_uuids - New function change_data_pool
This commit is contained in:
@@ -10,20 +10,26 @@ from rich.console import Console , Align
|
|||||||
from rich.prompt import Prompt
|
from rich.prompt import Prompt
|
||||||
console = Console()
|
console = Console()
|
||||||
|
|
||||||
def config_menu(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 configuration\n[/grey53 italic] \
|
config_menu_options="[gold bold][1] [grey53 italic]Show current configuration\n[/] \
|
||||||
\n[gold bold][2] [grey53 italic]Change configuraion[/grey53 italic]\n \
|
\n[gold bold][2] [grey53 italic]Setup new config file[/]\n \
|
||||||
\n\n[green_yellow bold]ENTER - return to Main Menu"
|
\n[gold bold][3] [grey53 italic]Change selected data pool[/]\n\
|
||||||
|
\n[gold bold][4] [grey53 italic]Change selected VMs[/]\
|
||||||
|
\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()
|
||||||
console.print(Panel(config_menu_options, title="[gold bold]SpaceVM Utility - Utility Configuration" , border_style="magenta" , width=150 , padding = 2))
|
console.print(Panel(config_menu_options, title="[gold bold]SpaceVM Utility - Utility Configuration" , border_style="magenta" , width=150 , padding = 2))
|
||||||
sub_choice=str(input("\n>>> "))
|
sub_choice=str(input("\n>>> "))
|
||||||
if sub_choice == "1":
|
if sub_choice == "1":
|
||||||
config_show(config_relative_path)
|
config_show(config_relative_path)
|
||||||
config_menu(config_relative_path)
|
config_menu(base_url, api_key, config_relative_path)
|
||||||
if sub_choice == "2":
|
if sub_choice == "2":
|
||||||
config_edit(config_relative_path)
|
config_edit(config_relative_path)
|
||||||
|
if sub_choice == "3":
|
||||||
|
change_data_pool(base_url, api_key, config_relative_path)
|
||||||
|
if sub_choice == "4":
|
||||||
|
change_vm_uuids(config_relative_path)
|
||||||
|
|
||||||
def config_show(config_relative_path):
|
def config_show(config_relative_path):
|
||||||
cls()
|
cls()
|
||||||
@@ -47,14 +53,53 @@ def config_import(config_relative_path):
|
|||||||
vm_list.append(value)
|
vm_list.append(value)
|
||||||
#get pretty name for selected data pool
|
#get pretty name for selected data pool
|
||||||
data_pool_name = get_data_pool_name(base_url , api_key , data_pool_uuid)
|
data_pool_name = get_data_pool_name(base_url , api_key , data_pool_uuid)
|
||||||
|
|
||||||
#get pretty name for selected VMs
|
#get pretty name for selected VMs
|
||||||
vm_names=[]
|
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))
|
||||||
|
|
||||||
return base_url, api_key, data_pool_uuid, data_pool_name, vm_list, vm_names
|
return base_url, api_key, data_pool_uuid, data_pool_name, vm_list, vm_names
|
||||||
|
|
||||||
|
def change_data_pool(base_url, api_key, config_relative_path):
|
||||||
|
cls()
|
||||||
|
show_data_pools(base_url, api_key)
|
||||||
|
new_data_pool_uuid = input("Type NEW Data Pool UUID: ")
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
config.read(config_relative_path)
|
||||||
|
if config.has_section('Data_Pool'):
|
||||||
|
# update data_pool_uuid
|
||||||
|
config.set('Data_Pool', 'data_pool_uuid', new_data_pool_uuid)
|
||||||
|
with open(config_relative_path, 'w') as config_file:
|
||||||
|
config.write(config_file)
|
||||||
|
else:
|
||||||
|
print("No 'Data_Pool' section in config file..")
|
||||||
|
config_show(config_relative_path)
|
||||||
|
|
||||||
|
|
||||||
|
def change_vm_uuids(config_relative_path):
|
||||||
|
config = configparser.ConfigParser()
|
||||||
|
config.read(config_relative_path)
|
||||||
|
# Remove old VM_List section if it exists, then add a fresh one
|
||||||
|
if config.has_section('VM_List'):
|
||||||
|
config.remove_section('VM_List')
|
||||||
|
config.add_section('VM_List')
|
||||||
|
cls()
|
||||||
|
console.print("[yellow bold]Type new VM UUIDs one by one (input ENTER to stop):")
|
||||||
|
x = 0
|
||||||
|
while True:
|
||||||
|
vm_input = input(">> ")
|
||||||
|
if not vm_input:
|
||||||
|
break
|
||||||
|
x += 1
|
||||||
|
config.set('VM_List', f'uuid_{x}', vm_input)
|
||||||
|
|
||||||
|
with open(config_relative_path, 'w') as configfile:
|
||||||
|
config.write(configfile)
|
||||||
|
|
||||||
|
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:")
|
||||||
|
config_show(config_relative_path)
|
||||||
|
|
||||||
|
|
||||||
def config_edit(config_relative_path):
|
def config_edit(config_relative_path):
|
||||||
read_input = input("Create new config file? (Y / N): ")
|
read_input = input("Create new config file? (Y / N): ")
|
||||||
menu_choice = str(read_input)
|
menu_choice = str(read_input)
|
||||||
@@ -67,8 +112,8 @@ def config_edit(config_relative_path):
|
|||||||
while check_api_key(base_url, "jwt " + api_key) != 200:
|
while check_api_key(base_url, "jwt " + api_key) != 200:
|
||||||
api_key = console.input("[bold red]Check and type SpaceVM Controller API Key again: [/]")
|
api_key = console.input("[bold red]Check and type SpaceVM Controller API Key again: [/]")
|
||||||
show_data_pools(base_url, "jwt " + api_key)
|
show_data_pools(base_url, "jwt " + api_key)
|
||||||
|
|
||||||
data_pool_uuid = input("Type Data Pool UUID you wish to use: ")
|
data_pool_uuid = input("Type Data Pool UUID you wish to use: ")
|
||||||
|
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config["General"] = {
|
config["General"] = {
|
||||||
"controller_ip": base_url,
|
"controller_ip": base_url,
|
||||||
@@ -88,7 +133,7 @@ def config_edit(config_relative_path):
|
|||||||
vm_input = input(">> ")
|
vm_input = input(">> ")
|
||||||
if vm_input:
|
if vm_input:
|
||||||
x += 1
|
x += 1
|
||||||
file.write(f"UUID_{x} = {vm_input}\n")
|
file.write(f"uuid_{x} = {vm_input}\n")
|
||||||
|
|
||||||
console.print("[green bold]VM UUIDs have been written in config :pencil:")
|
console.print("[green bold]VM UUIDs have been written in config :pencil:")
|
||||||
console.print("[green bold]Configuration completed ! :white_check_mark:")
|
console.print("[green bold]Configuration completed ! :white_check_mark:")
|
||||||
|
8
main.py
8
main.py
@@ -7,7 +7,11 @@ 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
|
||||||
|
|
||||||
config_relative_path = os.path.join(os.getcwd() , 'SpaceVM_Utility.conf') #config.txt in the same directory with main.py
|
config_relative_path = os.path.join(os.getcwd() , 'SpaceVM_Utility.conf') #config in the same directory with main.py
|
||||||
|
|
||||||
|
print("Reading config from:", os.path.abspath(config_relative_path))
|
||||||
|
if not os.path.exists(config_relative_path):
|
||||||
|
print(f"Config file not found: {config_relative_path}")
|
||||||
|
|
||||||
menu_choice=0
|
menu_choice=0
|
||||||
console = Console()
|
console = Console()
|
||||||
@@ -29,7 +33,7 @@ while(menu_choice != ""): #main menu loop
|
|||||||
console.print(Panel(menu_options, title="[bold magenta]SpaceVM Utility - Main Menu" , subtitle = menu_subtitle, subtitle_align="right" , style="yellow" , width=150 , padding = 2))
|
console.print(Panel(menu_options, title="[bold magenta]SpaceVM Utility - Main Menu" , subtitle = menu_subtitle, subtitle_align="right" , style="yellow" , width=150 , padding = 2))
|
||||||
menu_choice=str(input("\n>>> "))
|
menu_choice=str(input("\n>>> "))
|
||||||
if menu_choice == "1":
|
if menu_choice == "1":
|
||||||
config_menu(config_relative_path)
|
config_menu(base_url, api_key, config_relative_path)
|
||||||
if menu_choice == "2":
|
if menu_choice == "2":
|
||||||
disk_edit_mode(base_url , api_key , data_pool_uuid , vm_uuids)
|
disk_edit_mode(base_url , api_key , data_pool_uuid , vm_uuids)
|
||||||
if menu_choice == "3":
|
if menu_choice == "3":
|
||||||
|
Reference in New Issue
Block a user