mirror of
https://github.com/GNS3/gns3-server.git
synced 2025-01-29 15:44:24 +00:00
Disallow to modify a template if changes cannot be written on disk. Fixes #1695
This commit is contained in:
parent
a47fa83cec
commit
98f5454ccb
@ -132,6 +132,20 @@ class Controller:
|
|||||||
self._computes = {}
|
self._computes = {}
|
||||||
self._projects = {}
|
self._projects = {}
|
||||||
|
|
||||||
|
def check_can_write_config(self):
|
||||||
|
"""
|
||||||
|
Check if the controller configuration can be written on disk
|
||||||
|
|
||||||
|
:returns: boolean
|
||||||
|
"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.makedirs(os.path.dirname(self._config_file), exist_ok=True)
|
||||||
|
if not os.access(self._config_file, os.W_OK):
|
||||||
|
raise aiohttp.web.HTTPConflict(text="Change rejected, cannot write to controller configuration file '{}'".format(self._config_file))
|
||||||
|
except OSError as e:
|
||||||
|
raise aiohttp.web.HTTPConflict(text="Change rejected: {}".format(e))
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
"""
|
"""
|
||||||
Save the controller configuration on disk
|
Save the controller configuration on disk
|
||||||
|
@ -177,9 +177,11 @@ class Template:
|
|||||||
|
|
||||||
def update(self, **kwargs):
|
def update(self, **kwargs):
|
||||||
|
|
||||||
self._settings.update(kwargs)
|
|
||||||
from gns3server.controller import Controller
|
from gns3server.controller import Controller
|
||||||
controller = Controller.instance()
|
controller = Controller.instance()
|
||||||
|
Controller.instance().check_can_write_config()
|
||||||
|
self._settings.update(kwargs)
|
||||||
controller.notification.controller_emit("template.updated", self.__json__())
|
controller.notification.controller_emit("template.updated", self.__json__())
|
||||||
controller.save()
|
controller.save()
|
||||||
|
|
||||||
|
@ -93,8 +93,10 @@ class TemplateManager:
|
|||||||
except jsonschema.ValidationError as e:
|
except jsonschema.ValidationError as e:
|
||||||
message = "JSON schema error adding template with JSON data '{}': {}".format(settings, e.message)
|
message = "JSON schema error adding template with JSON data '{}': {}".format(settings, e.message)
|
||||||
raise aiohttp.web.HTTPBadRequest(text=message)
|
raise aiohttp.web.HTTPBadRequest(text=message)
|
||||||
self._templates[template.id] = template
|
|
||||||
from . import Controller
|
from . import Controller
|
||||||
|
Controller.instance().check_can_write_config()
|
||||||
|
self._templates[template.id] = template
|
||||||
Controller.instance().save()
|
Controller.instance().save()
|
||||||
Controller.instance().notification.controller_emit("template.created", template.__json__())
|
Controller.instance().notification.controller_emit("template.created", template.__json__())
|
||||||
return template
|
return template
|
||||||
@ -123,8 +125,9 @@ class TemplateManager:
|
|||||||
template = self.get_template(template_id)
|
template = self.get_template(template_id)
|
||||||
if template.builtin:
|
if template.builtin:
|
||||||
raise aiohttp.web.HTTPConflict(text="Template ID {} cannot be deleted because it is a builtin".format(template_id))
|
raise aiohttp.web.HTTPConflict(text="Template ID {} cannot be deleted because it is a builtin".format(template_id))
|
||||||
self._templates.pop(template_id)
|
|
||||||
from . import Controller
|
from . import Controller
|
||||||
|
Controller.instance().check_can_write_config()
|
||||||
|
self._templates.pop(template_id)
|
||||||
Controller.instance().save()
|
Controller.instance().save()
|
||||||
Controller.instance().notification.controller_emit("template.deleted", template.__json__())
|
Controller.instance().notification.controller_emit("template.deleted", template.__json__())
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user