mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 14:01:15 +02:00
Merge pull request #1467 from GNS3/symbol-themes
Support symbol themes. Ref #1466
This commit is contained in:
350 files changed
+2271
-219
No files matched your search
@@ -312,10 +312,10 @@ class GNS3VM:
|
||||
engine.vcpus = self._settings["vcpus"]
|
||||
engine.headless = self._settings["headless"]
|
||||
compute = await self._controller.add_compute(compute_id="vm",
|
||||
name="GNS3 VM is starting ({})".format(engine.vmname),
|
||||
host=None,
|
||||
force=True,
|
||||
connect=False)
|
||||
name="GNS3 VM is starting ({})".format(engine.vmname),
|
||||
host=None,
|
||||
force=True,
|
||||
connect=False)
|
||||
|
||||
try:
|
||||
await engine.start()
|
||||
@@ -363,8 +363,11 @@ class GNS3VM:
|
||||
if netmask:
|
||||
compute_network = ipaddress.ip_interface("{}/{}".format(compute.host_ip, netmask)).network
|
||||
if vm_network.compare_networks(compute_network) != 0:
|
||||
msg = "The GNS3 VM ({}) is not on the same network as the {} server ({}), please make sure the local server binding is in the same network as the GNS3 VM".format(
|
||||
vm_network, compute_id, compute_network)
|
||||
msg = "The GNS3 VM (IP={}, NETWORK={}) is not on the same network as the {} server (IP={}, NETWORK={}), please make sure the local server binding is in the same network as the GNS3 VM".format(self.ip_address,
|
||||
vm_network,
|
||||
compute_id,
|
||||
compute.host_ip,
|
||||
compute_network)
|
||||
self._controller.notification.controller_emit("log.warning", {"message": msg})
|
||||
except ComputeError as e:
|
||||
log.warning("Could not check the VM is in the same subnet as the local server: {}".format(e))
|
||||
|
||||
@@ -0,0 +1,130 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2018 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/>.
|
||||
|
||||
|
||||
CLASSIC_SYMBOL_THEME = {"cloud": ":/symbols/classic/cloud.svg",
|
||||
"ethernet_switch": ":/symbols/classic/ethernet_switch.svg",
|
||||
"ethernet_hub": ":/symbols/classic/hub.svg",
|
||||
"frame_relay_switch": ":/symbols/classic/frame_relay_switch.svg",
|
||||
"atm_switch": ":/symbols/classic/atm_switch.svg",
|
||||
"router": ":/symbols/classic/router.svg",
|
||||
"multilayer_switch": ":/symbols/classic/multilayer_switch.svg",
|
||||
"firewall": ":/symbols/classic/firewall.svg",
|
||||
"computer": ":/symbols/classic/computer.svg",
|
||||
"vpcs_guest": ":/symbols/classic/vpcs_guest.svg",
|
||||
"qemu_guest": ":/symbols/classic/qemu_guest.svg",
|
||||
"vbox_guest": ":/symbols/classic/vbox_guest.svg",
|
||||
"vmware_guest": ":/symbols/classic/vmware_guest.svg",
|
||||
"docker_guest": ":/symbols/classic/docker_guest.svg"}
|
||||
|
||||
INFINITY_SQUARE_BLUE_SYMBOL_THEME = {"cloud": ":/symbols/affinity/square/blue/cloud.svg",
|
||||
"ethernet_switch": ":/symbols/affinity/square/blue/switch.svg",
|
||||
"ethernet_hub": ":/symbols/affinity/square/blue/hub.svg",
|
||||
"frame_relay_switch.svg": ":/symbols/affinity/square/blue/isdn.svg",
|
||||
"atm_switch": ":/symbols/affinity/square/blue/atm.svg",
|
||||
"router": ":/symbols/affinity/square/blue/router.svg",
|
||||
"multilayer_switch": ":/symbols/affinity/square/blue/multilayer_switch.svg",
|
||||
"firewall": ":/symbols/affinity/square/blue/firewall3.svg",
|
||||
"computer": ":/symbols/affinity/square/blue/client.svg",
|
||||
"vpcs_guest": ":/symbols/affinity/square/blue/client.svg",
|
||||
"qemu_guest": ":/symbols/affinity/square/blue/client_vm.svg",
|
||||
"vbox_guest": ":/symbols/affinity/square/blue/virtualbox.svg",
|
||||
"vmware_guest": ":/symbols/affinity/square/blue/vmware.svg",
|
||||
"docker_guest": ":/symbols/affinity/square/blue/docker.svg"}
|
||||
|
||||
INFINITY_SQUARE_RED_SYMBOL_THEME = {"cloud": ":/symbols/affinity/square/red/cloud.svg",
|
||||
"ethernet_switch": ":/symbols/affinity/square/red/switch.svg",
|
||||
"ethernet_hub": ":/symbols/affinity/square/red/hub.svg",
|
||||
"frame_relay_switch": ":/symbols/affinity/square/red/isdn.svg",
|
||||
"atm_switch": ":/symbols/affinity/square/red/atm.svg",
|
||||
"router": ":/symbols/affinity/square/red/router.svg",
|
||||
"multilayer_switch": ":/symbols/affinity/square/red/multilayer_switch.svg",
|
||||
"firewall": ":/symbols/affinity/square/red/firewall3.svg",
|
||||
"computer": ":/symbols/affinity/square/red/client.svg",
|
||||
"vpcs_guest": ":/symbols/affinity/square/red/client.svg",
|
||||
"qemu_guest": ":/symbols/affinity/square/red/client_vm.svg",
|
||||
"vbox_guest": ":/symbols/affinity/square/red/virtualbox.svg",
|
||||
"vmware_guest": ":/symbols/affinity/square/red/vmware.svg",
|
||||
"docker_guest": ":/symbols/affinity/square/red/docker.svg"}
|
||||
|
||||
INFINITY_SQUARE_GRAY_SYMBOL_THEME = {"cloud": ":/symbols/affinity/square/gray/cloud.svg",
|
||||
"ethernet_switch": ":/symbols/affinity/square/gray/switch.svg",
|
||||
"ethernet_hub": ":/symbols/affinity/square/gray/hub.svg",
|
||||
"frame_relay_switch": ":/symbols/affinity/square/gray/isdn.svg",
|
||||
"atm_switch": ":/symbols/affinity/square/gray/atm.svg",
|
||||
"router": ":/symbols/affinity/square/gray/router.svg",
|
||||
"multilayer_switch": ":/symbols/affinity/square/gray/multilayer_switch.svg",
|
||||
"firewall": ":/symbols/affinity/square/gray/firewall3.svg",
|
||||
"computer": ":/symbols/affinity/square/gray/client.svg",
|
||||
"vpcs_guest": ":/symbols/affinity/square/gray/client.svg",
|
||||
"qemu_guest": ":/symbols/affinity/square/gray/client_vm.svg",
|
||||
"vbox_guest": ":/symbols/affinity/square/gray/virtualbox.svg",
|
||||
"vmware_guest": ":/symbols/affinity/square/gray/vmware.svg",
|
||||
"docker_guest": ":/symbols/affinity/square/gray/docker.svg"}
|
||||
|
||||
INFINITY_CIRCLE_BLUE_SYMBOL_THEME = {"cloud": ":/symbols/affinity/circle/blue/cloud.svg",
|
||||
"ethernet_switch": ":/symbols/affinity/circle/blue/switch.svg",
|
||||
"ethernet_hub": ":/symbols/affinity/circle/blue/hub.svg",
|
||||
"frame_relay_switch": ":/symbols/affinity/circle/blue/isdn.svg",
|
||||
"atm_switch": ":/symbols/affinity/circle/blue/atm.svg",
|
||||
"router": ":/symbols/affinity/circle/blue/router.svg",
|
||||
"multilayer_switch": ":/symbols/affinity/circle/blue/multilayer_switch.svg",
|
||||
"firewall": ":/symbols/affinity/circle/blue/firewall3.svg",
|
||||
"computer": ":/symbols/affinity/circle/blue/client.svg",
|
||||
"vpcs_guest": ":/symbols/affinity/circle/blue/client.svg",
|
||||
"qemu_guest": ":/symbols/affinity/circle/blue/client_vm.svg",
|
||||
"vbox_guest": ":/symbols/affinity/circle/blue/virtualbox.svg",
|
||||
"vmware_guest": ":/symbols/affinity/circle/blue/vmware.svg",
|
||||
"docker_guest": ":/symbols/affinity/circle/blue/docker.svg"}
|
||||
|
||||
INFINITY_CIRCLE_RED_SYMBOL_THEME = {"cloud": ":/symbols/affinity/circle/red/cloud.svg",
|
||||
"ethernet_switch": ":/symbols/affinity/circle/red/switch.svg",
|
||||
"ethernet_hub": ":/symbols/affinity/circle/red/hub.svg",
|
||||
"frame_relay_switch": ":/symbols/affinity/circle/red/isdn.svg",
|
||||
"atm_switch": ":/symbols/affinity/circle/red/atm.svg",
|
||||
"router": ":/symbols/affinity/circle/red/router.svg",
|
||||
"multilayer_switch": ":/symbols/affinity/circle/red/multilayer_switch.svg",
|
||||
"firewall": ":/symbols/affinity/circle/red/firewall3.svg",
|
||||
"computer": ":/symbols/affinity/circle/red/client.svg",
|
||||
"vpcs_guest": ":/symbols/affinity/circle/red/client.svg",
|
||||
"qemu_guest": ":/symbols/affinity/circle/red/client_vm.svg",
|
||||
"vbox_guest": ":/symbols/affinity/circle/red/virtualbox.svg",
|
||||
"vmware_guest": ":/symbols/affinity/circle/red/vmware.svg",
|
||||
"docker_guest": ":/symbols/affinity/circle/red/docker.svg"}
|
||||
|
||||
INFINITY_CIRCLE_GRAY_SYMBOL_THEME = {"cloud": ":/symbols/affinity/circle/gray/cloud.svg",
|
||||
"ethernet_switch": ":/symbols/affinity/circle/gray/switch.svg",
|
||||
"ethernet_hub": ":/symbols/affinity/circle/gray/hub.svg",
|
||||
"frame_relay_switch": ":/symbols/affinity/circle/gray/isdn.svg",
|
||||
"atm_switch": ":/symbols/affinity/circle/gray/atm.svg",
|
||||
"router": ":/symbols/affinity/circle/gray/router.svg",
|
||||
"multilayer_switch": ":/symbols/affinity/circle/gray/multilayer_switch.svg",
|
||||
"firewall": ":/symbols/affinity/circle/gray/firewall3.svg",
|
||||
"computer": ":/symbols/affinity/circle/gray/client.svg",
|
||||
"vpcs_guest": ":/symbols/affinity/circle/gray/client.svg",
|
||||
"qemu_guest": ":/symbols/affinity/circle/gray/client_vm.svg",
|
||||
"vbox_guest": ":/symbols/affinity/circle/gray/virtualbox.svg",
|
||||
"vmware_guest": ":/symbols/affinity/circle/gray/vmware.svg",
|
||||
"docker_guest": ":/symbols/affinity/circle/gray/docker.svg"}
|
||||
|
||||
BUILTIN_SYMBOL_THEMES = {"Classic": CLASSIC_SYMBOL_THEME,
|
||||
"Infinity-square-blue": INFINITY_SQUARE_BLUE_SYMBOL_THEME,
|
||||
"Infinity-square-red": INFINITY_SQUARE_RED_SYMBOL_THEME,
|
||||
"Infinity-square-gray": INFINITY_SQUARE_GRAY_SYMBOL_THEME,
|
||||
"Infinity-circle-blue": INFINITY_CIRCLE_BLUE_SYMBOL_THEME,
|
||||
"Infinity-circle-red": INFINITY_CIRCLE_RED_SYMBOL_THEME,
|
||||
"Infinity-circle-gray": INFINITY_CIRCLE_GRAY_SYMBOL_THEME}
|
||||
@@ -16,8 +16,9 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
import posixpath
|
||||
|
||||
|
||||
from .symbol_themes import BUILTIN_SYMBOL_THEMES
|
||||
from ..utils.get_resource import get_resource
|
||||
from ..utils.picture import get_size
|
||||
from ..config import Config
|
||||
@@ -32,14 +33,32 @@ class Symbols:
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
|
||||
try:
|
||||
self.list()
|
||||
except OSError: # The error will be raised and forward later
|
||||
except OSError: # The error will be raised and forwarded later
|
||||
pass
|
||||
|
||||
# Keep a cache of symbols size
|
||||
self._symbol_size_cache = {}
|
||||
self._current_theme = "Infinity-square-gray"
|
||||
self._themes = BUILTIN_SYMBOL_THEMES
|
||||
|
||||
@property
|
||||
def theme(self):
|
||||
|
||||
return self._current_theme
|
||||
|
||||
@theme.setter
|
||||
def theme(self, theme):
|
||||
|
||||
if not self._themes.get(theme):
|
||||
log.error("Could not find symbol theme '{}'".format(theme))
|
||||
return
|
||||
self._current_theme = theme
|
||||
|
||||
def list(self):
|
||||
|
||||
self._symbols_path = {}
|
||||
symbols = []
|
||||
if get_resource("symbols"):
|
||||
@@ -47,13 +66,11 @@ class Symbols:
|
||||
for filename in files:
|
||||
if filename.startswith('.'):
|
||||
continue
|
||||
symbol_file = os.path.relpath(os.path.join(root, filename), get_resource("symbols"))
|
||||
symbol_file = posixpath.normpath(os.path.relpath(os.path.join(root, filename), get_resource("symbols"))).replace('\\', '/')
|
||||
symbol_id = ':/symbols/' + symbol_file
|
||||
symbols.append({
|
||||
'symbol_id': symbol_id,
|
||||
'filename': symbol_file,
|
||||
'builtin': True,
|
||||
})
|
||||
symbols.append({'symbol_id': symbol_id,
|
||||
'filename': symbol_file,
|
||||
'builtin': True})
|
||||
self._symbols_path[symbol_id] = os.path.join(root, filename)
|
||||
|
||||
directory = self.symbols_path()
|
||||
@@ -62,12 +79,10 @@ class Symbols:
|
||||
for filename in files:
|
||||
if filename.startswith('.'):
|
||||
continue
|
||||
symbol_file = os.path.relpath(os.path.join(root, filename), directory)
|
||||
symbols.append({
|
||||
'symbol_id': symbol_file,
|
||||
'filename': symbol_file,
|
||||
'builtin': False,
|
||||
})
|
||||
symbol_file = posixpath.normpath(os.path.relpath(os.path.join(root, filename), directory)).replace('\\', '/')
|
||||
symbols.append({'symbol_id': symbol_file,
|
||||
'filename': symbol_file,
|
||||
'builtin': False,})
|
||||
self._symbols_path[symbol_file] = os.path.join(root, filename)
|
||||
|
||||
symbols.sort(key=lambda x: x["filename"])
|
||||
@@ -84,17 +99,21 @@ class Symbols:
|
||||
return directory
|
||||
|
||||
def get_path(self, symbol_id):
|
||||
symbol_filename = os.path.splitext(os.path.basename(symbol_id))[0]
|
||||
theme = self._themes.get(self._current_theme, {})
|
||||
if not theme:
|
||||
log.error("Could not find symbol theme '{}'".format(self._current_theme))
|
||||
try:
|
||||
return self._symbols_path[symbol_id]
|
||||
# Symbol not found, let's refresh the cache
|
||||
return self._symbols_path[theme.get(symbol_filename, symbol_id)]
|
||||
except KeyError:
|
||||
# Symbol not found, let's refresh the cache
|
||||
try:
|
||||
self.list()
|
||||
return self._symbols_path[symbol_id]
|
||||
except (OSError, KeyError):
|
||||
log.warning("Could not retrieve symbol '{}'".format(symbol_id))
|
||||
symbols_path = self._symbols_path
|
||||
return symbols_path[":/symbols/computer.svg"]
|
||||
return symbols_path.get(":/symbols/classic/{}".format(os.path.basename(symbol_id)), symbols_path[":/symbols/classic/computer.svg"])
|
||||
|
||||
def get_size(self, symbol_id):
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user