Fill cloud interface server side

Fix https://github.com/GNS3/gns3-gui/issues/1535
This commit is contained in:
Julien Duponchelle committed 2016-09-22 17:46:32 +02:00
1 parent 286112ced4
commit 29563ed7bc
6 files changed
+119 -12

No files matched your search

+16 -5
View File
@@ -23,7 +23,7 @@ from ...error import NodeError
from ...base_node import BaseNode
from ...nios.nio_udp import NIOUDP
from gns3server.utils.interfaces import interfaces
import gns3server.utils.interfaces
import gns3server.utils.asyncio
import logging
@@ -41,18 +41,29 @@ class Cloud(BaseNode):
:param manager: Parent VM Manager
"""
def __init__(self, name, node_id, project, manager, ports=None):
def __init__(self, name, node_id, project, manager, ports=[]):
super().__init__(name, node_id, project, manager)
self._nios = {}
self._ports_mapping = []
if ports:
# If the cloud is not configured we fill it with host interfaces
if not ports or len(ports) == 0:
self._ports_mapping = []
network_interfaces = gns3server.utils.interfaces.interfaces()
for interface in network_interfaces:
if not interface["special"]:
self._ports_mapping.append({
"interface": interface["name"],
"type": interface["type"],
"port_number": len(self._ports_mapping),
"name": interface["name"]
})
else:
self._ports_mapping = ports
def __json__(self):
host_interfaces = []
network_interfaces = interfaces()
network_interfaces = gns3server.utils.interfaces.interfaces()
for interface in network_interfaces:
host_interfaces.append({"name": interface["name"],
"type": interface["type"],
+12 -4
View File
@@ -29,19 +29,27 @@ class Nat(Cloud):
"""
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if "virbr0" not in [interface["name"] for interface in gns3server.utils.interfaces.interfaces()]:
raise NodeError("virbr0 is missing. You need to install libvirt")
self.ports_mapping = [
ports = [
{
"name": "virbr0",
"name": "nat0",
"type": "ethernet",
"interface": "virbr0",
"port_number": 0
}
]
super().__init__(*args, ports=ports)
@property
def ports_mapping(self):
return self._ports_mapping
@ports_mapping.setter
def ports_mapping(self, ports):
# It's not allowed to change it
pass
@classmethod
def is_supported(self):