From 2c3938b6ab9a0fd46d7f65a69cff79c13794470e Mon Sep 17 00:00:00 2001 From: zohar kabeli Date: Mon, 2 Aug 2021 10:58:40 +0300 Subject: [PATCH] add support for python3 + expose additional capabilities from cli --- vmfusion/__init__.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/vmfusion/__init__.py b/vmfusion/__init__.py index cbf9161..68c5925 100644 --- a/vmfusion/__init__.py +++ b/vmfusion/__init__.py @@ -43,9 +43,9 @@ def __init__( self, bundle_directory=None, vmrun_path=None ): def __vmrun( self, command ): base = [ self.tool_path, '-T', 'fusion' ] base.extend( command ) - + proc = subprocess.Popen( base, stdout=subprocess.PIPE ) - stdout = proc.stdout.readlines() + stdout = [x.decode('utf8') for x in proc.stdout.readlines()] if len(stdout) and stdout[0].startswith('Error'): raise VMRunException(stdout[0]) @@ -62,7 +62,7 @@ def list( self ): # [optional absolute path to VMX n] data = {} data[ 'count' ] = int(output[0].split(':')[1].strip()) - data[ 'machines' ] = [vmx.strip() for vmx in output[1:]] + data[ 'machines' ] = [vmx.strip() for vmx in output[1:]] return data @@ -151,6 +151,9 @@ def delete_snapshot( self, vmx, name ): self.__vmrun( [ 'deleteSnapshot', vmx, name ] ) + def fetch_ipaddress(self, vmx): + vmx = get_abspath( vmx ) + return self.__vmrun( ['getGuestIPAddress', vmx, '-wait'] )[0].strip('\n') class VM(object): """ @@ -194,6 +197,8 @@ def revert_to_snapshot(self, name): def delete_snapshot(self, name): return self.vmrun.delete_snapshot(self.vmx, name) + def fetch_ipaddress(self): + return self.vmrun.fetch_ipaddress(self.vmx) class vdiskmanager_cli( object ): # Valid disks @@ -335,8 +340,8 @@ def load( self ): if mac not in all_leases or lease.starts.datetime > all_leases[mac].starts.datetime: all_leases[ mac ] = lease - except AttributeError, e: - print e + except AttributeError as e: + print(e) for mac in all_leases: all_leases[ mac ] = all_leases[ mac ].ipaddress