Notification to clients

This commit is contained in:
grossmj committed 2014-03-19 18:48:42 -06:00
1 parent 99cc7345b8
commit c4d9e8371f
5 files changed
+91 -23

No files matched your search

+23 -2
View File
@@ -115,8 +115,8 @@ class Dynamips(IModule):
self._working_dir = self._projects_dir
self._dynamips = ""
#self._callback = self.add_periodic_callback(self.test, 1000)
#self._callback.start()
self._callback = self.add_periodic_callback(self._check_hypervisors, 5000)
self._callback.start()
def stop(self):
"""
@@ -127,6 +127,27 @@ class Dynamips(IModule):
self._hypervisor_manager.stop_all_hypervisors()
IModule.stop(self) # this will stop the I/O loop
def _check_hypervisors(self):
"""
Periodic callback to check if Dynamips hypervisors are running.
Sends a notification to the client if not.
"""
if self._hypervisor_manager:
for hypervisor in self._hypervisor_manager.hypervisors:
if hypervisor.started and not hypervisor.is_running():
notification = {"module": self.name}
stdout = hypervisor.read_stdout()
device_names = []
for device in hypervisor.devices:
device_names.append(device.name)
notification["message"] = "Dynamips has stopped running"
notification["details"] = stdout
notification["devices"] = device_names
self.send_notification("{}.dynamips_stopped".format(self.name), notification)
hypervisor.stop()
@IModule.route("dynamips.reset")
def reset(self, request):
"""
+14
View File
@@ -54,6 +54,7 @@ class Hypervisor(DynamipsHypervisor):
self._command = []
self._process = None
self._stdout_file = ""
self._started = False
# settings used the load-balance hypervisors
# (for the hypervisor manager)
@@ -70,6 +71,16 @@ class Hypervisor(DynamipsHypervisor):
return(self._id)
@property
def started(self):
"""
Returns either this hypervisor has been started or not.
:returns: boolean
"""
return self._started
@property
def path(self):
"""
@@ -199,6 +210,7 @@ class Hypervisor(DynamipsHypervisor):
stderr=subprocess.STDOUT,
cwd=self._working_dir)
log.info("Dynamips started PID={}".format(self._process.pid))
self._started = True
except EnvironmentError as e:
log.error("could not start Dynamips: {}".format(e))
raise DynamipsError("could not start Dynamips: {}".format(e))
@@ -222,6 +234,8 @@ class Hypervisor(DynamipsHypervisor):
if self._process.poll() == None:
log.warn("Dynamips process {} is still running".format(self._process.pid))
self._started = False
def read_stdout(self):
"""
Reads the standard output of the Dynamips process.