Skip to content

Commit

Permalink
Adding some initial examples
Browse files Browse the repository at this point in the history
  • Loading branch information
nkrsharma committed Nov 12, 2015
1 parent 39cf1ec commit 30cbfe3
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 19 deletions.
19 changes: 0 additions & 19 deletions example.py

This file was deleted.

26 changes: 26 additions & 0 deletions examples/example1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'''
A simple PyREM script to run iperf between two machines.
'''

import time
from pyrem.host import RemoteHost

# Declare two hosts.
HOST1 = RemoteHost('tradewars.cs.washington.edu')
HOST2 = RemoteHost('spyhunter.cs.washington.edu')

# Create tasks to be run on the hosts.
server = HOST1.run(['iperf -s'], quiet=True)
client = HOST2.run(['iperf -c tradewars.cs.washington.edu'])

# Start the server task.
server.start()

# Wait for servers to be ready.
time.sleep(1)

# Run the client task.
client.start(wait=True)

# Clean up.
server.stop()
15 changes: 15 additions & 0 deletions examples/example1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#/bin/bash
'''
A simple shell script to run iperf between two machines.
'''

HOST1='tradewars.cs.washington.edu'
HOST2='spyhunter.cs.washington.edu'

ssh $HOST1 "iperf -s &"

sleep 1

ssh $HOST2 "iperf -c $HOST1"

ssh $HOST1 "pkill -u $USER iperf"
30 changes: 30 additions & 0 deletions examples/example2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'''
A PyREM script to run iperf between multiple machines.
'''

import time
from pyrem.host import RemoteHost, LocalHost
from pyrem.task import Parallel, Sequential

# Declare the hosts.
SERVER_HOSTS = [RemoteHost(name + '.cs.washington.edu') for name in
['zork', 'spyhunter', 'tradewars']]
CLIENT_HOST = LocalHost()

# Create tasks to be run on the hosts.
servers = Parallel([host.run(['iperf -s'], quiet=True)
for host in SERVER_HOSTS])
client = Sequential([CLIENT_HOST.run(['iperf -c', host.hostname], shell=True)
for host in SERVER_HOSTS])

# Start all the servers in parallel.
servers.start()

# Wait for servers to be ready.
time.sleep(1)

# Run the client task.
client.start(wait=True)

# Clean up.
servers.stop()

0 comments on commit 30cbfe3

Please sign in to comment.