mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-28 11:18:11 +00:00
TAP interface support for QEMU VMs. Fixes #153.
This commit is contained in:
parent
b6a935aeb8
commit
f208b472a1
@ -247,7 +247,7 @@ class QEMUHandler:
|
|||||||
qemu_manager = Qemu.instance()
|
qemu_manager = Qemu.instance()
|
||||||
vm = qemu_manager.get_vm(request.match_info["vm_id"], project_id=request.match_info["project_id"])
|
vm = qemu_manager.get_vm(request.match_info["vm_id"], project_id=request.match_info["project_id"])
|
||||||
nio_type = request.json["type"]
|
nio_type = request.json["type"]
|
||||||
if nio_type != "nio_udp":
|
if nio_type not in ("nio_udp", "nio_tap"):
|
||||||
raise HTTPConflict(text="NIO of type {} is not supported".format(nio_type))
|
raise HTTPConflict(text="NIO of type {} is not supported".format(nio_type))
|
||||||
nio = qemu_manager.create_nio(vm.qemu_path, request.json)
|
nio = qemu_manager.create_nio(vm.qemu_path, request.json)
|
||||||
yield from vm.adapter_add_nio_binding(int(request.match_info["adapter_number"]), nio)
|
yield from vm.adapter_add_nio_binding(int(request.match_info["adapter_number"]), nio)
|
||||||
|
@ -364,8 +364,9 @@ class BaseManager:
|
|||||||
nio = NIOUDP(lport, rhost, rport)
|
nio = NIOUDP(lport, rhost, rport)
|
||||||
elif nio_settings["type"] == "nio_tap":
|
elif nio_settings["type"] == "nio_tap":
|
||||||
tap_device = nio_settings["tap_device"]
|
tap_device = nio_settings["tap_device"]
|
||||||
if not self._has_privileged_access(executable):
|
#FIXME: check for permissions on tap device
|
||||||
raise aiohttp.web.HTTPForbidden(text="{} has no privileged access to {}.".format(executable, tap_device))
|
#if not self._has_privileged_access(executable):
|
||||||
|
# raise aiohttp.web.HTTPForbidden(text="{} has no privileged access to {}.".format(executable, tap_device))
|
||||||
nio = NIOTAP(tap_device)
|
nio = NIOTAP(tap_device)
|
||||||
elif nio_settings["type"] == "nio_generic_ethernet":
|
elif nio_settings["type"] == "nio_generic_ethernet":
|
||||||
nio = NIOGenericEthernet(nio_settings["ethernet_device"])
|
nio = NIOGenericEthernet(nio_settings["ethernet_device"])
|
||||||
|
@ -32,6 +32,7 @@ import socket
|
|||||||
from .qemu_error import QemuError
|
from .qemu_error import QemuError
|
||||||
from ..adapters.ethernet_adapter import EthernetAdapter
|
from ..adapters.ethernet_adapter import EthernetAdapter
|
||||||
from ..nios.nio_udp import NIOUDP
|
from ..nios.nio_udp import NIOUDP
|
||||||
|
from ..nios.nio_tap import NIOTAP
|
||||||
from ..base_vm import BaseVM
|
from ..base_vm import BaseVM
|
||||||
from ...schemas.qemu import QEMU_OBJECT_SCHEMA
|
from ...schemas.qemu import QEMU_OBJECT_SCHEMA
|
||||||
|
|
||||||
@ -995,19 +996,25 @@ class QemuVM(BaseVM):
|
|||||||
else:
|
else:
|
||||||
network_options.extend(["-device", "{},mac={},netdev=gns3-{}".format(self._adapter_type, mac, adapter_number)])
|
network_options.extend(["-device", "{},mac={},netdev=gns3-{}".format(self._adapter_type, mac, adapter_number)])
|
||||||
nio = adapter.get_nio(0)
|
nio = adapter.get_nio(0)
|
||||||
if nio and isinstance(nio, NIOUDP):
|
if nio:
|
||||||
if self._legacy_networking:
|
if isinstance(nio, NIOUDP):
|
||||||
network_options.extend(["-net", "udp,vlan={},name=gns3-{},sport={},dport={},daddr={}".format(adapter_number,
|
if self._legacy_networking:
|
||||||
adapter_number,
|
network_options.extend(["-net", "udp,vlan={},name=gns3-{},sport={},dport={},daddr={}".format(adapter_number,
|
||||||
nio.lport,
|
adapter_number,
|
||||||
nio.rport,
|
nio.lport,
|
||||||
nio.rhost)])
|
nio.rport,
|
||||||
else:
|
nio.rhost)])
|
||||||
network_options.extend(["-netdev", "socket,id=gns3-{},udp={}:{},localaddr={}:{}".format(adapter_number,
|
else:
|
||||||
nio.rhost,
|
network_options.extend(["-netdev", "socket,id=gns3-{},udp={}:{},localaddr={}:{}".format(adapter_number,
|
||||||
nio.rport,
|
nio.rhost,
|
||||||
self._host,
|
nio.rport,
|
||||||
nio.lport)])
|
self._host,
|
||||||
|
nio.lport)])
|
||||||
|
elif isinstance(nio, NIOTAP):
|
||||||
|
if self._legacy_networking:
|
||||||
|
network_options.extend(["-net", "tap,name=gns3-{},ifname={}".format(adapter_number, nio.tap_device)])
|
||||||
|
else:
|
||||||
|
network_options.extend(["-netdev", "tap,id=gns3-{},ifname={}".format(adapter_number, nio.tap_device)])
|
||||||
else:
|
else:
|
||||||
if self._legacy_networking:
|
if self._legacy_networking:
|
||||||
network_options.extend(["-net", "user,vlan={},name=gns3-{}".format(adapter_number, adapter_number)])
|
network_options.extend(["-net", "user,vlan={},name=gns3-{}".format(adapter_number, adapter_number)])
|
||||||
|
Loading…
Reference in New Issue
Block a user