mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 22:11:14 +02:00
Remove generic controller settings API endpoint.
This commit is contained in:
1 parent
cebb56387a
commit
98f04365b7
15 files changed
+120
-118
No files matched your search
@@ -54,9 +54,9 @@ class Controller:
|
||||
self._notification = Notification(self)
|
||||
self.gns3vm = GNS3VM(self)
|
||||
self.symbols = Symbols()
|
||||
|
||||
# FIXME: store settings shared by the different GUI will be replace by dedicated API later
|
||||
self._settings = None
|
||||
self._iou_license_settings = {"iourc_content": "",
|
||||
"license_check": True}
|
||||
self._config_loaded = False
|
||||
self._appliances = {}
|
||||
self._appliance_templates = {}
|
||||
self._appliance_templates_etag = None
|
||||
@@ -150,6 +150,7 @@ class Controller:
|
||||
raise aiohttp.web.HTTPConflict(text="Cannot create new appliance: key '{}' is missing for appliance ID '{}'".format(e, appliance_id))
|
||||
self._appliances[appliance.id] = appliance
|
||||
self.save()
|
||||
self.notification.controller_emit("appliance.created", appliance.__json__())
|
||||
return appliance
|
||||
|
||||
def get_appliance(self, appliance_id):
|
||||
@@ -173,13 +174,12 @@ class Controller:
|
||||
:param appliance_id: appliance identifier
|
||||
"""
|
||||
|
||||
appliance = self._appliances.get(appliance_id)
|
||||
if not appliance:
|
||||
raise aiohttp.web.HTTPNotFound(text="Appliance ID {} doesn't exist".format(appliance_id))
|
||||
appliance = self.get_appliance(appliance_id)
|
||||
if appliance.builtin:
|
||||
raise aiohttp.web.HTTPConflict(text="Appliance ID {} cannot be deleted because it is a builtin".format(appliance_id))
|
||||
self._appliances.pop(appliance_id)
|
||||
self.save()
|
||||
self.notification.controller_emit("appliance.deleted", appliance.__json__())
|
||||
|
||||
def load_appliances(self):
|
||||
|
||||
@@ -231,7 +231,7 @@ class Controller:
|
||||
user=server_config.get("user", ""),
|
||||
password=server_config.get("password", ""),
|
||||
force=True)
|
||||
except aiohttp.web.HTTPConflict as e:
|
||||
except aiohttp.web.HTTPConflict:
|
||||
log.fatal("Cannot access to the local server, make sure something else is not running on the TCP port {}".format(port))
|
||||
sys.exit(1)
|
||||
for c in computes:
|
||||
@@ -276,14 +276,13 @@ class Controller:
|
||||
Save the controller configuration on disk
|
||||
"""
|
||||
|
||||
# We don't save during the loading otherwise we could lost stuff
|
||||
if self._settings is None:
|
||||
if self._config_loaded is False:
|
||||
return
|
||||
|
||||
controller_settings = {"computes": [],
|
||||
"settings": self._settings,
|
||||
"appliances": [],
|
||||
"gns3vm": self.gns3vm.__json__(),
|
||||
"iou_license": self._iou_license_settings,
|
||||
"appliance_templates_etag": self._appliance_templates_etag,
|
||||
"version": __version__}
|
||||
|
||||
@@ -321,14 +320,8 @@ class Controller:
|
||||
controller_settings = json.load(f)
|
||||
except (OSError, ValueError) as e:
|
||||
log.critical("Cannot load configuration file '{}': {}".format(self._config_file, e))
|
||||
self._settings = {}
|
||||
return []
|
||||
|
||||
if "settings" in controller_settings and controller_settings["settings"] is not None:
|
||||
self._settings = controller_settings["settings"]
|
||||
else:
|
||||
self._settings = {}
|
||||
|
||||
# load the appliances
|
||||
if "appliances" in controller_settings:
|
||||
for appliance_settings in controller_settings["appliances"]:
|
||||
@@ -345,9 +338,14 @@ class Controller:
|
||||
if "gns3vm" in controller_settings:
|
||||
self.gns3vm.settings = controller_settings["gns3vm"]
|
||||
|
||||
# load the IOU license settings
|
||||
if "iou_license" in controller_settings:
|
||||
self._iou_license_settings = controller_settings["iou_license"]
|
||||
|
||||
self._appliance_templates_etag = controller_settings.get("appliance_templates_etag")
|
||||
self.load_appliance_templates()
|
||||
self.load_appliances()
|
||||
self._config_loaded = True
|
||||
return controller_settings.get("computes", [])
|
||||
|
||||
async def load_projects(self):
|
||||
@@ -528,26 +526,6 @@ class Controller:
|
||||
log.warning("Cannot load appliance template {} ('{}'): missing key {}".format(vm["appliance_id"], vm.get("name", "unknown"), e))
|
||||
continue
|
||||
|
||||
self._settings = {}
|
||||
|
||||
@property
|
||||
def settings(self):
|
||||
"""
|
||||
Store settings shared by the different GUI will be replace by dedicated API later. Dictionnary
|
||||
"""
|
||||
|
||||
return self._settings
|
||||
|
||||
@settings.setter
|
||||
def settings(self, val):
|
||||
|
||||
self._settings = val
|
||||
self._settings["modification_uuid"] = str(uuid.uuid4()) # We add a modification id to the settings to help the gui to detect changes
|
||||
self.save()
|
||||
self.load_appliance_templates()
|
||||
self.load_appliances()
|
||||
self.notification.controller_emit("settings.updated", val)
|
||||
|
||||
async def add_compute(self, compute_id=None, name=None, force=False, connect=True, **kwargs):
|
||||
"""
|
||||
Add a server to the dictionary of compute servers controlled by this controller
|
||||
@@ -783,6 +761,14 @@ class Controller:
|
||||
|
||||
return self._appliances
|
||||
|
||||
@property
|
||||
def iou_license(self):
|
||||
"""
|
||||
:returns: The dictionary of IOU license settings
|
||||
"""
|
||||
|
||||
return self._iou_license_settings
|
||||
|
||||
def projects_directory(self):
|
||||
|
||||
server_config = Config.instance().get_section_config("Server")
|
||||
|
||||
@@ -96,8 +96,11 @@ class Appliance:
|
||||
|
||||
def update(self, **kwargs):
|
||||
|
||||
#TODO: do not update appliance_id, builtin or appliance_type
|
||||
self._settings.update(kwargs)
|
||||
from gns3server.controller import Controller
|
||||
controller = Controller.instance()
|
||||
controller.notification.controller_emit("appliance.updated", self.__json__())
|
||||
controller.save()
|
||||
|
||||
def __json__(self):
|
||||
"""
|
||||
|
||||
@@ -271,16 +271,17 @@ class Node:
|
||||
if self._label is None:
|
||||
# Apply to label user style or default
|
||||
try:
|
||||
style = qt_font_to_style(self._project.controller.settings["GraphicsView"]["default_label_font"],
|
||||
self._project.controller.settings["GraphicsView"]["default_label_color"])
|
||||
style = None # FIXME: allow configuration of default label font & color on controller
|
||||
#style = qt_font_to_style(self._project.controller.settings["GraphicsView"]["default_label_font"],
|
||||
# self._project.controller.settings["GraphicsView"]["default_label_color"])
|
||||
except KeyError:
|
||||
style = "font-size: 10;font-familly: Verdana"
|
||||
style = "font-family: TypeWriter;font-size: 10.0;font-weight: bold;fill: #000000;fill-opacity: 1.0;"
|
||||
|
||||
self._label = {
|
||||
"y": round(self._height / 2 + 10) * -1,
|
||||
"text": html.escape(self._name),
|
||||
"style": style,
|
||||
"x": None, # None: mean the client should center it
|
||||
"style": style, # None: means the client will apply its default style
|
||||
"x": None, # None: means the client should center it
|
||||
"rotation": 0
|
||||
}
|
||||
|
||||
@@ -483,11 +484,11 @@ class Node:
|
||||
try:
|
||||
# For IOU we need to send the licence everytime
|
||||
if self.node_type == "iou":
|
||||
try:
|
||||
licence = self._project.controller.settings["IOU"]["iourc_content"]
|
||||
except KeyError:
|
||||
license_check = self._project.controller.iou_license.get("license_check", True)
|
||||
iourc_content = self._project.controller.iou_license.get("iourc_content", None)
|
||||
if license_check and not iourc_content:
|
||||
raise aiohttp.web.HTTPConflict(text="IOU licence is not configured")
|
||||
await self.post("/start", timeout=240, data={"iourc_content": licence})
|
||||
await self.post("/start", timeout=240, data={"license_check": license_check, "iourc_content": iourc_content})
|
||||
else:
|
||||
await self.post("/start", data=data, timeout=240)
|
||||
except asyncio.TimeoutError:
|
||||
|
||||
Reference in new issue
Block a user