feat&fix: update AWS VM management methods and add AWS provider configuration
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -190,6 +190,7 @@ test2.xlsx
|
|||||||
docker_vm_data
|
docker_vm_data
|
||||||
vmware_vm_data
|
vmware_vm_data
|
||||||
.vmware*
|
.vmware*
|
||||||
|
.aws*
|
||||||
|
|
||||||
# result
|
# result
|
||||||
**/result*/**/*
|
**/result*/**/*
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ class DesktopEnv(gym.Env):
|
|||||||
self.path_to_vm = os.path.abspath(os.path.expandvars(os.path.expanduser(path_to_vm))) \
|
self.path_to_vm = os.path.abspath(os.path.expandvars(os.path.expanduser(path_to_vm))) \
|
||||||
if provider_name in {"vmware", "virtualbox"} else path_to_vm
|
if provider_name in {"vmware", "virtualbox"} else path_to_vm
|
||||||
else:
|
else:
|
||||||
self.path_to_vm = self.manager.get_vm_path(self.os_type, region)
|
self.path_to_vm = self.manager.get_vm_path(os_type=self.os_type, region=region)
|
||||||
|
|
||||||
self.snapshot_name = snapshot_name
|
self.snapshot_name = snapshot_name
|
||||||
self.cache_dir_base: str = cache_dir
|
self.cache_dir_base: str = cache_dir
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ DEFAULT_REGION = "us-east-1"
|
|||||||
# todo: public the AMI images
|
# todo: public the AMI images
|
||||||
IMAGE_ID_MAP = {
|
IMAGE_ID_MAP = {
|
||||||
"us-east-1": "ami-05e7d7bd279ea4f14",
|
"us-east-1": "ami-05e7d7bd279ea4f14",
|
||||||
"ap-east-1": "ami-0c092a5b8be4116f5"
|
"ap-east-1": "ami-0c092a5b8be4116f5",
|
||||||
}
|
}
|
||||||
|
|
||||||
INSTANCE_TYPE = "t3.medium"
|
INSTANCE_TYPE = "t3.medium"
|
||||||
@@ -71,13 +71,13 @@ class AWSVMManager(VMManager):
|
|||||||
self.lock = FileLock(".aws_lck", timeout=60)
|
self.lock = FileLock(".aws_lck", timeout=60)
|
||||||
self.initialize_registry()
|
self.initialize_registry()
|
||||||
|
|
||||||
def initialize_registry(self):
|
def initialize_registry(self, **kwargs):
|
||||||
with self.lock: # Locking during initialization
|
with self.lock: # Locking during initialization
|
||||||
if not os.path.exists(self.registry_path):
|
if not os.path.exists(self.registry_path):
|
||||||
with open(self.registry_path, 'w') as file:
|
with open(self.registry_path, 'w') as file:
|
||||||
file.write('')
|
file.write('')
|
||||||
|
|
||||||
def add_vm(self, vm_path, region=DEFAULT_REGION, lock_needed=True):
|
def add_vm(self, vm_path, region=DEFAULT_REGION, lock_needed=True, **kwargs):
|
||||||
if lock_needed:
|
if lock_needed:
|
||||||
with self.lock:
|
with self.lock:
|
||||||
self._add_vm(vm_path, region)
|
self._add_vm(vm_path, region)
|
||||||
@@ -92,7 +92,7 @@ class AWSVMManager(VMManager):
|
|||||||
with open(self.registry_path, 'w') as file:
|
with open(self.registry_path, 'w') as file:
|
||||||
file.writelines(new_lines)
|
file.writelines(new_lines)
|
||||||
|
|
||||||
def delete_vm(self, vm_path, region=DEFAULT_REGION, lock_needed=True):
|
def delete_vm(self, vm_path, region=DEFAULT_REGION, lock_needed=True, **kwargs):
|
||||||
if lock_needed:
|
if lock_needed:
|
||||||
with self.lock:
|
with self.lock:
|
||||||
self._delete_vm(vm_path, region)
|
self._delete_vm(vm_path, region)
|
||||||
@@ -112,7 +112,7 @@ class AWSVMManager(VMManager):
|
|||||||
with open(self.registry_path, 'w') as file:
|
with open(self.registry_path, 'w') as file:
|
||||||
file.writelines(new_lines)
|
file.writelines(new_lines)
|
||||||
|
|
||||||
def occupy_vm(self, vm_path, pid, region=DEFAULT_REGION, lock_needed=True):
|
def occupy_vm(self, vm_path, pid, region=DEFAULT_REGION, lock_needed=True, **kwargs):
|
||||||
if lock_needed:
|
if lock_needed:
|
||||||
with self.lock:
|
with self.lock:
|
||||||
self._occupy_vm(vm_path, pid, region)
|
self._occupy_vm(vm_path, pid, region)
|
||||||
@@ -132,7 +132,7 @@ class AWSVMManager(VMManager):
|
|||||||
with open(self.registry_path, 'w') as file:
|
with open(self.registry_path, 'w') as file:
|
||||||
file.writelines(new_lines)
|
file.writelines(new_lines)
|
||||||
|
|
||||||
def check_and_clean(self, lock_needed=True):
|
def check_and_clean(self, lock_needed=True, **kwargs):
|
||||||
if lock_needed:
|
if lock_needed:
|
||||||
with self.lock:
|
with self.lock:
|
||||||
self._check_and_clean()
|
self._check_and_clean()
|
||||||
@@ -215,7 +215,7 @@ class AWSVMManager(VMManager):
|
|||||||
# Since this can lead to unexpected delete on other server
|
# Since this can lead to unexpected delete on other server
|
||||||
# PLease do monitor the instances to avoid additional cost
|
# PLease do monitor the instances to avoid additional cost
|
||||||
|
|
||||||
def list_free_vms(self, region=DEFAULT_REGION, lock_needed=True):
|
def list_free_vms(self, region=DEFAULT_REGION, lock_needed=True, **kwargs):
|
||||||
if lock_needed:
|
if lock_needed:
|
||||||
with self.lock:
|
with self.lock:
|
||||||
return self._list_free_vms(region)
|
return self._list_free_vms(region)
|
||||||
@@ -234,7 +234,7 @@ class AWSVMManager(VMManager):
|
|||||||
|
|
||||||
return free_vms
|
return free_vms
|
||||||
|
|
||||||
def get_vm_path(self, region=DEFAULT_REGION):
|
def get_vm_path(self, region=DEFAULT_REGION, **kwargs):
|
||||||
with self.lock:
|
with self.lock:
|
||||||
if not AWSVMManager.checked_and_cleaned:
|
if not AWSVMManager.checked_and_cleaned:
|
||||||
AWSVMManager.checked_and_cleaned = True
|
AWSVMManager.checked_and_cleaned = True
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ MAX_ATTEMPTS = 10
|
|||||||
|
|
||||||
class AWSProvider(Provider):
|
class AWSProvider(Provider):
|
||||||
|
|
||||||
def start_emulator(self, path_to_vm: str, headless: bool):
|
def start_emulator(self, path_to_vm: str, headless: bool, *args, **kwargs):
|
||||||
logger.info("Starting AWS VM...")
|
logger.info("Starting AWS VM...")
|
||||||
ec2_client = boto3.client('ec2', region_name=self.region)
|
ec2_client = boto3.client('ec2', region_name=self.region)
|
||||||
|
|
||||||
|
|||||||
@@ -221,6 +221,10 @@ def test(args: argparse.Namespace, test_all_meta: dict) -> None:
|
|||||||
env = DesktopEnv(
|
env = DesktopEnv(
|
||||||
path_to_vm=args.path_to_vm,
|
path_to_vm=args.path_to_vm,
|
||||||
action_space=agent.action_space,
|
action_space=agent.action_space,
|
||||||
|
|
||||||
|
provider_name="aws",
|
||||||
|
region="us-east-1",
|
||||||
|
|
||||||
screen_size=(args.screen_width, args.screen_height),
|
screen_size=(args.screen_width, args.screen_height),
|
||||||
headless=args.headless,
|
headless=args.headless,
|
||||||
os_type="Ubuntu",
|
os_type="Ubuntu",
|
||||||
|
|||||||
Reference in New Issue
Block a user