read_input=input("Create new config file? (Y / N): ")
menu_choice=str(read_input)
ifmenu_choice=="Y"ormenu_choice=="y":
base_url=input("Type SpaceVM Controller IP: ")
api_key=input("Type your API Key: ")
data_pool_uuid=input("Type Data pool uuid you wish to use: ")
lines=[base_url,api_key,data_pool_uuid]
withopen(config_relative_path,"w+")asfile:
forlineinlines:
file.write(line+'\n')
print("Type VM-UUID (input ENTER to stop)")
withopen(config_relative_path,"a")asfile:#appends new content at the end without modifying the existing data
vm_input="test"
while(vm_input!=""):
vm_input=input(">> ")
file.write(vm_input+'\n')
print("UUIDs has been written in config")
print("\nConfiguration completed!")
ifos.path.exists(config_relative_path)andos.path.getsize(config_relative_path)>0:#check if file exists and not empty
pass#do nothing
else:
print("Config file was not found or empty.. ")
config_edit()
#importing API-KEY / IP / DATA POOL UUID from config
withopen(config_relative_path,"r")asf:
all_lines=f.readlines()
base_url=all_lines[0].strip('\n')
api_key="jwt "+all_lines[1].strip('\n')#actual format for api_key. That was realy obvious DACOM >:C
data_pool_uuid=all_lines[2].strip('\n')
#importing VM-UUIDs
vm_uuids=[]
withopen(config_relative_path,"r")asf:
foriinrange(3):# ignoring 2 first lines (IP, API-KEY)
next(f)
forlineinf:
line=line.strip('\n')
ifline:# checks if line is empty (EOF). ESSENTIAL, DO NOT REMOVE
vm_uuids.append(line)
#so-called INT MAIN
menu_choice=0
while(menu_choice!=""):#main menu loop
read_input=input("\nUitility Main Menu: \n1) Manage utility config \n2) Enter disk edit mode \n3) Show breif cluster overview \n4) Show VM info \n>>> ")
menu_choice=str(read_input)
ifmenu_choice=="1":
print("\033[H\033[2J",end="")# clears cmd screen, but saves scrollback buffer
print("1) Show current configuration \n2) Change configuraion")
read_input=input(">> ")
menu_choice=int(read_input)
ifmenu_choice==1:
print("Current configuration:\n")
withopen(config_relative_path,"r")asf:
print(f.read())
ifmenu_choice==2:
config_edit()
ifmenu_choice=="2":
print("\033[H\033[2J",end="")
print("Select option: \n 1) Delete vDisk by UUID \n 2) Delete ALL vDisks on selected Virtual Machine \n 3) Create Disk \n 4) Prepare VMs for Courses™")
read_input=input(">> ")
menu_choice=int(read_input)
ifmenu_choice==1:
read_input=input("Input vDisk uuid to delete: ")
vdisk_uuid=str(read_input)
delete_disk(base_url,api_key,vdisk_uuid)
ifmenu_choice==2:
print(vm_uuids)
select_uuids=int(input("Select VM to delete disks from. \n Type VM uuid index number (from list above) to select: "))-1