Skip to main content

NEPI demo script, Simple - Alina Quereilhac & Damien Saucez
slides-interim-2013-icnrg-4-9-1

Meeting Slides Information-Centric Networking (icnrg) RG
Date and time 2013-11-03 07:00
Title NEPI demo script, Simple - Alina Quereilhac & Damien Saucez
State Archived
Other versions plain text
Last updated 2013-11-04

slides-interim-2013-icnrg-4-9-1
from nepi.execution.resource import ResourceState, ResourceAction
from nepi.execution.ec import ExperimentController

# == Experiement controller ===================================================
ec = ExperimentController(exp_id = "simple")

# == Specify node =============================================================
# it is a linux node
node = ec.register_resource("LinuxNode")
ec.set(node, "hostname", "planetlab2.s3.kth.se")
ec.set(node, "username", "inria_nepi")
# NEPI produces directories to store experiment files, specify to clean them
# once finished
ec.set(node, "cleanExperiment", True)
ec.set(node, "cleanProcesses", True)

# == deploy the experiement ===================================================
ec.deploy() # not needed to be done now, just for the example

# == we want to execute a linux command =======================================
app = ec.register_resource("LinuxApplication")
ec.set(app, "command", "echo \"Hello world!\"")

# == this application must run on the node we just specified ==================
ec.register_connection(app, node)

# == deploy the application ===================================================
ec.deploy([app])

# == wait the application to be finished to retrieve experiement's traces =====
ec.wait_finished(app)
ec.trace(app, "stdout")
ec.trace(app, "stderr")

# =============================================================================
# == A more complex example with execution flow ===============================
# =============================================================================

# == Two applications =========================================================
# a ping
app_ping = ec.register_resource("LinuxApplication")
ec.set(app_ping, "command", "ping -c 20 www.ietf.org > /tmp/ietf.dat")
ec.register_connection(app_ping, node)

# and a summary of the ping
app_summary = ec.register_resource("LinuxApplication")
ec.set(app_summary, "command", "tail -3 /tmp/ietf.dat || echo 'FAILED'")
ec.register_connection(app_summary, node)

# == Flow execution, the summary is computed after ping completed =============
# the summary can be taken only after the ping!
ec.register_condition(app_summary, ResourceAction.START, app_ping, ResourceState.FINISHED)

# == deploy the experiment ====================================================
ec.deploy([app_ping, app_summary])

# == retrieve status ==========================================================
ec.state(app_ping, hr = True)
ec.state(app_summary, hr = True)

# wait the end of the experiment
ec.wait_finished(app_summary)

# what is the status of each app now?
ec.state(app_ping, hr = True)
ec.state(app_summary, hr = True)

# == retrieve experiement's trace =============================================
sum = ec.trace(app_summary, "stdout")
print sum