From 5518164c15d95c8a09d3ceafc20b4942524f5bbd Mon Sep 17 00:00:00 2001 From: Ahmad Bilal Khalid Date: Thu, 4 Jul 2019 13:09:29 +0500 Subject: [PATCH] --vm added to detect if it is running on vm --- main.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 05e4bc3..0dc00cd 100644 --- a/main.py +++ b/main.py @@ -18,12 +18,14 @@ from etcd3_wrapper import Etcd3Wrapper from decouple import config -def get_vm_start_cmd(owner_dir, vm_uuid): +def get_vm_start_cmd(owner_dir, vm_uuid, vm=False): vm_sock_flags = f"-qmp unix:{owner_dir}/.vm/{vm_uuid}-sock,server,nowait" vm_start_command_flags = ( f"-boot c -net nic -net user -m 256 {vm_sock_flags} -daemonize" ) vm_start_command = f"""qemu-system-x86_64 {owner_dir}/.vm/{vm_uuid}.raw {vm_start_command_flags}""" + if vm: + vm_start_command += " -display none" return vm_start_command @@ -36,7 +38,7 @@ def get_qemu_mon(sock_file): return m -def main(hostname): +def main(hostname, is_vm): client = Etcd3Wrapper() events = client.watch_prefix("/v1/vm/") @@ -109,7 +111,7 @@ def main(hostname): else: print("Starting VM") subprocess.run( - get_vm_start_cmd(owner_dir, vm_uuid).split(" ") + get_vm_start_cmd(owner_dir, vm_uuid, is_vm).split(" ") ) e.value["status"] = "RUNNING" client.put(e.key, e.value, value_in_json=True) @@ -119,6 +121,7 @@ def main(hostname): argparser = argparse.ArgumentParser() argparser.add_argument("hostname", help="Name of this host. e.g /v1/host/1") +argparser.add_argument("--vm", type=bool, default=False) args = argparser.parse_args() -main(args.hostname) +main(args.hostname, args.vm)