mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
parent
4a53c7789d
commit
a577fe9fdb
@ -218,7 +218,7 @@ class VMware(BaseManager):
|
||||
for line in f.read().splitlines():
|
||||
try:
|
||||
key, value = line.split('=', 1)
|
||||
pairs[key.strip()] = value.strip('" ')
|
||||
pairs[key.strip().lower()] = value.strip('" ')
|
||||
except ValueError:
|
||||
continue
|
||||
return pairs
|
||||
@ -276,16 +276,16 @@ class VMware(BaseManager):
|
||||
vm_entry, variable_name = key.split('.', 1)
|
||||
except ValueError:
|
||||
continue
|
||||
if not vm_entry in vm_entries:
|
||||
if vm_entry not in vm_entries:
|
||||
vm_entries[vm_entry] = {}
|
||||
vm_entries[vm_entry][variable_name.strip()] = value
|
||||
except OSError as e:
|
||||
log.warning("Could not read VMware inventory file {}: {}".format(inventory_path, e))
|
||||
|
||||
for vm_settings in vm_entries.values():
|
||||
if "DisplayName" in vm_settings and "config" in vm_settings:
|
||||
log.debug('Found VM named "{}" with VMX file "{}"'.format(vm_settings["DisplayName"], vm_settings["config"]))
|
||||
vms.append({"vmname": vm_settings["DisplayName"], "vmx_path": vm_settings["config"]})
|
||||
if "displayname" in vm_settings and "config" in vm_settings:
|
||||
log.debug('Found VM named "{}" with VMX file "{}"'.format(vm_settings["displayname"], vm_settings["config"]))
|
||||
vms.append({"vmname": vm_settings["displayname"], "vmx_path": vm_settings["config"]})
|
||||
return vms
|
||||
|
||||
def _get_vms_from_directory(self, directory):
|
||||
@ -305,9 +305,9 @@ class VMware(BaseManager):
|
||||
log.debug('Reading VMware VMX file "{}"'.format(vmx_path))
|
||||
try:
|
||||
pairs = self.parse_vmware_file(vmx_path)
|
||||
if "displayName" in pairs:
|
||||
log.debug('Found VM named "{}"'.format(pairs["displayName"]))
|
||||
vms.append({"vmname": pairs["displayName"], "vmx_path": vmx_path})
|
||||
if "displayname" in pairs:
|
||||
log.debug('Found VM named "{}"'.format(pairs["displayname"]))
|
||||
vms.append({"vmname": pairs["displayname"], "vmx_path": vmx_path})
|
||||
except OSError as e:
|
||||
log.warning('Could not read VMware VMX file "{}": {}'.format(vmx_path, e))
|
||||
continue
|
||||
@ -341,7 +341,7 @@ class VMware(BaseManager):
|
||||
elif sys.platform.startswith("darwin"):
|
||||
return os.path.expanduser("~/Library/Preferences/VMware Fusion/preferences")
|
||||
else:
|
||||
return os.path.expanduser("~/.vmware/preferences")
|
||||
return os.path.expanduser("~/.vmware/preferences")
|
||||
|
||||
@staticmethod
|
||||
def get_vmware_default_vm_path():
|
||||
|
@ -176,6 +176,7 @@ class VMwareVM(BaseVM):
|
||||
|
||||
def _get_vmx_setting(self, name, value=None):
|
||||
|
||||
name = name.lower()
|
||||
if name in self._vmx_pairs:
|
||||
if value is not None:
|
||||
if self._vmx_pairs[name] == value:
|
||||
@ -269,7 +270,7 @@ class VMwareVM(BaseVM):
|
||||
bridge_name = "bridge{}".format(adapter_number)
|
||||
|
||||
vnet = "ethernet{}.vnet".format(adapter_number)
|
||||
if not vnet in self._vmx_pairs:
|
||||
if vnet not in self._vmx_pairs:
|
||||
continue
|
||||
|
||||
vmnet_interface = os.path.basename(self._vmx_pairs[vnet])
|
||||
@ -328,7 +329,7 @@ class VMwareVM(BaseVM):
|
||||
"""
|
||||
|
||||
try:
|
||||
#self._update_ubridge_config()
|
||||
# self._update_ubridge_config()
|
||||
command = [self.ubridge_path]
|
||||
log.info("starting ubridge: {}".format(command))
|
||||
self._ubridge_stdout_file = os.path.join(self.working_dir, "ubridge.log")
|
||||
|
46
tests/modules/vmware/test_vmware_manager.py
Normal file
46
tests/modules/vmware/test_vmware_manager.py
Normal file
@ -0,0 +1,46 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
# Copyright (C) 2015 GNS3 Technologies Inc.
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
import pytest
|
||||
import tempfile
|
||||
import os
|
||||
import stat
|
||||
import asyncio
|
||||
|
||||
|
||||
from unittest.mock import patch
|
||||
|
||||
from gns3server.modules.vmware import VMware
|
||||
from tests.utils import asyncio_patch
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def manager(port_manager):
|
||||
m = VMware.instance()
|
||||
m.port_manager = port_manager
|
||||
return m
|
||||
|
||||
|
||||
def test_parse_vmware_file(manager, tmpdir):
|
||||
path = str(tmpdir / "test.vmx")
|
||||
with open(path, "w+") as f:
|
||||
f.write('displayname = "GNS3 VM"\nguestOS = "ubuntu-64"')
|
||||
|
||||
vmx = VMware.parse_vmware_file(path)
|
||||
assert vmx["displayname"] == "GNS3 VM"
|
||||
assert vmx["guestos"] == "ubuntu-64"
|
Loading…
Reference in New Issue
Block a user