aboutsummaryrefslogtreecommitdiff
path: root/rumba/storyboard.py
diff options
context:
space:
mode:
Diffstat (limited to 'rumba/storyboard.py')
-rw-r--r--rumba/storyboard.py54
1 files changed, 46 insertions, 8 deletions
diff --git a/rumba/storyboard.py b/rumba/storyboard.py
index 9aff375..ba6883d 100644
--- a/rumba/storyboard.py
+++ b/rumba/storyboard.py
@@ -423,6 +423,39 @@ class StoryBoard(SBEntity):
del self.server_apps[server.id]
self._build_nodes_lists()
+ def schedule_action(self,
+ call,
+ args=None,
+ kwargs=None,
+ c_time=None,
+ trigger=None,
+ ev_id=None,):
+ """
+ Calls a function with the specified triggers and arguments.
+ :param call: the function to run
+ :type call: function (methods included)
+ :param c_time: the function will not be called before `c_time`
+ seconds have passed
+ :type c_time: :py:class:`float`
+ :param trigger: the function must not be called before the event
+ `trigger` has completed
+ :type trigger: :py:class:`.Event` or :py:class:`str`
+ :param ev_id: the ID to assign to the generated event
+ :type ev_id: :py:class:`str`
+ :param args: arguments to pass to the function
+ :param kwargs: keyword arguments to be passed
+ :return: the event representing the calling of the function
+ :rtype: :py:class:`.Event`
+ """
+ if args is None:
+ args = []
+ if kwargs is None:
+ kwargs = {}
+ action = functools.partial(call, *args, **kwargs)
+ event = Event(action, ev_id=ev_id, ev_time=c_time, trigger=trigger)
+ self.add_event(event)
+ return event
+
def schedule_command(self, t, node, command):
"""
Schedules the given command to be run at t seconds from the start.
@@ -846,14 +879,19 @@ class StoryBoard(SBEntity):
str(uuid.uuid4())[0:4] + ".pcap"
tcpd_client = Client(ap="tcpdump", options="-i %s -w %s" \
- % (ipcp.ifname, pcap_file))
- duration = end - start
- cb = functools.partial(node.fetch_file, pcap_file,
- self.experiment.log_dir, sudo=True)
- action = functools.partial(self.run_client, tcpd_client,
- duration=duration, node=node,
- callback = cb)
- self._script.add_event(Event(action, ev_time=start))
+ % (ipcp.ifname, pcap_file))\
+ .process(end-start, node, 'tcpdump_proc')
+
+ self.schedule_action(tcpd_client.run, c_time=start)
+ end_event = self.schedule_action(tcpd_client.stop, c_time=end)
+
+ self.schedule_action(
+ node.fetch_file,
+ args=[pcap_file, self.experiment.log_dir],
+ kwargs={'sudo': True},
+ trigger=end_event
+ )
+
class Event(object):