mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-24 17:28:08 +00:00
Merge branch '1.5' into networkv2
This commit is contained in:
commit
dd2fdcc574
@ -75,7 +75,7 @@ class Config(object):
|
|||||||
# 2: $HOME/.config/GNS3.conf
|
# 2: $HOME/.config/GNS3.conf
|
||||||
# 3: /etc/xdg/GNS3/gns3_server.conf
|
# 3: /etc/xdg/GNS3/gns3_server.conf
|
||||||
# 4: /etc/xdg/GNS3.conf
|
# 4: /etc/xdg/GNS3.conf
|
||||||
# 5: server.conf in the current working directory
|
# 5: gns3_server.conf in the current working directory
|
||||||
|
|
||||||
appname = "GNS3"
|
appname = "GNS3"
|
||||||
home = os.path.expanduser("~")
|
home = os.path.expanduser("~")
|
||||||
@ -84,6 +84,7 @@ class Config(object):
|
|||||||
self._files = [os.path.join(os.getcwd(), filename),
|
self._files = [os.path.join(os.getcwd(), filename),
|
||||||
os.path.join(home, ".config", appname, filename),
|
os.path.join(home, ".config", appname, filename),
|
||||||
os.path.join(home, ".config", appname + ".conf"),
|
os.path.join(home, ".config", appname + ".conf"),
|
||||||
|
os.path.join("/etc/gns3", filename),
|
||||||
os.path.join("/etc/xdg", appname, filename),
|
os.path.join("/etc/xdg", appname, filename),
|
||||||
os.path.join("/etc/xdg", appname + ".conf")]
|
os.path.join("/etc/xdg", appname + ".conf")]
|
||||||
|
|
||||||
|
@ -195,16 +195,22 @@ class DockerVM(BaseVM):
|
|||||||
},
|
},
|
||||||
"Volumes": {},
|
"Volumes": {},
|
||||||
"Env": [],
|
"Env": [],
|
||||||
"Cmd": image_infos.get("ContainerConfig", {"Cmd": []})["Cmd"]
|
"Cmd": [],
|
||||||
|
"Entrypoint": image_infos.get("Config", {"Entrypoint": []})["Entrypoint"]
|
||||||
}
|
}
|
||||||
|
|
||||||
params["Cmd"].insert(0, "/bin/sh")
|
|
||||||
params["Cmd"].insert(1, "/gns3/init.sh")
|
if params["Entrypoint"] is None:
|
||||||
|
params["Entrypoint"] = []
|
||||||
if self._start_command:
|
if self._start_command:
|
||||||
params["Cmd"] += shlex.split(self._start_command)
|
params["Cmd"] = shlex.split(self._start_command)
|
||||||
else:
|
if len(params["Cmd"]) == 0:
|
||||||
if len(params["Cmd"]) == 2:
|
params["Cmd"] = image_infos.get("Config", {"Cmd": []})["Cmd"]
|
||||||
params["Cmd"] += ["/bin/sh"]
|
if params["Cmd"] is None:
|
||||||
|
params["Cmd"] = []
|
||||||
|
if len(params["Cmd"]) == 0 and len(params["Entrypoint"]) == 0:
|
||||||
|
params["Cmd"] = ["/bin/sh"]
|
||||||
|
params["Entrypoint"].insert(0, "/gns3/init.sh")
|
||||||
|
|
||||||
if self._environment:
|
if self._environment:
|
||||||
params["Env"] += [e.strip() for e in self._environment.split("\n")]
|
params["Env"] += [e.strip() for e in self._environment.split("\n")]
|
||||||
|
2
gns3server/hypervisor/docker/resources/init.sh
Normal file → Executable file
2
gns3server/hypervisor/docker/resources/init.sh
Normal file → Executable file
@ -43,4 +43,4 @@ sed -n 's/^ *\(eth[0-9]*\):.*/\1/p' < /proc/net/dev | while read dev; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
# continue normal docker startup
|
# continue normal docker startup
|
||||||
/bin/sh -c "$@"
|
exec "$@"
|
||||||
|
@ -55,7 +55,6 @@ class DynamipsHypervisor:
|
|||||||
self._working_dir = working_dir
|
self._working_dir = working_dir
|
||||||
self._version = "N/A"
|
self._version = "N/A"
|
||||||
self._timeout = timeout
|
self._timeout = timeout
|
||||||
self._uuid = None
|
|
||||||
self._reader = None
|
self._reader = None
|
||||||
self._writer = None
|
self._writer = None
|
||||||
self._io_lock = asyncio.Lock()
|
self._io_lock = asyncio.Lock()
|
||||||
@ -99,8 +98,6 @@ class DynamipsHypervisor:
|
|||||||
except IndexError:
|
except IndexError:
|
||||||
self._version = "Unknown"
|
self._version = "Unknown"
|
||||||
|
|
||||||
self._uuid = yield from self.send("hypervisor uuid")
|
|
||||||
|
|
||||||
# this forces to send the working dir to Dynamips
|
# this forces to send the working dir to Dynamips
|
||||||
yield from self.set_working_dir(self._working_dir)
|
yield from self.set_working_dir(self._working_dir)
|
||||||
|
|
||||||
@ -174,16 +171,6 @@ class DynamipsHypervisor:
|
|||||||
|
|
||||||
return self._working_dir
|
return self._working_dir
|
||||||
|
|
||||||
@property
|
|
||||||
def uuid(self):
|
|
||||||
"""
|
|
||||||
Returns this hypervisor UUID.
|
|
||||||
|
|
||||||
:Returns: uuid string
|
|
||||||
"""
|
|
||||||
|
|
||||||
return self._uuid
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def devices(self):
|
def devices(self):
|
||||||
"""
|
"""
|
||||||
|
@ -35,10 +35,10 @@ from pkg_resources import parse_version
|
|||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
from ..base_manager import BaseManager
|
from gns3server.modules.base_manager import BaseManager
|
||||||
from .vmware_vm import VMwareVM
|
from gns3server.modules.vmware.vmware_vm import VMwareVM
|
||||||
from .vmware_error import VMwareError
|
from gns3server.modules.vmware.vmware_error import VMwareError
|
||||||
from .nio_vmnet import NIOVMNET
|
from gns3server.modules.vmware.nio_vmnet import NIOVMNET
|
||||||
|
|
||||||
|
|
||||||
class VMware(BaseManager):
|
class VMware(BaseManager):
|
||||||
@ -162,8 +162,8 @@ class VMware(BaseManager):
|
|||||||
else:
|
else:
|
||||||
if sys.platform.startswith("darwin"):
|
if sys.platform.startswith("darwin"):
|
||||||
if not os.path.isdir("/Applications/VMware Fusion.app"):
|
if not os.path.isdir("/Applications/VMware Fusion.app"):
|
||||||
raise VMwareError("VMware Fusion is not installed")
|
raise VMwareError("VMware Fusion is not installed in the standard location /Applications/VMware Fusion.app")
|
||||||
return # FIXME: no version checking on Mac OS X
|
return # FIXME: no version checking on Mac OS X but we support all versions of fusion
|
||||||
|
|
||||||
vmware_path = VMware._get_linux_vmware_binary()
|
vmware_path = VMware._get_linux_vmware_binary()
|
||||||
if vmware_path is None:
|
if vmware_path is None:
|
||||||
@ -646,3 +646,10 @@ class VMware(BaseManager):
|
|||||||
if path is None:
|
if path is None:
|
||||||
path = shutil.which("vmplayer")
|
path = shutil.which("vmplayer")
|
||||||
return path
|
return path
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
loop = asyncio.get_event_loop()
|
||||||
|
vmware = VMware.instance()
|
||||||
|
print("=> Check version")
|
||||||
|
loop.run_until_complete(asyncio.async(vmware.check_vmware_version()))
|
||||||
|
@ -26,7 +26,7 @@ import asyncio
|
|||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from gns3server.utils.telnet_server import TelnetServer
|
from gns3server.utils.telnet_server import TelnetServer
|
||||||
from gns3server.utils.interfaces import get_windows_interfaces
|
from gns3server.utils.interfaces import interfaces, get_windows_interfaces
|
||||||
from gns3server.utils.asyncio import wait_for_file_creation, wait_for_named_pipe_creation
|
from gns3server.utils.asyncio import wait_for_file_creation, wait_for_named_pipe_creation
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from .vmware_error import VMwareError
|
from .vmware_error import VMwareError
|
||||||
@ -318,20 +318,29 @@ class VMwareVM(BaseVM):
|
|||||||
vmnet_interface = os.path.basename(self._vmx_pairs[vnet])
|
vmnet_interface = os.path.basename(self._vmx_pairs[vnet])
|
||||||
if sys.platform.startswith("linux"):
|
if sys.platform.startswith("linux"):
|
||||||
yield from self._ubridge_hypervisor.send('bridge add_nio_linux_raw {name} "{interface}"'.format(name=vnet,
|
yield from self._ubridge_hypervisor.send('bridge add_nio_linux_raw {name} "{interface}"'.format(name=vnet,
|
||||||
interface=vmnet_interface))
|
interface=vmnet_interface))
|
||||||
elif sys.platform.startswith("win"):
|
elif sys.platform.startswith("win"):
|
||||||
windows_interfaces = get_windows_interfaces()
|
windows_interfaces = get_windows_interfaces()
|
||||||
npf = None
|
npf = None
|
||||||
|
source_mac = None
|
||||||
for interface in windows_interfaces:
|
for interface in windows_interfaces:
|
||||||
if "netcard" in interface and vmnet_interface in interface["netcard"]:
|
if "netcard" in interface and vmnet_interface in interface["netcard"]:
|
||||||
npf = interface["id"]
|
npf = interface["id"]
|
||||||
|
source_mac = interface["mac_address"]
|
||||||
elif vmnet_interface in interface["name"]:
|
elif vmnet_interface in interface["name"]:
|
||||||
npf = interface["id"]
|
npf = interface["id"]
|
||||||
|
source_mac = interface["mac_address"]
|
||||||
if npf:
|
if npf:
|
||||||
yield from self._ubridge_hypervisor.send('bridge add_nio_ethernet {name} "{interface}"'.format(name=vnet,
|
yield from self._ubridge_hypervisor.send('bridge add_nio_ethernet {name} "{interface}"'.format(name=vnet,
|
||||||
interface=npf))
|
interface=npf))
|
||||||
else:
|
else:
|
||||||
raise VMwareError("Could not find NPF id for VMnet interface {}".format(vmnet_interface))
|
raise VMwareError("Could not find NPF id for VMnet interface {}".format(vmnet_interface))
|
||||||
|
|
||||||
|
# TODO: should provide that as an option
|
||||||
|
#if source_mac:
|
||||||
|
# yield from self._ubridge_hypervisor.send('bridge set_pcap_filter {name} "not ether src {mac}"'.format(name=vnet,
|
||||||
|
# mac=source_mac))
|
||||||
|
|
||||||
elif sys.platform.startswith("darwin"):
|
elif sys.platform.startswith("darwin"):
|
||||||
yield from self._ubridge_hypervisor.send('bridge add_nio_fusion_vmnet {name} "{interface}"'.format(name=vnet,
|
yield from self._ubridge_hypervisor.send('bridge add_nio_fusion_vmnet {name} "{interface}"'.format(name=vnet,
|
||||||
interface=vmnet_interface))
|
interface=vmnet_interface))
|
||||||
@ -351,6 +360,14 @@ class VMwareVM(BaseVM):
|
|||||||
|
|
||||||
yield from self._ubridge_hypervisor.send('bridge start {name}'.format(name=vnet))
|
yield from self._ubridge_hypervisor.send('bridge start {name}'.format(name=vnet))
|
||||||
|
|
||||||
|
# TODO: this only work when using PCAP (NIO Ethernet)
|
||||||
|
# source_mac = None
|
||||||
|
# for interface in interfaces():
|
||||||
|
# if interface["name"] == vmnet_interface:
|
||||||
|
# source_mac = interface["mac_address"]
|
||||||
|
# if source_mac:
|
||||||
|
# yield from self._ubridge_hypervisor.send('bridge set_pcap_filter {name} "not ether src {mac}"'.format(name=vnet, mac=source_mac))
|
||||||
|
|
||||||
@asyncio.coroutine
|
@asyncio.coroutine
|
||||||
def _delete_ubridge_connection(self, adapter_number):
|
def _delete_ubridge_connection(self, adapter_number):
|
||||||
"""
|
"""
|
||||||
|
@ -23,7 +23,7 @@ import struct
|
|||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
if psutil.version_info < (3, 0, 0):
|
if psutil.version_info < (3, 0, 0):
|
||||||
raise Exception("psutil version should >= 3.0.0. If you are under ubuntu/debian install gns3 via apt instead of pip")
|
raise Exception("psutil version should >= 3.0.0. If you are under Ubuntu/Debian install gns3 via apt instead of pip")
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@ -59,6 +59,7 @@ def _get_windows_interfaces_from_registry():
|
|||||||
interfaces.append({"id": npf_interface,
|
interfaces.append({"id": npf_interface,
|
||||||
"name": name,
|
"name": name,
|
||||||
"ip_address": ip_address,
|
"ip_address": ip_address,
|
||||||
|
"mac_address": "", # TODO: find MAC address in registry
|
||||||
"netcard": netcard})
|
"netcard": netcard})
|
||||||
winreg.CloseKey(hkeyinterface)
|
winreg.CloseKey(hkeyinterface)
|
||||||
winreg.CloseKey(hkeycon)
|
winreg.CloseKey(hkeycon)
|
||||||
@ -99,6 +100,7 @@ def get_windows_interfaces():
|
|||||||
interfaces.append({"id": npf_interface,
|
interfaces.append({"id": npf_interface,
|
||||||
"name": adapter.NetConnectionID,
|
"name": adapter.NetConnectionID,
|
||||||
"ip_address": ip_address,
|
"ip_address": ip_address,
|
||||||
|
"mac_address": adapter.MACAddress,
|
||||||
"netcard": adapter.name})
|
"netcard": adapter.name})
|
||||||
except (AttributeError, pywintypes.com_error):
|
except (AttributeError, pywintypes.com_error):
|
||||||
log.warn("Could not use the COM service to retrieve interface info, trying using the registry...")
|
log.warn("Could not use the COM service to retrieve interface info, trying using the registry...")
|
||||||
@ -148,14 +150,17 @@ def interfaces():
|
|||||||
if not sys.platform.startswith("win"):
|
if not sys.platform.startswith("win"):
|
||||||
for interface in sorted(psutil.net_if_addrs().keys()):
|
for interface in sorted(psutil.net_if_addrs().keys()):
|
||||||
ip_address = ""
|
ip_address = ""
|
||||||
|
mac_address = ""
|
||||||
for addr in psutil.net_if_addrs()[interface]:
|
for addr in psutil.net_if_addrs()[interface]:
|
||||||
# get the first available IPv4 address only
|
# get the first available IPv4 address only
|
||||||
if addr.family == socket.AF_INET:
|
if addr.family == socket.AF_INET:
|
||||||
ip_address = addr.address
|
ip_address = addr.address
|
||||||
break
|
if addr.family == psutil.AF_LINK:
|
||||||
|
mac_address = addr.address
|
||||||
results.append({"id": interface,
|
results.append({"id": interface,
|
||||||
"name": interface,
|
"name": interface,
|
||||||
"ip_address": ip_address})
|
"ip_address": ip_address,
|
||||||
|
"mac_address": mac_address})
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
results = get_windows_interfaces()
|
results = get_windows_interfaces()
|
||||||
|
@ -82,16 +82,25 @@ def _get_unused_port():
|
|||||||
def http_server(request, loop, port_manager, monkeypatch):
|
def http_server(request, loop, port_manager, monkeypatch):
|
||||||
"""A GNS3 server"""
|
"""A GNS3 server"""
|
||||||
|
|
||||||
port = _get_unused_port()
|
|
||||||
host = "localhost"
|
|
||||||
app = web.Application()
|
app = web.Application()
|
||||||
for method, route, handler in Route.get_routes():
|
for method, route, handler in Route.get_routes():
|
||||||
app.router.add_route(method, route, handler)
|
app.router.add_route(method, route, handler)
|
||||||
for module in MODULES:
|
for module in MODULES:
|
||||||
instance = module.instance()
|
instance = module.instance()
|
||||||
instance.port_manager = port_manager
|
instance.port_manager = port_manager
|
||||||
srv = loop.create_server(app.make_handler(), host, port)
|
|
||||||
srv = loop.run_until_complete(srv)
|
host = "localhost"
|
||||||
|
|
||||||
|
# We try multiple time. Because on Travis test can fail when because the port is taken by someone else
|
||||||
|
for i in range(0, 5):
|
||||||
|
port = _get_unused_port()
|
||||||
|
try:
|
||||||
|
srv = loop.create_server(app.make_handler(), host, port)
|
||||||
|
srv = loop.run_until_complete(srv)
|
||||||
|
except OSError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
def tear_down():
|
def tear_down():
|
||||||
for module in MODULES:
|
for module in MODULES:
|
||||||
|
@ -98,7 +98,8 @@ def test_create(loop, project, manager):
|
|||||||
"Hostname": "test",
|
"Hostname": "test",
|
||||||
"Image": "ubuntu",
|
"Image": "ubuntu",
|
||||||
"Env": [],
|
"Env": [],
|
||||||
"Cmd": ["/bin/sh", "/gns3/init.sh", "/bin/sh"]
|
"Entrypoint": ["/gns3/init.sh"],
|
||||||
|
"Cmd": ["/bin/sh"]
|
||||||
})
|
})
|
||||||
assert vm._cid == "e90e34656806"
|
assert vm._cid == "e90e34656806"
|
||||||
|
|
||||||
@ -135,7 +136,8 @@ def test_create_vnc(loop, project, manager):
|
|||||||
"Hostname": "test",
|
"Hostname": "test",
|
||||||
"Image": "ubuntu",
|
"Image": "ubuntu",
|
||||||
"Env": ['DISPLAY=:42'],
|
"Env": ['DISPLAY=:42'],
|
||||||
"Cmd": ["/bin/sh", "/gns3/init.sh", "/bin/sh"]
|
"Entrypoint": ["/gns3/init.sh"],
|
||||||
|
"Cmd": ["/bin/sh"]
|
||||||
})
|
})
|
||||||
assert vm._start_vnc.called
|
assert vm._start_vnc.called
|
||||||
assert vm._cid == "e90e34656806"
|
assert vm._cid == "e90e34656806"
|
||||||
@ -163,7 +165,8 @@ def test_create_start_cmd(loop, project, manager):
|
|||||||
"Privileged": True
|
"Privileged": True
|
||||||
},
|
},
|
||||||
"Volumes": {},
|
"Volumes": {},
|
||||||
"Cmd": ["/bin/sh", "/gns3/init.sh", "/bin/ls"],
|
"Entrypoint": ["/gns3/init.sh"],
|
||||||
|
"Cmd": ["/bin/ls"],
|
||||||
"NetworkDisabled": True,
|
"NetworkDisabled": True,
|
||||||
"Name": "test",
|
"Name": "test",
|
||||||
"Hostname": "test",
|
"Hostname": "test",
|
||||||
@ -200,7 +203,8 @@ def test_create_environment(loop, project, manager):
|
|||||||
"Name": "test",
|
"Name": "test",
|
||||||
"Hostname": "test",
|
"Hostname": "test",
|
||||||
"Image": "ubuntu",
|
"Image": "ubuntu",
|
||||||
"Cmd": ["/bin/sh", "/gns3/init.sh", "/bin/sh"]
|
"Entrypoint": ["/gns3/init.sh"],
|
||||||
|
"Cmd": ["/bin/sh"]
|
||||||
})
|
})
|
||||||
assert vm._cid == "e90e34656806"
|
assert vm._cid == "e90e34656806"
|
||||||
|
|
||||||
@ -246,7 +250,8 @@ def test_create_image_not_available(loop, project, manager):
|
|||||||
"Hostname": "test",
|
"Hostname": "test",
|
||||||
"Image": "ubuntu",
|
"Image": "ubuntu",
|
||||||
"Env": [],
|
"Env": [],
|
||||||
"Cmd": ["/bin/sh", "/gns3/init.sh", "/bin/sh"]
|
"Entrypoint": ["/gns3/init.sh"],
|
||||||
|
"Cmd": ["/bin/sh"]
|
||||||
})
|
})
|
||||||
assert vm._cid == "e90e34656806"
|
assert vm._cid == "e90e34656806"
|
||||||
mock_pull.assert_called_with("ubuntu")
|
mock_pull.assert_called_with("ubuntu")
|
||||||
@ -456,7 +461,8 @@ def test_update(loop, vm):
|
|||||||
"Hostname": "test",
|
"Hostname": "test",
|
||||||
"Image": "ubuntu",
|
"Image": "ubuntu",
|
||||||
"Env": [],
|
"Env": [],
|
||||||
"Cmd": ["/bin/sh", "/gns3/init.sh", "/bin/sh"]
|
"Entrypoint": ["/gns3/init.sh"],
|
||||||
|
"Cmd": ["/bin/sh"]
|
||||||
})
|
})
|
||||||
assert vm.console == original_console
|
assert vm.console == original_console
|
||||||
|
|
||||||
@ -493,7 +499,8 @@ def test_update_running(loop, vm):
|
|||||||
"Hostname": "test",
|
"Hostname": "test",
|
||||||
"Image": "ubuntu",
|
"Image": "ubuntu",
|
||||||
"Env": [],
|
"Env": [],
|
||||||
"Cmd": ["/bin/sh", "/gns3/init.sh", "/bin/sh"]
|
"Entrypoint": ["/gns3/init.sh"],
|
||||||
|
"Cmd": ["/bin/sh"]
|
||||||
})
|
})
|
||||||
|
|
||||||
assert vm.console == original_console
|
assert vm.console == original_console
|
||||||
|
@ -166,6 +166,8 @@ def vmnet_windows(args, vmnet_range_start, vmnet_range_end):
|
|||||||
continue
|
continue
|
||||||
print("Adding vmnet{}...".format(vmnet_number))
|
print("Adding vmnet{}...".format(vmnet_number))
|
||||||
os.system('"{}" -- add adapter vmnet{}'.format(vnetlib_path, vmnet_number))
|
os.system('"{}" -- add adapter vmnet{}'.format(vnetlib_path, vmnet_number))
|
||||||
|
os.system("net stop npf")
|
||||||
|
os.system("net start npf")
|
||||||
|
|
||||||
|
|
||||||
def vmnet_unix(args, vmnet_range_start, vmnet_range_end):
|
def vmnet_unix(args, vmnet_range_start, vmnet_range_end):
|
||||||
|
Loading…
Reference in New Issue
Block a user