mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-01 04:38:12 +00:00
parent
4a53c7789d
commit
a577fe9fdb
@ -218,7 +218,7 @@ class VMware(BaseManager):
|
|||||||
for line in f.read().splitlines():
|
for line in f.read().splitlines():
|
||||||
try:
|
try:
|
||||||
key, value = line.split('=', 1)
|
key, value = line.split('=', 1)
|
||||||
pairs[key.strip()] = value.strip('" ')
|
pairs[key.strip().lower()] = value.strip('" ')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
continue
|
continue
|
||||||
return pairs
|
return pairs
|
||||||
@ -276,16 +276,16 @@ class VMware(BaseManager):
|
|||||||
vm_entry, variable_name = key.split('.', 1)
|
vm_entry, variable_name = key.split('.', 1)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
continue
|
continue
|
||||||
if not vm_entry in vm_entries:
|
if vm_entry not in vm_entries:
|
||||||
vm_entries[vm_entry] = {}
|
vm_entries[vm_entry] = {}
|
||||||
vm_entries[vm_entry][variable_name.strip()] = value
|
vm_entries[vm_entry][variable_name.strip()] = value
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
log.warning("Could not read VMware inventory file {}: {}".format(inventory_path, e))
|
log.warning("Could not read VMware inventory file {}: {}".format(inventory_path, e))
|
||||||
|
|
||||||
for vm_settings in vm_entries.values():
|
for vm_settings in vm_entries.values():
|
||||||
if "DisplayName" in vm_settings and "config" in vm_settings:
|
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"]))
|
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"]})
|
vms.append({"vmname": vm_settings["displayname"], "vmx_path": vm_settings["config"]})
|
||||||
return vms
|
return vms
|
||||||
|
|
||||||
def _get_vms_from_directory(self, directory):
|
def _get_vms_from_directory(self, directory):
|
||||||
@ -305,9 +305,9 @@ class VMware(BaseManager):
|
|||||||
log.debug('Reading VMware VMX file "{}"'.format(vmx_path))
|
log.debug('Reading VMware VMX file "{}"'.format(vmx_path))
|
||||||
try:
|
try:
|
||||||
pairs = self.parse_vmware_file(vmx_path)
|
pairs = self.parse_vmware_file(vmx_path)
|
||||||
if "displayName" in pairs:
|
if "displayname" in pairs:
|
||||||
log.debug('Found VM named "{}"'.format(pairs["displayName"]))
|
log.debug('Found VM named "{}"'.format(pairs["displayname"]))
|
||||||
vms.append({"vmname": pairs["displayName"], "vmx_path": vmx_path})
|
vms.append({"vmname": pairs["displayname"], "vmx_path": vmx_path})
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
log.warning('Could not read VMware VMX file "{}": {}'.format(vmx_path, e))
|
log.warning('Could not read VMware VMX file "{}": {}'.format(vmx_path, e))
|
||||||
continue
|
continue
|
||||||
|
@ -176,6 +176,7 @@ class VMwareVM(BaseVM):
|
|||||||
|
|
||||||
def _get_vmx_setting(self, name, value=None):
|
def _get_vmx_setting(self, name, value=None):
|
||||||
|
|
||||||
|
name = name.lower()
|
||||||
if name in self._vmx_pairs:
|
if name in self._vmx_pairs:
|
||||||
if value is not None:
|
if value is not None:
|
||||||
if self._vmx_pairs[name] == value:
|
if self._vmx_pairs[name] == value:
|
||||||
@ -269,7 +270,7 @@ class VMwareVM(BaseVM):
|
|||||||
bridge_name = "bridge{}".format(adapter_number)
|
bridge_name = "bridge{}".format(adapter_number)
|
||||||
|
|
||||||
vnet = "ethernet{}.vnet".format(adapter_number)
|
vnet = "ethernet{}.vnet".format(adapter_number)
|
||||||
if not vnet in self._vmx_pairs:
|
if vnet not in self._vmx_pairs:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
vmnet_interface = os.path.basename(self._vmx_pairs[vnet])
|
vmnet_interface = os.path.basename(self._vmx_pairs[vnet])
|
||||||
|
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