From 1bb760d3f0c0118dcb93e1590f3dff16930b86f7 Mon Sep 17 00:00:00 2001 From: Julien Duponchelle Date: Fri, 11 Nov 2016 11:41:16 +0100 Subject: [PATCH] Make logs for searching GNS3 VM vmware IP less noisy Fix #765 --- gns3server/compute/vmware/__init__.py | 10 +++++----- gns3server/controller/gns3vm/__init__.py | 1 - gns3server/controller/gns3vm/vmware_gns3_vm.py | 8 +++++--- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/gns3server/compute/vmware/__init__.py b/gns3server/compute/vmware/__init__.py index ce930172..5a9510eb 100644 --- a/gns3server/compute/vmware/__init__.py +++ b/gns3server/compute/vmware/__init__.py @@ -357,19 +357,19 @@ class VMware(BaseManager): return self._host_type @asyncio.coroutine - def execute(self, subcommand, args, timeout=120): + def execute(self, subcommand, args, timeout=120, log_level=logging.INFO): try: - return (yield from self._execute(subcommand, args, timeout=timeout)) + return (yield from self._execute(subcommand, args, timeout=timeout, log_level=log_level)) except VMwareError as e: # We can fail to detect that it's VMware player instead of Workstation (due to marketing change Player is now Player Workstation) if self.host_type == "ws" and "VIX_SERVICEPROVIDER_VMWARE_WORKSTATION" in str(e): self._host_type = "player" - return (yield from self._execute(subcommand, args, timeout=timeout)) + return (yield from self._execute(subcommand, args, timeout=timeout, log_level=log_level)) else: raise e @asyncio.coroutine - def _execute(self, subcommand, args, timeout=120): + def _execute(self, subcommand, args, timeout=120, log_level=logging.INFO): if self.host_type is None: yield from self.check_vmware_version() @@ -380,7 +380,7 @@ class VMware(BaseManager): command = [vmrun_path, "-T", self.host_type, subcommand] command.extend(args) command_string = " ".join(command) - log.info("Executing vmrun with command: {}".format(command_string)) + log.log(log_level, "Executing vmrun with command: {}".format(command_string)) try: process = yield from asyncio.create_subprocess_exec(*command, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE) except (OSError, subprocess.SubprocessError) as e: diff --git a/gns3server/controller/gns3vm/__init__.py b/gns3server/controller/gns3vm/__init__.py index f1d849a5..9a1cba3e 100644 --- a/gns3server/controller/gns3vm/__init__.py +++ b/gns3server/controller/gns3vm/__init__.py @@ -279,7 +279,6 @@ class GNS3VM: port=self.port, user=self.user, password=self.password) - print(compute.password) @locked_coroutine def _suspend(self): diff --git a/gns3server/controller/gns3vm/vmware_gns3_vm.py b/gns3server/controller/gns3vm/vmware_gns3_vm.py index 33085d64..927fc95e 100644 --- a/gns3server/controller/gns3vm/vmware_gns3_vm.py +++ b/gns3server/controller/gns3vm/vmware_gns3_vm.py @@ -44,10 +44,10 @@ class VMwareGNS3VM(BaseGNS3VM): return self._vmx_path @asyncio.coroutine - def _execute(self, subcommand, args, timeout=60): + def _execute(self, subcommand, args, timeout=60, log_level=logging.INFO): try: - result = yield from self._vmware_manager.execute(subcommand, args, timeout) + result = yield from self._vmware_manager.execute(subcommand, args, timeout, log_level=log_level) return (''.join(result)) except VMwareError as e: raise GNS3VMError("Error while executing VMware command: {}".format(e)) @@ -132,14 +132,16 @@ class VMwareGNS3VM(BaseGNS3VM): # get the guest IP address (first adapter only) trial = 120 guest_ip_address = "" + log.info("Waiting for GNS3 VM IP") while True: - guest_ip_address = yield from self._execute("readVariable", [self._vmx_path, "guestVar", "gns3.eth0"], timeout=120) + guest_ip_address = yield from self._execute("readVariable", [self._vmx_path, "guestVar", "gns3.eth0"], timeout=120, log_level=logging.DEBUG) guest_ip_address = guest_ip_address.strip() if len(guest_ip_address) != 0: break trial -= 1 # If ip not found fallback on old method if trial == 0: + log.warn("No IP found for the VM via readVariable fallback to getGuestIPAddress") guest_ip_address = yield from self._execute("getGuestIPAddress", [self._vmx_path, "-wait"], timeout=120) break yield from asyncio.sleep(1)