feat: add support for symbol resolution based on active theme in appliance templates

This commit is contained in:
grossmj committed 2026-11-13 12:08:36 +07:00
1 parent 8cd82f3b6c
commit 6289f81298
3 files changed
+78 -27

No files matched your search

+14 -19
View File
@@ -49,6 +49,12 @@ class ApplianceToTemplate:
Appliance installation.
"""
def __init__(self):
from . import Controller
self._controller = Controller.instance()
def new_template(self, appliance_config, version, server):
"""
Creates a new template from an appliance.
@@ -89,17 +95,11 @@ class ApplianceToTemplate:
if new_template.get("symbol") is None:
if appliance_config["category"] == "guest":
if "docker" in appliance_config:
new_template["symbol"] = ":/symbols/docker_guest.svg"
new_template["symbol"] = self._controller.symbols.resolve_symbol("docker_guest")
else:
new_template["symbol"] = ":/symbols/qemu_guest.svg"
elif appliance_config["category"] == "router":
new_template["symbol"] = ":/symbols/router.svg"
elif appliance_config["category"] == "switch":
new_template["symbol"] = ":/symbols/ethernet_switch.svg"
elif appliance_config["category"] == "multilayer_switch":
new_template["symbol"] = ":/symbols/multilayer_switch.svg"
elif appliance_config["category"] == "firewall":
new_template["symbol"] = ":/symbols/firewall.svg"
new_template["symbol"] = self._controller.symbols.resolve_symbol("qemu_guest")
else:
new_template["symbol"] = self._controller.symbols.resolve_symbol(appliance_config.get("category"))
if "qemu" in appliance_config:
new_template["template_type"] = "qemu"
@@ -114,6 +114,7 @@ class ApplianceToTemplate:
new_template["template_type"] = "docker"
self._add_docker_config(new_template, appliance_config)
print(new_template)
return new_template
def _add_qemu_config(self, new_config, appliance_config, version):
@@ -225,17 +226,11 @@ class ApplianceToTemplate:
# apply a default symbol based on the effective category and template type
if category_before_remap == "guest":
if settings["template_type"] == "docker":
new_template["symbol"] = ":/symbols/docker_guest.svg"
new_template["symbol"] = self._controller.symbols.resolve_symbol("docker_guest")
else:
new_template["symbol"] = ":/symbols/qemu_guest.svg"
new_template["symbol"] = self._controller.symbols.resolve_symbol("qemu_guest")
else:
symbols = {
"router": ":/symbols/router.svg",
"switch": ":/symbols/ethernet_switch.svg",
"multilayer_switch": ":/symbols/multilayer_switch.svg",
"firewall": ":/symbols/firewall.svg",
}
new_template["symbol"] = symbols.get(category_before_remap)
new_template["symbol"] = self._controller.symbols.resolve_symbol(category_before_remap)
if version and version.get("images"):
if settings["template_type"] == "iou":
+7
View File
@@ -20,6 +20,7 @@ CLASSIC_SYMBOL_THEME = {
"cloud": ":/symbols/classic/cloud.svg",
"nat": ":/symbols/classic/nat.svg",
"ethernet_switch": ":/symbols/classic/ethernet_switch.svg",
"switch": ":/symbols/classic/ethernet_switch.svg",
"hub": ":/symbols/classic/hub.svg",
"frame_relay_switch": ":/symbols/classic/frame_relay_switch.svg",
"atm_switch": ":/symbols/classic/atm_switch.svg",
@@ -38,6 +39,7 @@ AFFINITY_SQUARE_BLUE_SYMBOL_THEME = {
"cloud": ":/symbols/affinity/square/blue/cloud.svg",
"nat": ":/symbols/affinity/square/blue/nat.svg",
"ethernet_switch": ":/symbols/affinity/square/blue/switch.svg",
"switch": ":/symbols/affinity/square/blue/switch.svg",
"hub": ":/symbols/affinity/square/blue/hub.svg",
"frame_relay_switch": ":/symbols/affinity/square/blue/isdn.svg",
"atm_switch": ":/symbols/affinity/square/blue/atm.svg",
@@ -56,6 +58,7 @@ AFFINITY_SQUARE_RED_SYMBOL_THEME = {
"cloud": ":/symbols/affinity/square/red/cloud.svg",
"nat": ":/symbols/affinity/square/red/nat.svg",
"ethernet_switch": ":/symbols/affinity/square/red/switch.svg",
"switch": ":/symbols/affinity/square/red/switch.svg",
"hub": ":/symbols/affinity/square/red/hub.svg",
"frame_relay_switch": ":/symbols/affinity/square/red/isdn.svg",
"atm_switch": ":/symbols/affinity/square/red/atm.svg",
@@ -74,6 +77,7 @@ AFFINITY_SQUARE_GRAY_SYMBOL_THEME = {
"cloud": ":/symbols/affinity/square/gray/cloud.svg",
"nat": ":/symbols/affinity/square/gray/nat.svg",
"ethernet_switch": ":/symbols/affinity/square/gray/switch.svg",
"switch": ":/symbols/affinity/square/gray/switch.svg",
"hub": ":/symbols/affinity/square/gray/hub.svg",
"frame_relay_switch": ":/symbols/affinity/square/gray/isdn.svg",
"atm_switch": ":/symbols/affinity/square/gray/atm.svg",
@@ -92,6 +96,7 @@ AFFINITY_CIRCLE_BLUE_SYMBOL_THEME = {
"cloud": ":/symbols/affinity/circle/blue/cloud.svg",
"nat": ":/symbols/affinity/circle/blue/nat.svg",
"ethernet_switch": ":/symbols/affinity/circle/blue/switch.svg",
"switch": ":/symbols/affinity/circle/blue/switch.svg",
"hub": ":/symbols/affinity/circle/blue/hub.svg",
"frame_relay_switch": ":/symbols/affinity/circle/blue/isdn.svg",
"atm_switch": ":/symbols/affinity/circle/blue/atm.svg",
@@ -110,6 +115,7 @@ AFFINITY_CIRCLE_RED_SYMBOL_THEME = {
"cloud": ":/symbols/affinity/circle/red/cloud.svg",
"nat": ":/symbols/affinity/circle/red/nat.svg",
"ethernet_switch": ":/symbols/affinity/circle/red/switch.svg",
"switch": ":/symbols/affinity/circle/red/switch.svg",
"hub": ":/symbols/affinity/circle/red/hub.svg",
"frame_relay_switch": ":/symbols/affinity/circle/red/isdn.svg",
"atm_switch": ":/symbols/affinity/circle/red/atm.svg",
@@ -128,6 +134,7 @@ AFFINITY_CIRCLE_GRAY_SYMBOL_THEME = {
"cloud": ":/symbols/affinity/circle/gray/cloud.svg",
"nat": ":/symbols/affinity/circle/gray/nat.svg",
"ethernet_switch": ":/symbols/affinity/circle/gray/switch.svg",
"switch": ":/symbols/affinity/circle/gray/switch.svg",
"hub": ":/symbols/affinity/circle/gray/hub.svg",
"frame_relay_switch": ":/symbols/affinity/circle/gray/isdn.svg",
"atm_switch": ":/symbols/affinity/circle/gray/atm.svg",