Improve the logic in auto-installation

This commit is contained in:
Timothyxxx
2024-05-16 18:47:37 +08:00
parent 09ffcc8542
commit e1e44d77c5

View File

@@ -286,7 +286,7 @@ def _install_virtual_machine(vm_name, vms_dir, downloaded_file_name, original_vm
def start_vm(vm_path, max_retries=20):
command = f'vmrun {get_vmrun_type()} start "{vm_path}" nogui'
for attempt in range(max_retries):
result = subprocess.run(command, shell=True, text=True, capture_output=True)
result = subprocess.run(command, shell=True, text=True, capture_output=True, encoding="utf-8")
if result.returncode == 0:
print("Virtual machine started.")
return True
@@ -306,7 +306,7 @@ def _install_virtual_machine(vm_name, vms_dir, downloaded_file_name, original_vm
def get_vm_ip(vm_path, max_retries=20):
command = f'vmrun {get_vmrun_type()} getGuestIPAddress "{vm_path}" -wait'
for attempt in range(max_retries):
result = subprocess.run(command, shell=True, text=True, capture_output=True)
result = subprocess.run(command, shell=True, text=True, capture_output=True, encoding="utf-8")
if result.returncode == 0:
return result.stdout.strip()
else:
@@ -347,7 +347,7 @@ def _install_virtual_machine(vm_name, vms_dir, downloaded_file_name, original_vm
def create_vm_snapshot(vm_path, max_retries=20):
command = f'vmrun {get_vmrun_type()} snapshot "{vm_path}" "init_state"'
for attempt in range(max_retries):
result = subprocess.run(command, shell=True, text=True, capture_output=True)
result = subprocess.run(command, shell=True, text=True, capture_output=True, encoding="utf-8")
if result.returncode == 0:
print("Snapshot created.")
return True