mirror of
https://github.com/GNS3/gns3-server.git
synced 2025-06-21 16:39:40 +00:00
NIO NAT support for QEMU VMs (user mode back-end is used).
This commit is contained in:
@ -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 not in ("nio_udp", "nio_tap"):
|
if nio_type not in ("nio_udp", "nio_tap", "nio_nat"):
|
||||||
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)
|
||||||
|
@ -34,6 +34,7 @@ from .project_manager import ProjectManager
|
|||||||
|
|
||||||
from .nios.nio_udp import NIOUDP
|
from .nios.nio_udp import NIOUDP
|
||||||
from .nios.nio_tap import NIOTAP
|
from .nios.nio_tap import NIOTAP
|
||||||
|
from .nios.nio_nat import NIONAT
|
||||||
from .nios.nio_generic_ethernet import NIOGenericEthernet
|
from .nios.nio_generic_ethernet import NIOGenericEthernet
|
||||||
|
|
||||||
|
|
||||||
@ -370,6 +371,8 @@ class BaseManager:
|
|||||||
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"])
|
||||||
|
elif nio_settings["type"] == "nio_nat":
|
||||||
|
nio = NIONAT()
|
||||||
assert nio is not None
|
assert nio is not None
|
||||||
return nio
|
return nio
|
||||||
|
|
||||||
|
@ -410,6 +410,8 @@ class Dynamips(BaseManager):
|
|||||||
nio = NIOVDE(node.hypervisor, control_file, local_file)
|
nio = NIOVDE(node.hypervisor, control_file, local_file)
|
||||||
elif nio_settings["type"] == "nio_null":
|
elif nio_settings["type"] == "nio_null":
|
||||||
nio = NIONull(node.hypervisor)
|
nio = NIONull(node.hypervisor)
|
||||||
|
else:
|
||||||
|
raise aiohttp.web.HTTPConflict(text="NIO of type {} is not supported".format(nio_settings["type"]))
|
||||||
|
|
||||||
yield from nio.create()
|
yield from nio.create()
|
||||||
return nio
|
return nio
|
||||||
|
41
gns3server/modules/nios/nio_nat.py
Normal file
41
gns3server/modules/nios/nio_nat.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
#
|
||||||
|
# Copyright (C) 2013 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/>.
|
||||||
|
|
||||||
|
"""
|
||||||
|
Interface for NAT NIOs.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from .nio import NIO
|
||||||
|
|
||||||
|
|
||||||
|
class NIONAT(NIO):
|
||||||
|
|
||||||
|
"""
|
||||||
|
NAT NIO.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
|
||||||
|
return "NIO TAP"
|
||||||
|
|
||||||
|
def __json__(self):
|
||||||
|
|
||||||
|
return {"type": "nio_nat"}
|
@ -23,7 +23,6 @@ order to run a QEMU VM.
|
|||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import random
|
|
||||||
import subprocess
|
import subprocess
|
||||||
import shlex
|
import shlex
|
||||||
import asyncio
|
import asyncio
|
||||||
@ -33,6 +32,7 @@ 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 ..nios.nio_tap import NIOTAP
|
||||||
|
from ..nios.nio_nat import NIONAT
|
||||||
from ..base_vm import BaseVM
|
from ..base_vm import BaseVM
|
||||||
from ...schemas.qemu import QEMU_OBJECT_SCHEMA
|
from ...schemas.qemu import QEMU_OBJECT_SCHEMA
|
||||||
|
|
||||||
@ -984,40 +984,44 @@ class QemuVM(BaseVM):
|
|||||||
def _network_options(self):
|
def _network_options(self):
|
||||||
|
|
||||||
network_options = []
|
network_options = []
|
||||||
adapter_number = 0
|
network_options.extend(["-net", "none"]) # we do not want any user networking back-end if no adapter is connected.
|
||||||
for adapter in self._ethernet_adapters:
|
for adapter_number, adapter in enumerate(self._ethernet_adapters):
|
||||||
# TODO: let users specify a base mac address
|
# TODO: let users specify a base mac address
|
||||||
mac = "00:00:ab:%s:%s:%02x" % (self.id[-4:-2], self.id[-2:], adapter_number)
|
mac = "00:00:ab:%s:%s:%02x" % (self.id[-4:-2], self.id[-2:], adapter_number)
|
||||||
if self._legacy_networking:
|
|
||||||
network_options.extend(["-net", "nic,vlan={},macaddr={},model={}".format(adapter_number, mac, self._adapter_type)])
|
|
||||||
else:
|
|
||||||
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:
|
|
||||||
if isinstance(nio, NIOUDP):
|
|
||||||
if self._legacy_networking:
|
if self._legacy_networking:
|
||||||
|
# legacy QEMU networking syntax (-net)
|
||||||
|
if nio:
|
||||||
|
network_options.extend(["-net", "nic,vlan={},macaddr={},model={}".format(adapter_number, mac, self._adapter_type)])
|
||||||
|
if isinstance(nio, NIOUDP):
|
||||||
network_options.extend(["-net", "udp,vlan={},name=gns3-{},sport={},dport={},daddr={}".format(adapter_number,
|
network_options.extend(["-net", "udp,vlan={},name=gns3-{},sport={},dport={},daddr={}".format(adapter_number,
|
||||||
adapter_number,
|
adapter_number,
|
||||||
nio.lport,
|
nio.lport,
|
||||||
nio.rport,
|
nio.rport,
|
||||||
nio.rhost)])
|
nio.rhost)])
|
||||||
|
elif isinstance(nio, NIOTAP):
|
||||||
|
network_options.extend(["-net", "tap,name=gns3-{},ifname={}".format(adapter_number, nio.tap_device)])
|
||||||
|
elif isinstance(nio, NIONAT):
|
||||||
|
network_options.extend(["-net", "user,vlan={},name=gns3-{}".format(adapter_number, adapter_number)])
|
||||||
else:
|
else:
|
||||||
|
network_options.extend(["-net", "nic,vlan={},macaddr={},model={}".format(adapter_number, mac, self._adapter_type)])
|
||||||
|
|
||||||
|
else:
|
||||||
|
# newer QEMU networking syntax
|
||||||
|
if nio:
|
||||||
|
network_options.extend(["-device", "{},mac={},netdev=gns3-{}".format(self._adapter_type, mac, adapter_number)])
|
||||||
|
if isinstance(nio, NIOUDP):
|
||||||
network_options.extend(["-netdev", "socket,id=gns3-{},udp={}:{},localaddr={}:{}".format(adapter_number,
|
network_options.extend(["-netdev", "socket,id=gns3-{},udp={}:{},localaddr={}:{}".format(adapter_number,
|
||||||
nio.rhost,
|
nio.rhost,
|
||||||
nio.rport,
|
nio.rport,
|
||||||
self._host,
|
self._host,
|
||||||
nio.lport)])
|
nio.lport)])
|
||||||
elif isinstance(nio, NIOTAP):
|
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)])
|
network_options.extend(["-netdev", "tap,id=gns3-{},ifname={}".format(adapter_number, nio.tap_device)])
|
||||||
else:
|
elif isinstance(nio, NIONAT):
|
||||||
if self._legacy_networking:
|
|
||||||
network_options.extend(["-net", "user,vlan={},name=gns3-{}".format(adapter_number, adapter_number)])
|
|
||||||
else:
|
|
||||||
network_options.extend(["-netdev", "user,id=gns3-{}".format(adapter_number)])
|
network_options.extend(["-netdev", "user,id=gns3-{}".format(adapter_number)])
|
||||||
adapter_number += 1
|
else:
|
||||||
|
network_options.extend(["-device", "{},mac={}".format(self._adapter_type, mac)])
|
||||||
|
|
||||||
return network_options
|
return network_options
|
||||||
|
|
||||||
|
@ -78,6 +78,16 @@ NIO_SCHEMA = {
|
|||||||
"required": ["type", "ethernet_device"],
|
"required": ["type", "ethernet_device"],
|
||||||
"additionalProperties": False
|
"additionalProperties": False
|
||||||
},
|
},
|
||||||
|
"NAT": {
|
||||||
|
"description": "NAT Network Input/Output",
|
||||||
|
"properties": {
|
||||||
|
"type": {
|
||||||
|
"enum": ["nio_nat"]
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"required": ["type"],
|
||||||
|
"additionalProperties": False
|
||||||
|
},
|
||||||
"TAP": {
|
"TAP": {
|
||||||
"description": "TAP Network Input/Output",
|
"description": "TAP Network Input/Output",
|
||||||
"properties": {
|
"properties": {
|
||||||
@ -148,6 +158,7 @@ NIO_SCHEMA = {
|
|||||||
{"$ref": "#/definitions/UDP"},
|
{"$ref": "#/definitions/UDP"},
|
||||||
{"$ref": "#/definitions/Ethernet"},
|
{"$ref": "#/definitions/Ethernet"},
|
||||||
{"$ref": "#/definitions/LinuxEthernet"},
|
{"$ref": "#/definitions/LinuxEthernet"},
|
||||||
|
{"$ref": "#/definitions/NAT"},
|
||||||
{"$ref": "#/definitions/TAP"},
|
{"$ref": "#/definitions/TAP"},
|
||||||
{"$ref": "#/definitions/UNIX"},
|
{"$ref": "#/definitions/UNIX"},
|
||||||
{"$ref": "#/definitions/VDE"},
|
{"$ref": "#/definitions/VDE"},
|
||||||
|
Reference in New Issue
Block a user