def list_vms(self):
        """
        Gets VMware VM list.
        """

        # check for the right VMware version
        yield from self.check_vmware_version()
        vmware_vms = []
        inventory_path = self.get_vmware_inventory_path()
        if os.path.exists(inventory_path) and self.host_type != "player":
            # inventory may exist for VMware player if VMware workstation has been previously installed
            vmware_vms = self._get_vms_from_inventory(inventory_path)
        if not vmware_vms:
            # backup methods when no VMware inventory file exists or for VMware player which has no inventory file
            vmware_preferences_path = self.get_vmware_preferences_path()
            pairs = {}
            if os.path.exists(vmware_preferences_path):
                # the default vm path may be present in VMware preferences file.
                try:
                    pairs = self.parse_vmware_file(vmware_preferences_path)
                except OSError as e:
                    log.warning('Could not read VMware preferences file "{}": {}'.format(vmware_preferences_path, e))
                if "prefvmx.defaultvmpath" in pairs:
                    default_vm_path = pairs["prefvmx.defaultvmpath"]
                    if not os.path.isdir(default_vm_path):
                        raise VMwareError('Could not find or access the default VM directory: "{default_vm_path}". Please change "prefvmx.defaultvmpath={default_vm_path}" in "{vmware_preferences_path}"'.format(default_vm_path=default_vm_path,
                                                                                                                                                                                                                  vmware_preferences_path=vmware_preferences_path))
                    vmware_vms = self._get_vms_from_directory(default_vm_path)

            if not vmware_vms:
                # the default vm path is not in the VMware preferences file or that directory is empty
                # let's search the default locations for VMs
                for default_vm_path in self.get_vmware_default_vm_paths():
                    if os.path.isdir(default_vm_path):
                        vmware_vms.extend(self._get_vms_from_directory(default_vm_path))

            if not vmware_vms:
                log.warning("Could not find any VMware VM in default locations")

            # look for VMX paths in the preferences file in case not all VMs are in a default directory
            for key, value in pairs.items():
                m = re.match(r'pref.mruVM(\d+)\.filename', key)
                if m:
                    display_name = "pref.mruVM{}.displayName".format(m.group(1))
                    if display_name in pairs:
                        found = False
                        for vmware_vm in vmware_vms:
                            if vmware_vm["vmname"] == display_name:
                                found = True
                        if found is False:
                            vmware_vms.append({"vmname": pairs[display_name], "vmx_path": value})
        return vmware_vms
def list_vms ( self ) : yield from self . check_vmware_version ( ) vmware_vms = [ ] inventory_path = self . get_vmware_inventory_path ( ) if os . path . exists ( inventory_path ) and self . host_type != "player" : vmware_vms = self . _get_vms_from_inventory ( inventory_path ) if not vmware_vms : vmware_preferences_path = self . get_vmware_preferences_path ( ) pairs = { } if os . path . exists ( vmware_preferences_path ) : try : pairs = self . parse_vmware_file ( vmware_preferences_path ) except OSError as e : log . warning ( 'Could not read VMware preferences file "{}": {}' . format ( vmware_preferences_path , e ) ) if "prefvmx.defaultvmpath" in pairs : default_vm_path = pairs [ "prefvmx.defaultvmpath" ] if not os . path . isdir ( default_vm_path ) : raise VMwareError ( 'Could not find or access the default VM directory: "{default_vm_path}". Please change "prefvmx.defaultvmpath={default_vm_path}" in "{vmware_preferences_path}"' . format ( default_vm_path = default_vm_path , vmware_preferences_path = vmware_preferences_path ) ) vmware_vms = self . _get_vms_from_directory ( default_vm_path ) if not vmware_vms : for default_vm_path in self . get_vmware_default_vm_paths ( ) : if os . path . isdir ( default_vm_path ) : vmware_vms . extend ( self . _get_vms_from_directory ( default_vm_path ) ) if not vmware_vms : log . warning ( "Could not find any VMware VM in default locations" ) for key , value in pairs . items ( ) : m = re . match ( r'pref.mruVM(\d+)\.filename' , key ) if m : display_name = "pref.mruVM{}.displayName" . format ( m . group ( 1 ) ) if display_name in pairs : found = False for vmware_vm in vmware_vms : if vmware_vm [ "vmname" ] == display_name : found = True if found is False : vmware_vms . append ( { "vmname" : pairs [ display_name ] , "vmx_path" : value } ) return vmware_vms
Gets VMware VM list.