mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
Merge branch '2.0' into 2.1
This commit is contained in:
29 files changed
+548
-55
No files matched your search
@@ -211,7 +211,8 @@ class EthernetSwitch(Device):
|
||||
nio = self._nios[port_number]
|
||||
if isinstance(nio, NIOUDP):
|
||||
self.manager.port_manager.release_udp_port(nio.lport, self._project)
|
||||
yield from self._hypervisor.send('ethsw remove_nio "{name}" {nio}'.format(name=self._name, nio=nio))
|
||||
if self._hypervisor:
|
||||
yield from self._hypervisor.send('ethsw remove_nio "{name}" {nio}'.format(name=self._name, nio=nio))
|
||||
|
||||
log.info('Ethernet switch "{name}" [{id}]: NIO {nio} removed from port {port}'.format(name=self._name,
|
||||
id=self._id,
|
||||
|
||||
@@ -24,6 +24,7 @@ import asyncio
|
||||
import time
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
import glob
|
||||
import shlex
|
||||
import base64
|
||||
@@ -1474,7 +1475,7 @@ class Router(BaseNode):
|
||||
try:
|
||||
with open(startup_config_path, "r+", encoding="utf-8", errors="replace") as f:
|
||||
old_config = f.read()
|
||||
new_config = old_config.replace(self.name, new_name)
|
||||
new_config = re.sub(r"^hostname .+$", "hostname " + new_name, old_config, flags=re.MULTILINE)
|
||||
f.seek(0)
|
||||
f.write(new_config)
|
||||
except OSError as e:
|
||||
|
||||
@@ -301,7 +301,7 @@ class IOUVM(BaseNode):
|
||||
|
||||
if self.startup_config_file:
|
||||
content = self.startup_config_content
|
||||
content = content.replace(self._name, new_name)
|
||||
content = re.sub(r"^hostname .+$", "hostname " + new_name, content, flags=re.MULTILINE)
|
||||
self.startup_config_content = content
|
||||
|
||||
super(IOUVM, IOUVM).name.__set__(self, new_name)
|
||||
@@ -1161,7 +1161,7 @@ class IOUVM(BaseNode):
|
||||
bay=adapter_number,
|
||||
unit=port_number,
|
||||
output_file=output_file,
|
||||
data_link_type=data_link_type))
|
||||
data_link_type=re.sub("^DLT_", "", data_link_type)))
|
||||
|
||||
@asyncio.coroutine
|
||||
def stop_capture(self, adapter_number, port_number):
|
||||
|
||||
@@ -303,6 +303,16 @@ class VirtualBoxVM(BaseNode):
|
||||
if self.acpi_shutdown:
|
||||
# use ACPI to shutdown the VM
|
||||
result = yield from self._control_vm("acpipowerbutton")
|
||||
trial = 0
|
||||
while True:
|
||||
vm_state = yield from self._get_vm_state()
|
||||
if vm_state == "poweroff":
|
||||
break
|
||||
yield from asyncio.sleep(1)
|
||||
trial += 1
|
||||
if trial >= 120:
|
||||
yield from self._control_vm("poweroff")
|
||||
break
|
||||
self.status = "stopped"
|
||||
log.debug("ACPI shutdown result: {}".format(result))
|
||||
else:
|
||||
|
||||
@@ -104,7 +104,7 @@ class VPCSVM(BaseNode):
|
||||
Check if VPCS is available with the correct version.
|
||||
"""
|
||||
|
||||
path = self.vpcs_path
|
||||
path = self._vpcs_path()
|
||||
if not path:
|
||||
raise VPCSError("No path to a VPCS executable has been set")
|
||||
|
||||
@@ -144,8 +144,7 @@ class VPCSVM(BaseNode):
|
||||
else:
|
||||
return None
|
||||
|
||||
@property
|
||||
def vpcs_path(self):
|
||||
def _vpcs_path(self):
|
||||
"""
|
||||
Returns the VPCS executable path.
|
||||
|
||||
@@ -170,6 +169,7 @@ class VPCSVM(BaseNode):
|
||||
if self.script_file:
|
||||
content = self.startup_script
|
||||
content = content.replace(self._name, new_name)
|
||||
content = re.sub(r"^set pcname .+$", "set pcname " + new_name, content, flags=re.MULTILINE)
|
||||
self.startup_script = content
|
||||
|
||||
super(VPCSVM, VPCSVM).name.__set__(self, new_name)
|
||||
@@ -215,7 +215,7 @@ class VPCSVM(BaseNode):
|
||||
Checks if the VPCS executable version is >= 0.8b or == 0.6.1.
|
||||
"""
|
||||
try:
|
||||
output = yield from subprocess_check_output(self.vpcs_path, "-v", cwd=self.working_dir)
|
||||
output = yield from subprocess_check_output(self._vpcs_path(), "-v", cwd=self.working_dir)
|
||||
match = re.search("Welcome to Virtual PC Simulator, version ([0-9a-z\.]+)", output)
|
||||
if match:
|
||||
version = match.group(1)
|
||||
@@ -223,7 +223,7 @@ class VPCSVM(BaseNode):
|
||||
if self._vpcs_version < parse_version("0.6.1"):
|
||||
raise VPCSError("VPCS executable version must be >= 0.6.1 but not a 0.8")
|
||||
else:
|
||||
raise VPCSError("Could not determine the VPCS version for {}".format(self.vpcs_path))
|
||||
raise VPCSError("Could not determine the VPCS version for {}".format(self._vpcs_path()))
|
||||
except (OSError, subprocess.SubprocessError) as e:
|
||||
raise VPCSError("Error while looking for the VPCS version: {}".format(e))
|
||||
|
||||
@@ -268,8 +268,8 @@ class VPCSVM(BaseNode):
|
||||
self.status = "started"
|
||||
except (OSError, subprocess.SubprocessError) as e:
|
||||
vpcs_stdout = self.read_vpcs_stdout()
|
||||
log.error("Could not start VPCS {}: {}\n{}".format(self.vpcs_path, e, vpcs_stdout))
|
||||
raise VPCSError("Could not start VPCS {}: {}\n{}".format(self.vpcs_path, e, vpcs_stdout))
|
||||
log.error("Could not start VPCS {}: {}\n{}".format(self._vpcs_path(), e, vpcs_stdout))
|
||||
raise VPCSError("Could not start VPCS {}: {}\n{}".format(self._vpcs_path(), e, vpcs_stdout))
|
||||
|
||||
def _termination_callback(self, returncode):
|
||||
"""
|
||||
@@ -512,7 +512,7 @@ class VPCSVM(BaseNode):
|
||||
|
||||
"""
|
||||
|
||||
command = [self.vpcs_path]
|
||||
command = [self._vpcs_path()]
|
||||
command.extend(["-p", str(self._internal_console_port)]) # listen to console port
|
||||
command.extend(["-m", str(self._manager.get_mac_id(self.id))]) # the unique ID is used to set the MAC address offset
|
||||
command.extend(["-i", "1"]) # option to start only one VPC instance
|
||||
|
||||
@@ -55,16 +55,21 @@ class Controller:
|
||||
def start(self):
|
||||
log.info("Start controller")
|
||||
self.load_base_files()
|
||||
yield from self.load()
|
||||
server_config = Config.instance().get_section_config("Server")
|
||||
host = server_config.get("host", "localhost")
|
||||
|
||||
# If console_host is 0.0.0.0 client will use the ip they use
|
||||
# to connect to the controller
|
||||
console_host = host
|
||||
if host == "0.0.0.0":
|
||||
host = "127.0.0.1"
|
||||
|
||||
name = socket.gethostname()
|
||||
if name == "gns3vm":
|
||||
name = "Main server"
|
||||
|
||||
yield from self.add_compute(compute_id="local",
|
||||
name=socket.gethostname(),
|
||||
name=name,
|
||||
protocol=server_config.get("protocol", "http"),
|
||||
host=host,
|
||||
console_host=console_host,
|
||||
@@ -72,6 +77,7 @@ class Controller:
|
||||
user=server_config.get("user", ""),
|
||||
password=server_config.get("password", ""),
|
||||
force=True)
|
||||
yield from self._load_controller_settings()
|
||||
yield from self.load_projects()
|
||||
yield from self.gns3vm.auto_start_vm()
|
||||
yield from self._project_auto_open()
|
||||
@@ -118,7 +124,7 @@ class Controller:
|
||||
json.dump(data, f, indent=4)
|
||||
|
||||
@asyncio.coroutine
|
||||
def load(self):
|
||||
def _load_controller_settings(self):
|
||||
"""
|
||||
Reload the controller configuration from disk
|
||||
"""
|
||||
@@ -279,7 +285,7 @@ class Controller:
|
||||
return None
|
||||
|
||||
for compute in self._computes.values():
|
||||
if name and compute.name == name:
|
||||
if name and compute.name == name and not force:
|
||||
raise aiohttp.web.HTTPConflict(text='Compute name "{}" already exists'.format(name))
|
||||
|
||||
compute = Compute(compute_id=compute_id, controller=self, name=name, **kwargs)
|
||||
|
||||
@@ -426,7 +426,7 @@ class Compute:
|
||||
except aiohttp.errors.WSServerHandshakeError:
|
||||
self._ws = None
|
||||
break
|
||||
if response.tp == aiohttp.MsgType.closed or response.tp == aiohttp.MsgType.error:
|
||||
if response.tp == aiohttp.MsgType.closed or response.tp == aiohttp.MsgType.error or response.data is None:
|
||||
self._connected = False
|
||||
break
|
||||
msg = json.loads(response.data)
|
||||
|
||||
@@ -43,6 +43,7 @@ class Drawing:
|
||||
self._id = str(uuid.uuid4())
|
||||
else:
|
||||
self._id = drawing_id
|
||||
self._svg = "<svg></svg>"
|
||||
self.svg = svg
|
||||
self._x = x
|
||||
self._y = y
|
||||
|
||||
@@ -47,6 +47,9 @@ def export_project(project, temporary_dir, include_images=False, keep_compute_id
|
||||
if project.is_running():
|
||||
raise aiohttp.web.HTTPConflict(text="Running topology could not be exported")
|
||||
|
||||
# Make sure we save the project
|
||||
project.dump()
|
||||
|
||||
z = zipstream.ZipFile(allowZip64=True)
|
||||
|
||||
if not os.path.exists(project._path):
|
||||
|
||||
@@ -222,8 +222,14 @@ class GNS3VM:
|
||||
"""
|
||||
engine = self._get_engine(engine)
|
||||
vms = []
|
||||
for vm in (yield from engine.list()):
|
||||
vms.append({"vmname": vm["vmname"]})
|
||||
try:
|
||||
for vm in (yield from engine.list()):
|
||||
vms.append({"vmname": vm["vmname"]})
|
||||
except GNS3VMError as e:
|
||||
# We raise error only if user activated the GNS3 VM
|
||||
# otherwise you have noise when VMware is not installed
|
||||
if self.enable:
|
||||
raise e
|
||||
return vms
|
||||
|
||||
@asyncio.coroutine
|
||||
@@ -267,6 +273,7 @@ class GNS3VM:
|
||||
engine.vmname = self._settings["vmname"]
|
||||
engine.ram = self._settings["ram"]
|
||||
engine.vpcus = self._settings["vcpus"]
|
||||
engine.headless = self._settings["headless"]
|
||||
compute = yield from self._controller.add_compute(compute_id="vm",
|
||||
name="GNS3 VM is starting ({})".format(engine.vmname),
|
||||
host=None,
|
||||
@@ -277,6 +284,7 @@ class GNS3VM:
|
||||
except Exception as e:
|
||||
yield from self._controller.delete_compute("vm")
|
||||
log.error("Can't start the GNS3 VM: {}", str(e))
|
||||
yield from compute.update(name="GNS3 VM ({})".format(engine.vmname))
|
||||
raise e
|
||||
yield from compute.update(name="GNS3 VM ({})".format(engine.vmname),
|
||||
protocol=self.protocol,
|
||||
|
||||
@@ -221,7 +221,7 @@ class VirtualBoxGNS3VM(BaseGNS3VM):
|
||||
second to a GNS3 endpoint in order to get the list of the interfaces and
|
||||
their IP and after that match it with VirtualBox host only.
|
||||
"""
|
||||
remaining_try = 240
|
||||
remaining_try = 300
|
||||
while remaining_try > 0:
|
||||
json_data = None
|
||||
session = aiohttp.ClientSession()
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import aiohttp
|
||||
|
||||
from .atm_port import ATMPort
|
||||
from .frame_relay_port import FrameRelayPort
|
||||
from .gigabitethernet_port import GigabitEthernetPort
|
||||
@@ -64,11 +66,14 @@ class StandardPortFactory:
|
||||
port_name = first_port_name
|
||||
port = PortFactory(port_name, segment_number, adapter_number, port_number, "ethernet")
|
||||
else:
|
||||
port_name = port_name_format.format(
|
||||
interface_number,
|
||||
segment_number,
|
||||
adapter=adapter_number,
|
||||
**cls._generate_replacement(interface_number, segment_number))
|
||||
try:
|
||||
port_name = port_name_format.format(
|
||||
interface_number,
|
||||
segment_number,
|
||||
adapter=adapter_number,
|
||||
**cls._generate_replacement(interface_number, segment_number))
|
||||
except (ValueError, KeyError) as e:
|
||||
raise aiohttp.web.HTTPConflict(text="Invalid port name format {}: {}".format(port_name_format, str(e)))
|
||||
port = PortFactory(port_name, segment_number, adapter_number, port_number, "ethernet")
|
||||
interface_number += 1
|
||||
if port_segment_size:
|
||||
|
||||
@@ -293,6 +293,8 @@ class Project:
|
||||
name = base_name.format(number, id=number, name="Node")
|
||||
except KeyError as e:
|
||||
raise aiohttp.web.HTTPConflict(text="{" + e.args[0] + "} is not a valid replacement string in the node name")
|
||||
except ValueError as e:
|
||||
raise aiohttp.web.HTTPConflict(text="{} is not a valid replacement string in the node name".format(base_name))
|
||||
if name not in self._allocated_node_names:
|
||||
self._allocated_node_names.add(name)
|
||||
return name
|
||||
|
||||
@@ -39,16 +39,17 @@ class Symbols:
|
||||
def list(self):
|
||||
self._symbols_path = {}
|
||||
symbols = []
|
||||
for file in os.listdir(get_resource("symbols")):
|
||||
if file.startswith('.'):
|
||||
continue
|
||||
symbol_id = ':/symbols/' + file
|
||||
symbols.append({
|
||||
'symbol_id': symbol_id,
|
||||
'filename': file,
|
||||
'builtin': True,
|
||||
})
|
||||
self._symbols_path[symbol_id] = os.path.join(get_resource("symbols"), file)
|
||||
if get_resource("symbols"):
|
||||
for file in os.listdir(get_resource("symbols")):
|
||||
if file.startswith('.'):
|
||||
continue
|
||||
symbol_id = ':/symbols/' + file
|
||||
symbols.append({
|
||||
'symbol_id': symbol_id,
|
||||
'filename': file,
|
||||
'builtin': True,
|
||||
})
|
||||
self._symbols_path[symbol_id] = os.path.join(get_resource("symbols"), file)
|
||||
directory = self.symbols_path()
|
||||
if directory:
|
||||
for file in os.listdir(directory):
|
||||
|
||||
@@ -363,6 +363,14 @@ def _convert_1_3_later(topo, topo_path):
|
||||
node["symbol"] = ":/symbols/vbox_guest.svg"
|
||||
elif old_node["type"] == "IOUDevice":
|
||||
node["node_type"] = "iou"
|
||||
node["port_name_format"] = old_node.get("port_name_format", "Ethernet{segment0}/{port0}")
|
||||
node["port_segment_size"] = int(old_node.get("port_segment_size", "4"))
|
||||
if node["symbol"] is None:
|
||||
if "l2" in node["properties"].get("path", ""):
|
||||
node["symbol"] = ":/symbols/multilayer_switch.svg"
|
||||
else:
|
||||
node["symbol"] = ":/symbols/router.svg"
|
||||
|
||||
elif old_node["type"] == "Cloud":
|
||||
old_node["ports"] = _create_cloud(node, old_node, ":/symbols/cloud.svg")
|
||||
elif old_node["type"] == "Host":
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
import os
|
||||
import sys
|
||||
import struct
|
||||
import aiohttp
|
||||
import platform
|
||||
|
||||
|
||||
@@ -94,6 +95,7 @@ class CrashReport:
|
||||
"os:win_32": " ".join(platform.win32_ver()),
|
||||
"os:mac": "{} {}".format(platform.mac_ver()[0], platform.mac_ver()[2]),
|
||||
"os:linux": " ".join(platform.linux_distribution()),
|
||||
"aiohttp:version": aiohttp.__version__,
|
||||
"python:version": "{}.{}.{}".format(sys.version_info[0],
|
||||
sys.version_info[1],
|
||||
sys.version_info[2]),
|
||||
|
||||
@@ -120,7 +120,8 @@ def _svg_convert_size(size):
|
||||
"pc": 15,
|
||||
"mm": 3.543307,
|
||||
"cm": 35.43307,
|
||||
"in": 90
|
||||
"in": 90,
|
||||
"px": 1
|
||||
}
|
||||
if len(size) > 3:
|
||||
if size[-2:] in conversion_table:
|
||||
|
||||
@@ -32,7 +32,7 @@ if "dev" in __version__:
|
||||
import os
|
||||
import subprocess
|
||||
if os.path.exists(os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", ".git")):
|
||||
r = subprocess.run(["git", "rev-parse", "--short", "HEAD"], stdout=subprocess.PIPE).stdout.decode().strip("\n")
|
||||
r = subprocess.check_output(["git", "rev-parse", "--short", "HEAD"]).decode().strip("\n")
|
||||
__version__ += "-" + r
|
||||
except Exception as e:
|
||||
print(e)
|
||||
@@ -39,6 +39,7 @@ class Response(aiohttp.web.Response):
|
||||
self._route = route
|
||||
self._output_schema = output_schema
|
||||
self._request = request
|
||||
headers['Connection'] = "close" # Disable keep alive because create trouble with old Qt (5.2, 5.3 and 5.4)
|
||||
headers['X-Route'] = self._route
|
||||
headers['Server'] = "Python/{0[0]}.{0[1]} GNS3/{1}".format(sys.version_info, __version__)
|
||||
super().__init__(headers=headers, **kwargs)
|
||||
|
||||
Reference in new issue
Block a user