mirror of
https://github.com/OVERLORD7F/SVMU.git
synced 2025-10-01 21:52:47 +03:00
Add files via upload
- vm uuids, data pool uuid is now stored only in config - only config.txt is required, ALL other subsidiary .txt files no longer beeing used - fixed vm_info function
This commit is contained in:
58
pyth-api1.py
58
pyth-api1.py
@@ -12,30 +12,37 @@ VM_UUID_relative_path = "Y:\\py\\VM-UUIDs.txt"
|
||||
|
||||
|
||||
|
||||
#importing API-KEY and ip address from config file
|
||||
#importing API-KEY / IP / DATA POOL UUID from config
|
||||
with open(config_relative_path, "r") as f: # using '\' (instead of '\\') throws syntax warning
|
||||
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 ONLY 1st entry in VM-UUIDs file
|
||||
with open(VM_UUID_relative_path, "r") as f:
|
||||
vm_uuids = f.readline().strip('\n')
|
||||
data_pool_uuid = all_lines[2].strip('\n')
|
||||
#print(f"data-pool-uuid - {data_pool_uuid}")
|
||||
|
||||
|
||||
#importing VM-UUIDs
|
||||
vm_uuids = []
|
||||
with open(config_relative_path, "r") as f:
|
||||
for i in range(3): # ignoring 2 first lines (IP, API-KEY)
|
||||
next(f)
|
||||
for line in f:
|
||||
line = line.strip('\n')
|
||||
if line: # checks if line is empty (EOF). ESSENTIAL, DO NOT REMOVE
|
||||
vm_uuids.append(line)
|
||||
print(f"vm uuids {vm_uuids}")
|
||||
|
||||
|
||||
|
||||
#importing data_pool_uuid from file
|
||||
#selected data pool will be used for new disks and alike
|
||||
with open("Y:\\py\\data-pool.txt", "r") as f:
|
||||
data_pool_uuid = f.readline()
|
||||
|
||||
def config_edit():
|
||||
read_input=input("Create new config file? (Y / N): ")
|
||||
menu_choice=str(read_input)
|
||||
if menu_choice == "Y" or menu_choice == "y":
|
||||
base_url = input("Type ip address: ")
|
||||
api_key = input("Type integration key: ")
|
||||
lines = [base_url, api_key]
|
||||
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]
|
||||
with open(config_relative_path, "w+") as file:
|
||||
for line in lines:
|
||||
file.write(line + '\n')
|
||||
@@ -205,7 +212,7 @@ def vm_info (vm_uuids):
|
||||
|
||||
#so-called INT MAIN
|
||||
menu_choice=0
|
||||
while(menu_choice != ""):
|
||||
while(menu_choice != ""): #main menu loop
|
||||
read_input=input("\nUitility Main Menu: \n1) Edit config \n2) Enter disk edit mode \n3) Show breif cluster overview \n4) Show VM info \n>>> ")
|
||||
menu_choice=str(read_input)
|
||||
|
||||
@@ -231,13 +238,11 @@ while(menu_choice != ""):
|
||||
create_and_attach_disk(vm_uuids , data_pool_uuid, menu_choice, "falloc")
|
||||
if menu_choice == 4:
|
||||
print("#" * 5 , "Preparing VMs for Courses" , "#" * 5)
|
||||
with open(VM_UUID_relative_path, "r") as f:
|
||||
for x in f: # only for removing disks
|
||||
|
||||
#with open(VM_UUID_relative_path, "r") as f:
|
||||
for x in vm_uuids: # only for removing disks
|
||||
domain_uuid = x.strip('\n')
|
||||
domain_info = get_domain_info(domain_uuid)
|
||||
domain_all_content = get_domain_all_content(domain_uuid)
|
||||
|
||||
if domain_info:
|
||||
print("=" * 14 , "Virtual Machine Info" , "=" * 15)
|
||||
print(f"\t VM: {domain_info['verbose_name']}")
|
||||
@@ -249,12 +254,11 @@ while(menu_choice != ""):
|
||||
for y in disk_uuids:
|
||||
delete_disk(y)
|
||||
print("All attached vDisks has been deleted!")
|
||||
with open(VM_UUID_relative_path, "r") as f:
|
||||
for z in f: # only for creating disks
|
||||
#with open(VM_UUID_relative_path, "r") as f:
|
||||
for z in vm_uuids: # only for creating disks
|
||||
domain_uuid = z.strip('\n')
|
||||
domain_info = get_domain_info(domain_uuid)
|
||||
domain_all_content = get_domain_all_content(domain_uuid)
|
||||
|
||||
if domain_info:
|
||||
create_and_attach_disk(domain_uuid , data_pool_uuid, 10, "falloc")
|
||||
create_and_attach_disk(domain_uuid , data_pool_uuid, 20, "falloc")
|
||||
@@ -264,15 +268,13 @@ while(menu_choice != ""):
|
||||
cluster_info()
|
||||
|
||||
if menu_choice == "4":
|
||||
with open(config_relative_path , 'r') as f:
|
||||
for i in range(2): # ignoring 2 first lines (IP, API-KEY)
|
||||
next(f)
|
||||
for line in f:
|
||||
#print(line.strip('\n'))
|
||||
vm_info(line.strip()) # strip with no args - removes '\n' and spaces
|
||||
print("\033[H\033[2J", end="")
|
||||
print(f"vm uuids - {vm_uuids}")
|
||||
for x in vm_uuids:
|
||||
vm_info(x)
|
||||
|
||||
|
||||
|
||||
# HOW - TO EOF ?????
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user