Skip to content

Instantly share code, notes, and snippets.

@qoelet
Created December 10, 2010 07:28
Show Gist options
  • Save qoelet/735907 to your computer and use it in GitHub Desktop.
Save qoelet/735907 to your computer and use it in GitHub Desktop.
import execnet, gevent
# Use boto to get images ip
from boto.ec2.connection import EC2Connection
conn = EC2Connection('secret', 'secret')
my_ami = conn.get_all_instances()
my_instances = my_ami[1].instances
servers = []
for instance in my_instances:
servers.append(instance.public_dns_name)
pypaths = {
'ec2_pypath':'/home/ubuntu/kenny/bin/python'
}
mine_script = """
# some process i run
channel.send(callback_stmt)
"""
gws = execnet.Group()
pool = Pool(10) # 1 per server
ec_inst_count = 1
for server in servers:
if server.startswith("ec2"):
gws.makegateway("ssh=" + "username" + "@"+server+"//id=" + "ec2_inst_" + str(ec_inst_count) + '//python=' + pypaths["ec2_pypath"])
ec_inst_count += 1
script = mine_script % param
for gw in gws:
gw_id = gw.id
channel = gws[gw_id].remote_exec(script)
channel.setcallback(cb) # assuming you have a callback function cb
# Run from commandline
if __name__ == '__main__':
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment