Add os_type param to VBox manager (#85)

This commit is contained in:
HappySix
2024-10-25 14:46:09 +08:00
committed by GitHub
parent 9229c44393
commit 900b511422
2 changed files with 8 additions and 5 deletions

View File

@@ -144,7 +144,7 @@ If you wish to run the baseline agent used in our paper, you can execute the fol
Set **OPENAI_API_KEY** environment variable with your API key
```bash
export OPENAI_API_KEY='changme'
export OPENAI_API_KEY='changeme'
```
```bash

View File

@@ -33,10 +33,10 @@ if platform.system() == 'Windows':
os.environ["PATH"] += os.pathsep + vboxmanage_path
def generate_new_vm_name(vms_dir):
def generate_new_vm_name(vms_dir, os_type):
registry_idx = 0
while True:
attempted_new_name = f"Ubuntu{registry_idx}"
attempted_new_name = f"{os_type}{registry_idx}"
if os.path.exists(
os.path.join(vms_dir, attempted_new_name, attempted_new_name, attempted_new_name + ".vbox")):
registry_idx += 1
@@ -428,7 +428,10 @@ class VirtualBoxVMManager(VMManager):
free_vms.append((vm_path, pid_str))
return free_vms
def get_vm_path(self, region=None):
def get_vm_path(self, os_type, region=None):
if os_type != "Ubuntu":
raise ValueError("Only support Ubuntu for now.")
with self.lock:
if not VirtualBoxVMManager.checked_and_cleaned:
VirtualBoxVMManager.checked_and_cleaned = True
@@ -448,7 +451,7 @@ class VirtualBoxVMManager(VMManager):
if allocation_needed:
logger.info("No free virtual machine available. Generating a new one, which would take a while...☕")
new_vm_name = generate_new_vm_name(vms_dir=VMS_DIR)
new_vm_name = generate_new_vm_name(vms_dir=VMS_DIR, os_type=os_type)
new_vm_path = _install_vm(new_vm_name, vms_dir=VMS_DIR,
downloaded_file_name=DOWNLOADED_FILE_NAME,
bridged_adapter_name=region)