Beispiel #1
0
def rm_ec2():
    """
    Terminates all spot instances, clear hosts file
    """
    for s in SpotInstance.get_spot_instances(REGION,EC2_Tag):
        print "terminating", s.status()
        if s.instance_object and s.instance_object.state_code != 48:
            s.terminate()
        print "terminated"
    with file("temp/hosts","w") as f:
        f.write("")
Beispiel #2
0
def ls_ec2():
    """
    Lists current EC2 instances with current Job tag, and stores their public_dns_name to hosts.
    """
    with open('temp/hosts','w') as fh:
        for i,instance in enumerate(SpotInstance.get_spot_instances(REGION,EC2_Tag)):
            print instance.status()
            if instance.public_dns_name:
                fh.write(instance.public_dns_name+'\n')
                print instance.public_dns_name
                with open("temp/connect_"+str(i)+'.sh','w') as fssh:
                    fssh.write("#!/usr/bin/env sh\nssh -i "+env.key_filename+" "+env.user+'@'+instance.public_dns_name)
    with lcd('temp'):
        local('chmod a+x *.sh')
    print "Information about current spot instance has been added to temp/hosts"
Beispiel #3
0
def get_ec2():
    """
    Requests a spot EC2 instance
    """
    spot = SpotInstance(REGION,EC2_Tag)
    spot.request_instance(price,instance_type,image_id,key_name,USER_DATA,IAM_PROFILE,SPOT_REQUEST_VALID)