mirror of
https://github.com/OVERLORD7F/SVMU.git
synced 2025-10-01 21:52:47 +03:00
- option to auto-attach ISO to VMs #20
- added splash screen (ASCII ART) option to skip #21 - Implemented disk options as variables from config #19 - Related changes in config creation / editing menus
This commit is contained in:
@@ -16,7 +16,9 @@ def config_menu(base_url, api_key, config_relative_path):
|
||||
\n[gold bold][1] [grey53 italic]Show current configuration\n[/] \
|
||||
\n[gold bold][2] [grey53 italic]Setup new config file[/]\n \
|
||||
\n[gold bold][3] [grey53 italic]Change selected data pool[/]\n\
|
||||
\n[gold bold][4] [grey53 italic]Change selected VMs[/]\
|
||||
\n[gold bold][4] [grey53 italic]Change selected VMs[/]\n\
|
||||
\n[gold bold][5] [grey53 italic]Change ISO UUID (auto-mount)[/]\n\
|
||||
\n[gold bold][6] [grey53 italic]Skip start-up splash[/]\n\
|
||||
\n\n[green_yellow bold]ENTER - return to Main Menu[/]"
|
||||
config_menu_options=Align.center(config_menu_options, vertical="middle")
|
||||
console = Console()
|
||||
@@ -33,10 +35,15 @@ def config_menu(base_url, api_key, config_relative_path):
|
||||
change_data_pool(base_url, api_key, config_relative_path)
|
||||
if sub_choice == "4":
|
||||
change_vm_uuids(config_relative_path)
|
||||
if sub_choice == "5":
|
||||
change_iso_uuid(config_relative_path)
|
||||
if sub_choice == "6":
|
||||
change_startup_option(config_relative_path)
|
||||
|
||||
def config_show_example():
|
||||
conf_example= """
|
||||
[General]
|
||||
skip_startup_splash = no
|
||||
#Master Controller IP of your cluster
|
||||
#Has to be accessible for a machine, which will be executing this Utility
|
||||
controller_ip = 10.20.30.44
|
||||
@@ -61,6 +68,20 @@ data_pool_uuid =
|
||||
uuid_1 =
|
||||
uuid_2 =
|
||||
|
||||
[VM_Options]
|
||||
#Select interface which will be used in virtual disk creation.
|
||||
#Available options: virtio / ide / scsi / sata
|
||||
disk_interface = virtio
|
||||
|
||||
#Select allocation type for virtual disks
|
||||
#Available options: none / falloc / full / metadata
|
||||
preallocation = falloc
|
||||
|
||||
#Specify uuid of iso you wish to automatically mount to Virtual Machines during operations (Courses)
|
||||
#This step is skipped if "none" provided
|
||||
iso_uuid = none
|
||||
|
||||
|
||||
[Courses-Space-VM]
|
||||
#Set vDisk size for "Prepare VMs for Courses™" option
|
||||
disk1 = 10
|
||||
@@ -74,6 +95,7 @@ disk3 = 20
|
||||
Prompt.ask("[green_yellow bold]ENTER - return to Utility Configuration.. :right_arrow_curving_down:")
|
||||
|
||||
def config_show(config_relative_path):
|
||||
|
||||
cls()
|
||||
console.rule(title = "Current configuration" , align="center" , style="yellow")
|
||||
with open(config_relative_path, "r") as f:
|
||||
@@ -85,15 +107,38 @@ def config_import(config_relative_path):
|
||||
config = configparser.ConfigParser()
|
||||
config.read(config_relative_path)
|
||||
|
||||
skip_startup_splash = config.get('General', 'skip_startup_splash')
|
||||
base_url = config.get('General', 'controller_ip')
|
||||
api_key = "jwt " + config.get('General', 'api_key') #That was realy obvious DACOM >:C
|
||||
data_pool_uuid = config.get('Data_Pool', 'data_pool_uuid')
|
||||
|
||||
|
||||
vm_list = []
|
||||
if 'VM_List' in config:
|
||||
for key, value in config['VM_List'].items():
|
||||
vm_list.append(value)
|
||||
|
||||
#importing VM_Options
|
||||
if config.has_section('VM_Options'):
|
||||
iso_uuid = config.get('VM_Options' , 'iso_uuid')
|
||||
disk_interface = config.get('VM_Options' , 'disk_interface')
|
||||
preallocation = config.get('VM_Options' , 'preallocation')
|
||||
iso_name=get_iso_name(base_url, api_key, iso_uuid)
|
||||
else:
|
||||
console.print("[bold yellow]Applying default values to Virtual Machine Options")
|
||||
iso_uuid = "none"
|
||||
disk_interface = "virtio"
|
||||
preallocation = "falloc"
|
||||
iso_name= "none"
|
||||
config = configparser.ConfigParser() #writing default values to config
|
||||
config["VM_Options"] = {
|
||||
"disk_interface": "virtio",
|
||||
"preallocation": "falloc",
|
||||
"iso_uuid": "none",
|
||||
}
|
||||
with open(config_relative_path, "a") as configfile: # appending to existing config file
|
||||
config.write(configfile)
|
||||
|
||||
#importing disk sizes for SpaceVM courses
|
||||
if config.has_section('Courses-Space-VM'):
|
||||
disk1_size = config.get('Courses-Space-VM', 'disk1')
|
||||
@@ -117,7 +162,22 @@ def config_import(config_relative_path):
|
||||
vm_names=[]
|
||||
for x in vm_list:
|
||||
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, disk1_size, disk2_size, disk3_size
|
||||
|
||||
return skip_startup_splash, base_url, api_key, data_pool_uuid, data_pool_name, vm_list, vm_names, disk1_size, disk2_size, disk3_size, disk_interface, preallocation, iso_uuid, iso_name
|
||||
|
||||
def change_startup_option(config_relative_path):
|
||||
cls()
|
||||
console.print("[yellow bold]Skip start-up splash ?")
|
||||
new_value = Prompt.ask("Type your choice", choices=["yes", "no"], default="no")
|
||||
config = configparser.ConfigParser()
|
||||
config.read(config_relative_path)
|
||||
if config.has_section('General'):
|
||||
config.set('General', 'skip_startup_splash', new_value)
|
||||
with open(config_relative_path, 'w') as config_file:
|
||||
config.write(config_file)
|
||||
console.print(f"[green bold]Option set to: {new_value}")
|
||||
else:
|
||||
console.print("[red bold]No section 'General' in config file")
|
||||
|
||||
def change_data_pool(base_url, api_key, config_relative_path): #change selected data pool in config
|
||||
cls()
|
||||
@@ -133,6 +193,18 @@ def change_data_pool(base_url, api_key, config_relative_path): #change selected
|
||||
print("No 'Data_Pool' section in config file..")
|
||||
config_show(config_relative_path)
|
||||
|
||||
def change_iso_uuid(config_relative_path):
|
||||
cls()
|
||||
new_iso_uuid = input("Type ISO UUID: ")
|
||||
config = configparser.ConfigParser()
|
||||
config.read(config_relative_path)
|
||||
if config.has_section('VM_Options'):
|
||||
config.set('VM_Options', 'iso_uuid', new_iso_uuid)
|
||||
with open(config_relative_path, 'w') as config_file:
|
||||
config.write(config_file)
|
||||
else:
|
||||
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
|
||||
config = configparser.ConfigParser()
|
||||
@@ -177,10 +249,20 @@ def config_edit(config_relative_path):
|
||||
config["General"] = {
|
||||
"controller_ip": base_url,
|
||||
"api_key": api_key,
|
||||
"skip_startup_splash": "no",
|
||||
}
|
||||
config["Data_Pool"] = {"data_pool_uuid": data_pool_uuid}
|
||||
|
||||
with open(config_relative_path, "w") as configfile:
|
||||
#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)")
|
||||
|
Reference in New Issue
Block a user