Add stop container
This commit is contained in:
@@ -12,22 +12,6 @@ logger.setLevel(logging.INFO)
|
|||||||
|
|
||||||
WAIT_TIME = 3
|
WAIT_TIME = 3
|
||||||
|
|
||||||
|
|
||||||
def get_vmrun_type(return_list=False):
|
|
||||||
if platform.system() == 'Windows' or platform.system() == 'Linux':
|
|
||||||
if return_list:
|
|
||||||
return ['-T', 'ws']
|
|
||||||
else:
|
|
||||||
return '-T ws'
|
|
||||||
elif platform.system() == 'Darwin': # Darwin is the system name for macOS
|
|
||||||
if return_list:
|
|
||||||
return ['-T', 'fusion']
|
|
||||||
else:
|
|
||||||
return '-T fusion'
|
|
||||||
else:
|
|
||||||
raise Exception("Unsupported operating system")
|
|
||||||
|
|
||||||
|
|
||||||
class DockerProvider(Provider):
|
class DockerProvider(Provider):
|
||||||
def __init__(self, region: str):
|
def __init__(self, region: str):
|
||||||
self.client = docker.from_env()
|
self.client = docker.from_env()
|
||||||
@@ -49,16 +33,24 @@ class DockerProvider(Provider):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def start_emulator(self, path_to_vm: str, headless: bool, os_type: str):
|
def start_emulator(self, path_to_vm: str, headless: bool, os_type: str):
|
||||||
pass
|
self.container = self.client.containers.run('qemux/qemu-docker', environment={"DISK_SIZE": "64G", "RAM_SIZE": "6G", "CPU_CORES": "8"}, volumes={"/Users/happysix/Programs/HKUNLP/Qemu/Ubuntu.qcow2": {"bind": "/Ubuntu.qcow2", "mode": "ro"}, "/Users/happysix/Programs/HKUNLP/Qemu/snapshot.qcow2": {"bind": "/boot.qcow2", "mode": "rw"}}, cap_add=["NET_ADMIN"], ports={8006: 8006, 5000: 5001}, detach=True)
|
||||||
|
|
||||||
def get_ip_address(self, path_to_vm: str) -> str:
|
def get_ip_address(self, path_to_vm: str) -> str:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def save_state(self, path_to_vm: str, snapshot_name: str):
|
def save_state(self, path_to_vm: str, snapshot_name: str):
|
||||||
pass
|
logger.info("Saving VM state...")
|
||||||
|
DockerProvider._execute_command(
|
||||||
|
["qemu-img", "convert", "-O", "qcow2", snapshot_name, "temp.qcow2"])
|
||||||
|
DockerProvider._execute_command(
|
||||||
|
["mv", "temp.qcow2", path_to_vm]
|
||||||
|
)
|
||||||
|
time.sleep(WAIT_TIME) # Wait for the VM to save
|
||||||
|
|
||||||
def revert_to_snapshot(self, path_to_vm: str, snapshot_name: str):
|
def revert_to_snapshot(self, path_to_vm: str, snapshot_name: str):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def stop_emulator(self, path_to_vm: str):
|
def stop_emulator(self, path_to_vm: str):
|
||||||
pass
|
logger.info("Stopping VMware VM...")
|
||||||
|
self.container.stop(WAIT_TIME)
|
||||||
|
self.container.remove()
|
||||||
Reference in New Issue
Block a user