Monitor IOU nvram for change

With the save as you go we need to save the startup config
when a change appear instead of the old commit system.
This commit is contained in:
Julien Duponchelle committed 2016-06-10 18:26:01 +02:00
1 parent 182a979e71
commit 69334665d2
4 files changed
+28 -26

No files matched your search

-17
View File
@@ -72,23 +72,6 @@ class IOU(BaseManager):
yield from super().close_node(node_id, *args, **kwargs)
return node
@asyncio.coroutine
def project_committed(self, project):
"""
Called when a project has been committed.
:param project: Project instance
"""
# save the configs when the project is committed
for node in self._nodes.copy().values():
if node.project.id == project.id:
try:
node.save_configs()
except IOUError as e:
log.warning(e)
continue
def get_application_id(self, node_id):
"""
Get an unique application identifier for IOU.
+23 -3
View File
@@ -46,10 +46,10 @@ from ..base_node import BaseNode
from .utils.iou_import import nvram_import
from .utils.iou_export import nvram_export
from .ioucon import start_ioucon
from gns3server.utils.file_watcher import FileWatcher
import gns3server.utils.asyncio
import gns3server.utils.images
import logging
import sys
log = logging.getLogger(__name__)
@@ -91,9 +91,17 @@ class IOUVM(BaseNode):
self._ram = 256 # Megabytes
self._l1_keepalives = False # used to overcome the always-up Ethernet interfaces (not supported by all IOSes).
self._nvram_watcher = None
def _config(self):
return self._manager.config.get_section_config("IOU")
def _nvram_changed(self, path):
"""
Called when the NVRAM file as changed
"""
self.save_configs()
@asyncio.coroutine
def close(self):
"""
@@ -424,6 +432,12 @@ class IOUVM(BaseNode):
self.iourc_path,
hostname))
def _nvram_file(self):
"""
Path to the nvram file
"""
return os.path.join(self.working_dir, "nvram_{:05d}".format(self.application_id))
def _push_configs_to_nvram(self):
"""
Push the startup-config and private-config content to the NVRAM.
@@ -431,7 +445,7 @@ class IOUVM(BaseNode):
startup_config_content = self.startup_config_content
if startup_config_content:
nvram_file = os.path.join(self.working_dir, "nvram_{:05d}".format(self.application_id))
nvram_file = self._nvram_file()
try:
if not os.path.exists(nvram_file):
open(nvram_file, "a").close()
@@ -489,6 +503,8 @@ class IOUVM(BaseNode):
# check if there is enough RAM to run
self.check_available_ram(self.ram)
self._nvram_watcher = FileWatcher(self._nvram_file(), self._nvram_changed)
# created a environment variable pointing to the iourc file.
env = os.environ.copy()
@@ -544,7 +560,7 @@ class IOUVM(BaseNode):
Before starting the VM, rename the nvram and vlan.dat files with the correct IOU application identifier.
"""
destination = os.path.join(self.working_dir, "nvram_{:05d}".format(self.application_id))
destination = self._nvram_file()
for file_path in glob.glob(os.path.join(glob.escape(self.working_dir), "nvram_*")):
shutil.move(file_path, destination)
destination = os.path.join(self.working_dir, "vlan.dat-{:05d}".format(self.application_id))
@@ -644,6 +660,10 @@ class IOUVM(BaseNode):
Stops the IOU process.
"""
if self._nvram_watcher:
self._nvram_watcher.close()
self._nvram_watcher = None
if self.is_running():
# stop console support
if self._ioucon_thread: