mirror of
https://github.com/OVERLORD7F/SVMU.git
synced 2025-10-01 21:52:47 +03:00
- Introducing power-on-check function.
All disk-related operations are available ONLY if VM is powered off.
This commit is contained in:
@@ -7,15 +7,13 @@ def data_pools(base_url , api_key): #output data pool info
|
||||
if response.status_code == 200:
|
||||
data_pools = response.json()
|
||||
results_data_pools_info = data_pools['results']
|
||||
|
||||
print("\nData pools overview:")
|
||||
print(f"\nData pools total: {data_pools['count']}")
|
||||
print("-" * 44)
|
||||
for x in results_data_pools_info:
|
||||
print(f"\nData pool: {x['verbose_name']} ({x['status']})")
|
||||
print(f"type: {x['type']} | Used: {round((x['free_space']/1024), 1)} Gb/{round((x['size'] / 1024), 1)} Gb")
|
||||
print(f"UID: {x['id']}")
|
||||
print("-" * 44)
|
||||
|
||||
print(f"Type: {x['type']} | Used: {round((x['free_space']/1024), 1)} Gb / {round((x['size'] / 1024), 1)} Gb")
|
||||
print(f"UUID: {x['id']}")
|
||||
print("-" * 44)
|
||||
else:
|
||||
print(f"Failed to retrieve data {response.status_code} ")
|
||||
|
@@ -3,7 +3,6 @@
|
||||
|
||||
import requests
|
||||
import secrets #for generating unique names
|
||||
#from main import power_state
|
||||
|
||||
|
||||
power_state = ["Unknown" , "Off" , "Suspend" , "On"] #3 - on; 2 - suspend; 1 - off; 0 - unknown
|
||||
@@ -152,4 +151,17 @@ def create_and_attach_disk(base_url , api_key , vm_id, data_pool_uuid, vdisk_siz
|
||||
return True
|
||||
else:
|
||||
print(f"ERROR creating vDisk :\n {response.status_code} - {response.text}")
|
||||
return False
|
||||
return False
|
||||
|
||||
#checks for power on.
|
||||
def vm_check_power(base_url , api_key , vm_uuids):
|
||||
domain_info = get_domain_info(base_url , api_key , vm_uuids)
|
||||
|
||||
if domain_info:
|
||||
#3 - on; 2 - suspend; 1 - off; 0 - unknown
|
||||
if domain_info['user_power_state'] == 3 or domain_info['user_power_state'] == 2 : #if ON or SUSPEND
|
||||
raise Exception(f"VM - {vm_uuids} IS POWERED ON! \n Turn it off and relaunch Utility.")
|
||||
if domain_info['user_power_state'] == 0:
|
||||
raise Exception(f"VM - {vm_uuids} is UNAVAILABLE! \n Have fun figuring that out D:")
|
||||
if domain_info['user_power_state'] == 1:
|
||||
print(f"VM - {vm_uuids} Power check passed!")
|
13
main.py
13
main.py
@@ -4,11 +4,8 @@ from cluster_api import *
|
||||
from domain_api import *
|
||||
from data_pools_api import *
|
||||
|
||||
#config.txt in the same directory with main.py
|
||||
config_relative_path = os.path.join(os.getcwd() , 'config.txt')
|
||||
print(config_relative_path)
|
||||
#check if config exists and not empty
|
||||
if os.path.exists(config_relative_path) and os.path.getsize(config_relative_path) > 0:
|
||||
config_relative_path = os.path.join(os.getcwd() , 'config.txt') #config.txt in the same directory with main.py
|
||||
if os.path.exists(config_relative_path) and os.path.getsize(config_relative_path) > 0: #check if config exists and not empty
|
||||
pass #do nothing
|
||||
else:
|
||||
print("Config file was not found or empty.. ")
|
||||
@@ -53,6 +50,7 @@ while(menu_choice != ""): #main menu loop
|
||||
if sub_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
|
||||
vm_check_power(vm_uuids[select_uuids]) #power on check
|
||||
domain_all_content = get_domain_all_content(base_url , api_key , vm_uuids[select_uuids])
|
||||
disk_uuids = get_disk_uuids(base_url , api_key , domain_all_content)
|
||||
for x in disk_uuids:
|
||||
@@ -66,6 +64,9 @@ while(menu_choice != ""): #main menu loop
|
||||
|
||||
if sub_choice == "4":
|
||||
print("#" * 5 , "Preparing VMs for Courses" , "#" * 5)
|
||||
for y in vm_uuids: #power-on check
|
||||
domain_uuid = y.strip('\n')
|
||||
vm_check_power(base_url , api_key , domain_uuid)
|
||||
for x in vm_uuids: # only for removing disks
|
||||
domain_uuid = x.strip('\n')
|
||||
domain_info = get_domain_info(base_url , api_key , domain_uuid)
|
||||
@@ -94,5 +95,5 @@ while(menu_choice != ""): #main menu loop
|
||||
if menu_choice == "5":
|
||||
data_pools(base_url , api_key)
|
||||
if menu_choice == "6":
|
||||
vm_info_short(base_url , api_key)
|
||||
vm_info_short(base_url , api_key)
|
||||
print("Exiting Utility..")
|
Reference in New Issue
Block a user