mirror of
https://github.com/OVERLORD7F/SVMU.git
synced 2025-10-01 21:52:47 +03:00
- Progress bars for disk delete / create actions
- Changed output for disk edit menu
This commit is contained in:
@@ -52,7 +52,6 @@ def disk_edit_mode(base_url , api_key , data_pool_uuid , vm_uuids):
|
||||
disk_uuids = get_disk_uuids(base_url , api_key , domain_all_content)
|
||||
for y in disk_uuids:
|
||||
delete_disk(base_url , api_key , y)
|
||||
console.print("[bold red]All attached vDisks has been deleted!")
|
||||
for z in vm_uuids: # only for creating disks
|
||||
domain_uuid = z.strip('\n')
|
||||
vm_name = get_vm_name(base_url, api_key, domain_uuid)
|
||||
|
@@ -6,6 +6,7 @@ from rich.console import Console , Align
|
||||
from rich.columns import Columns
|
||||
from rich.panel import Panel
|
||||
from rich.prompt import Prompt
|
||||
from rich.progress import Progress, SpinnerColumn, TextColumn
|
||||
|
||||
console = Console() #necessary for pretty menus & output
|
||||
power_state = ["Unknown" , "Off" , "Suspend" , "On"] #3 - on; 2 - suspend; 1 - off; 0 - unknown
|
||||
@@ -22,7 +23,6 @@ def get_domain_info(base_url , api_key , domain_uuid):
|
||||
print(f"Failed to retrieve data {response.status_code}")
|
||||
|
||||
|
||||
|
||||
def get_domain_all_content(base_url, api_key, domain_uuid):
|
||||
url= f"http://{base_url}/api/domains/{domain_uuid}/all-content"
|
||||
response = requests.get(url , headers={'Authorization' : api_key})
|
||||
@@ -66,9 +66,12 @@ def delete_disk(base_url , api_key , vdisk_uuid):
|
||||
"clean_type": "zero",
|
||||
"clean_count": 1
|
||||
}
|
||||
with Progress(SpinnerColumn(), TextColumn("[progress.description]{task.description}")) as progress:
|
||||
task = progress.add_task("Deleting vDisk...", total=None)
|
||||
response = requests.post(url , headers=headers, json=payload)
|
||||
progress.remove_task(task)
|
||||
if response.status_code == 200:
|
||||
print(f"vDisk {vdisk_uuid} successfully deleted")
|
||||
console.print(f"[grey53 italic]{vdisk_uuid}[/] :wastebasket:")
|
||||
return True
|
||||
else:
|
||||
print(f"ERROR deleting disk {vdisk_uuid} :\n {response.status_code} - {response.text}")
|
||||
@@ -110,6 +113,7 @@ def get_vm_name(base_url, api_key, vm_uuids):
|
||||
vm_name = response.json()
|
||||
return (f"{vm_name['verbose_name']}")
|
||||
|
||||
|
||||
def vm_info(base_url, api_key, vm_uuids):
|
||||
domain_info = get_domain_info(base_url, api_key, vm_uuids)
|
||||
domain_all_content = get_domain_all_content(base_url, api_key, vm_uuids)
|
||||
@@ -126,7 +130,6 @@ def vm_info(base_url, api_key, vm_uuids):
|
||||
console.rule(style="yellow")
|
||||
|
||||
|
||||
|
||||
def vm_info_short(base_url, api_key):
|
||||
url = f"http://{base_url}/api/domains/"
|
||||
response = requests.get(url, headers={'Authorization': api_key})
|
||||
@@ -148,9 +151,10 @@ def vm_info_short(base_url, api_key):
|
||||
Prompt.ask("[green_yellow bold]ENTER - return to Main Menu.... :right_arrow_curving_down:")
|
||||
os.system('cls' if os.name=='nt' else 'clear')
|
||||
|
||||
|
||||
def create_and_attach_disk(base_url , api_key , vm_id, data_pool_uuid, vdisk_size, preallocation):
|
||||
domain_name=get_domain_info(base_url , api_key , vm_id)
|
||||
disk_name=domain_name["verbose_name"]+"_"+secrets.token_hex(5) #generates unique hex id. this method can generate ~million unique ids
|
||||
disk_name=domain_name["verbose_name"] + "_" + secrets.token_hex(5) #generates unique hex id. this method can generate ~million unique ids
|
||||
url = f"http://{base_url}/api/domains/{vm_id}/create-attach-vdisk/"
|
||||
headers={
|
||||
"Authorization" : api_key,
|
||||
@@ -163,9 +167,12 @@ def create_and_attach_disk(base_url , api_key , vm_id, data_pool_uuid, vdisk_siz
|
||||
"datapool": data_pool_uuid,
|
||||
"target_bus": "virtio",
|
||||
}
|
||||
with Progress(SpinnerColumn(), TextColumn("[progress.description]{task.description}")) as progress:
|
||||
task = progress.add_task("Creating and attaching vDisk...", total=None)
|
||||
response = requests.post(url , headers=headers, json=payload)
|
||||
progress.remove_task(task)
|
||||
if response.status_code == 200:
|
||||
print(f"vDisk {disk_name} ({vdisk_size}GB) has been created and attached")
|
||||
console.print(f"[grey53 italic]{disk_name} ({vdisk_size}GB)[/] :white_check_mark:")
|
||||
return True
|
||||
else:
|
||||
print(f"ERROR creating vDisk :\n {response.status_code} - {response.text}")
|
||||
@@ -182,4 +189,5 @@ def vm_check_power(base_url , api_key , vm_uuids):
|
||||
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!")
|
||||
pass
|
||||
#print(f"VM - {vm_uuids} Power check passed!")
|
Reference in New Issue
Block a user