Quick exampleΒΆ

This example shows how to run SSH commands in serial and in parallel.

#!/usr/bin/env python3
from expyrimenter import SSH, Executor

# Suppose we have a cluster with hostnames vm0, vm1 and vm2
cluster = ['vm%d' % i for i in range(0, 3)]

# Let's run the command below in all VMs:
cmd = 'echo "$(date +%S) Hello by $(hostname)"'

# Blocking version, serial execution
print('Serial execution\n================')
for vm in cluster:
    output = SSH(vm, cmd, stdout=True).run()

# Create a pool for parallel execution
pool = Executor()

# Non-blocking version, parallel execution
print('\nParallel execution\n==================')
for vm in cluster:
    ssh = SSH(vm, cmd, stdout=True, stderr=False)

# Block until all parallel calls are done
# and then print the results
for result in pool.results:

Output (with all clocks synchronized):

Serial execution
58 Hello by vm0
00 Hello by vm1
01 Hello by vm2

Parallel execution
02 Hello by vm2
02 Hello by vm0
02 Hello by vm1