mirror of
https://github.com/GNS3/gns3-server
synced 2024-11-18 06:18:08 +00:00
Add NIO TAP support for Docker and VMware. Fixes #603.
This commit is contained in:
parent
e175650fb0
commit
08956e438c
@ -221,16 +221,10 @@ class DockerHandler:
|
|||||||
request.match_info["vm_id"],
|
request.match_info["vm_id"],
|
||||||
project_id=request.match_info["project_id"])
|
project_id=request.match_info["project_id"])
|
||||||
nio_type = request.json["type"]
|
nio_type = request.json["type"]
|
||||||
if nio_type not in ("nio_udp"):
|
if nio_type not in ("nio_udp", "nio_tap"):
|
||||||
raise HTTPConflict(
|
raise HTTPConflict(text="NIO of type {} is not supported".format(nio_type))
|
||||||
text="NIO of type {} is not supported".format(nio_type))
|
nio = docker_manager.create_nio(int(request.match_info["adapter_number"]), request.json)
|
||||||
nio = docker_manager.create_nio(
|
yield from container.adapter_add_nio_binding(int(request.match_info["adapter_number"]), nio)
|
||||||
int(request.match_info["adapter_number"]), request.json)
|
|
||||||
adapter = container._ethernet_adapters[
|
|
||||||
int(request.match_info["adapter_number"])
|
|
||||||
]
|
|
||||||
yield from container.adapter_add_nio_binding(
|
|
||||||
int(request.match_info["adapter_number"]), nio)
|
|
||||||
response.set_status(201)
|
response.set_status(201)
|
||||||
response.json(nio)
|
response.json(nio)
|
||||||
|
|
||||||
|
@ -271,7 +271,7 @@ class VMwareHandler:
|
|||||||
vmware_manager = VMware.instance()
|
vmware_manager = VMware.instance()
|
||||||
vm = vmware_manager.get_vm(request.match_info["vm_id"], project_id=request.match_info["project_id"])
|
vm = vmware_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 not in ("nio_udp", "nio_vmnet", "nio_nat"):
|
if nio_type not in ("nio_udp", "nio_vmnet", "nio_nat", "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 = vmware_manager.create_nio(None, request.json)
|
nio = vmware_manager.create_nio(None, 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)
|
||||||
|
@ -31,6 +31,7 @@ from .docker_error import *
|
|||||||
from ..base_vm import BaseVM
|
from ..base_vm import BaseVM
|
||||||
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 ...utils.asyncio.telnet_server import AsyncioTelnetServer
|
from ...utils.asyncio.telnet_server import AsyncioTelnetServer
|
||||||
from ...utils.asyncio.raw_command_server import AsyncioRawCommandServer
|
from ...utils.asyncio.raw_command_server import AsyncioRawCommandServer
|
||||||
from ...utils.asyncio import wait_for_file_creation
|
from ...utils.asyncio import wait_for_file_creation
|
||||||
@ -616,6 +617,7 @@ class DockerVM(BaseVM):
|
|||||||
:param adapter_number: adapter number
|
:param adapter_number: adapter number
|
||||||
:param namespace: Container namespace (pid)
|
:param namespace: Container namespace (pid)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
adapter = self._ethernet_adapters[adapter_number]
|
adapter = self._ethernet_adapters[adapter_number]
|
||||||
except IndexError:
|
except IndexError:
|
||||||
@ -629,41 +631,36 @@ class DockerVM(BaseVM):
|
|||||||
adapter.guest_ifc = "veth-gns3-i{}".format(str(index))
|
adapter.guest_ifc = "veth-gns3-i{}".format(str(index))
|
||||||
break
|
break
|
||||||
if not hasattr(adapter, "ifc"):
|
if not hasattr(adapter, "ifc"):
|
||||||
raise DockerError(
|
raise DockerError("Adapter {adapter_number} couldn't allocate interface on Docker container '{name}'. Too many Docker interfaces already exists".format(name=self.name,
|
||||||
"Adapter {adapter_number} couldn't allocate interface on Docker container '{name}'. Too many Docker interfaces already exists".format(
|
adapter_number=adapter_number))
|
||||||
name=self.name, adapter_number=adapter_number))
|
|
||||||
|
|
||||||
yield from self._ubridge_hypervisor.send(
|
yield from self._ubridge_hypervisor.send('docker create_veth {hostif} {guestif}'.format(guestif=adapter.guest_ifc,
|
||||||
'docker create_veth {hostif} {guestif}'.format(
|
hostif=adapter.host_ifc))
|
||||||
guestif=adapter.guest_ifc, hostif=adapter.host_ifc))
|
|
||||||
|
|
||||||
log.debug("Move container %s adapter %s to namespace %s", self.name, adapter.guest_ifc, namespace)
|
log.debug("Move container %s adapter %s to namespace %s", self.name, adapter.guest_ifc, namespace)
|
||||||
try:
|
try:
|
||||||
yield from self._ubridge_hypervisor.send(
|
yield from self._ubridge_hypervisor.send('docker move_to_ns {ifc} {ns} eth{adapter}'.format(ifc=adapter.guest_ifc,
|
||||||
'docker move_to_ns {ifc} {ns} eth{adapter}'.format(
|
ns=namespace,
|
||||||
ifc=adapter.guest_ifc, ns=namespace, adapter=adapter_number))
|
adapter=adapter_number))
|
||||||
except UbridgeError as e:
|
except UbridgeError as e:
|
||||||
raise UbridgeNamespaceError(e)
|
raise UbridgeNamespaceError(e)
|
||||||
|
|
||||||
|
if nio:
|
||||||
|
yield from self._ubridge_hypervisor.send('bridge create bridge{}'.format(adapter_number))
|
||||||
|
yield from self._ubridge_hypervisor.send('bridge add_nio_linux_raw bridge{adapter} {ifc}'.format(ifc=adapter.host_ifc, adapter=adapter_number))
|
||||||
if isinstance(nio, NIOUDP):
|
if isinstance(nio, NIOUDP):
|
||||||
yield from self._ubridge_hypervisor.send(
|
yield from self._ubridge_hypervisor.send('bridge add_nio_udp bridge{adapter} {lport} {rhost} {rport}'.format(adapter=adapter_number,
|
||||||
'bridge create bridge{}'.format(adapter_number))
|
lport=nio.lport,
|
||||||
yield from self._ubridge_hypervisor.send(
|
rhost=nio.rhost,
|
||||||
'bridge add_nio_linux_raw bridge{adapter} {ifc}'.format(
|
|
||||||
ifc=adapter.host_ifc, adapter=adapter_number))
|
|
||||||
|
|
||||||
yield from self._ubridge_hypervisor.send(
|
|
||||||
'bridge add_nio_udp bridge{adapter} {lport} {rhost} {rport}'.format(
|
|
||||||
adapter=adapter_number, lport=nio.lport, rhost=nio.rhost,
|
|
||||||
rport=nio.rport))
|
rport=nio.rport))
|
||||||
|
elif isinstance(nio, NIOTAP):
|
||||||
|
yield from self._ubridge_hypervisor.send('bridge add_nio_tap bridge{adapter} {tap}'.format(adapter=adapter_number, tap=nio.tap_device))
|
||||||
|
|
||||||
if nio.capturing:
|
if nio.capturing:
|
||||||
yield from self._ubridge_hypervisor.send(
|
yield from self._ubridge_hypervisor.send('bridge start_capture bridge{adapter} "{pcap_file}"'.format(adapter=adapter_number,
|
||||||
'bridge start_capture bridge{adapter} "{pcap_file}"'.format(
|
pcap_file=nio.pcap_output_file))
|
||||||
adapter=adapter_number, pcap_file=nio.pcap_output_file))
|
|
||||||
|
|
||||||
yield from self._ubridge_hypervisor.send(
|
yield from self._ubridge_hypervisor.send('bridge start bridge{adapter}'.format(adapter=adapter_number))
|
||||||
'bridge start bridge{adapter}'.format(adapter=adapter_number))
|
|
||||||
|
|
||||||
def _delete_ubridge_connection(self, adapter_number):
|
def _delete_ubridge_connection(self, adapter_number):
|
||||||
"""Deletes a connection in uBridge.
|
"""Deletes a connection in uBridge.
|
||||||
|
@ -32,6 +32,7 @@ from collections import OrderedDict
|
|||||||
from .vmware_error import VMwareError
|
from .vmware_error import VMwareError
|
||||||
from ..nios.nio_udp import NIOUDP
|
from ..nios.nio_udp import NIOUDP
|
||||||
from ..nios.nio_nat import NIONAT
|
from ..nios.nio_nat import NIONAT
|
||||||
|
from ..nios.nio_tap import NIOTAP
|
||||||
from .nio_vmnet import NIOVMNET
|
from .nio_vmnet import NIOVMNET
|
||||||
from ..adapters.ethernet_adapter import EthernetAdapter
|
from ..adapters.ethernet_adapter import EthernetAdapter
|
||||||
from ..base_vm import BaseVM
|
from ..base_vm import BaseVM
|
||||||
@ -345,6 +346,8 @@ class VMwareVM(BaseVM):
|
|||||||
lport=nio.lport,
|
lport=nio.lport,
|
||||||
rhost=nio.rhost,
|
rhost=nio.rhost,
|
||||||
rport=nio.rport))
|
rport=nio.rport))
|
||||||
|
elif isinstance(nio, NIOTAP):
|
||||||
|
yield from self._ubridge_hypervisor.send('bridge add_nio_tap {name} {tap}'.format(name=vnet, tap=nio.tap_device))
|
||||||
|
|
||||||
if nio.capturing:
|
if nio.capturing:
|
||||||
yield from self._ubridge_hypervisor.send('bridge start_capture {name} "{pcap_file}"'.format(name=vnet,
|
yield from self._ubridge_hypervisor.send('bridge start_capture {name} "{pcap_file}"'.format(name=vnet,
|
||||||
|
Loading…
Reference in New Issue
Block a user