Beispiel #1
0
def deploy_server(useraccesskeyid, usersecretkey, usertoken, producttoken,
                  bucketname, oldsecrets, amiimageid, instancesize,
                  customer_name, customer_email, customer_keyinfo, stdout, stderr,
                  secretsfile, config, serverinfopath=None, ec2secretpath=None, clock=None):
    serverinfopath = serverinfopath or '../serverinfo.csv'
    ec2secretpath = ec2secretpath or '../secret_config/ec2secret'
    myclock = clock or reactor

    ec2accesskeyid = str(config.other['ec2_access_key_id'])
    ec2secretkey = FilePath(ec2secretpath).getContent().strip()

    instancename = customer_email  # need not be unique

    admin_keypair_name = str(config.other['admin_keypair_name'])
    admin_privkey_path = str(config.other['admin_privkey_path'])
    monitor_pubkey = FilePath(str(config.other['monitor_pubkey_path'])).getContent().strip()
    monitor_privkey_path = str(config.other['monitor_privkey_path'])
    sinkname_suffix = str(config.other['sinkname_suffix'])

    # XXX Here's where we decide whether the new signup goes to a new EC2.
    d = deploy_EC2_instance(ec2accesskeyid, ec2secretkey, EC2_ENDPOINT, amiimageid,
                            instancesize, bucketname, admin_keypair_name, instancename,
                            stdout, stderr)

    def _deployed(instance):
        print >>stdout, "Waiting %d seconds for the server to be ready..." % (ADDRESS_DELAY_TIME,)
        d2 = task.deferLater(myclock, ADDRESS_DELAY_TIME, wait_for_EC2_addresses,
                             ec2accesskeyid, ec2secretkey, EC2_ENDPOINT, stdout, stderr,
                             instance.instance_id)

        def _got_addresses(addresses):
            assert len(addresses) == 1, addresses
            (publichost, privatehost) = addresses[0]
            print >>stdout, "The server's public address is %r." % (publichost,)

            d3 = verify_and_store_serverssh_pubkey(ec2accesskeyid, ec2secretkey, EC2_ENDPOINT,
                                                   publichost, VERIFY_POLL_TIME, VERIFY_TOTAL_WAIT,
                                                   stdout, stderr, instance.instance_id)

            def _got_sshfp(ignored):
                retries = LISTEN_RETRIES
                while True:
                    try:
                        install_server(publichost, admin_privkey_path, monitor_pubkey,
                                       monitor_privkey_path, stdout, stderr)
                        break
                    except NotListeningError:
                        retries -= 1
                        if retries <= 0:
                            print >>stdout, "Timed out waiting for EC2 instance to listen for ssh connections."
                            raise TimeoutError()
                        print >>stdout, "Waiting another %d seconds..." % (LISTEN_POLL_TIME)
                        time.sleep(LISTEN_POLL_TIME)
                        continue

                furl = bounce_server(publichost, admin_privkey_path, privatehost, useraccesskeyid,
                                     usersecretkey, usertoken, producttoken, bucketname, oldsecrets,
                                     stdout, stderr, secretsfile)

                # XXX We'll have to ammend this:
                initialize_statmover_source(publichost, monitor_privkey_path, admin_privkey_path,
                                            sinkname_suffix, [instance.instance_id, 'SSEC2s'])
                # XXX We probably need to rethink this:
                append_record(FilePath(serverinfopath), instance.launch_time, instance.instance_id,
                              publichost)

                print >>stderr, "Signup done."
                d4 = defer.succeed(None)
                if not oldsecrets:
                    d4.addCallback(lambda ign: send_signup_confirmation(publichost, customer_name,
                                                                        customer_email, furl,
                                                                        customer_keyinfo,
                                                                        stdout, stderr) )
                return d4
            d3.addCallback(_got_sshfp)
            return d3
        d2.addCallback(_got_addresses)
        return d2
    d.addCallback(_deployed)
    return d
from lae_automation.initialize import deploy_EC2_instance


if len(sys.argv) < 8:
    print "Usage: python deploy.py EC2_ACCESS_KEY_ID EC2_SECRET_KEY AMI_IMAGE_ID INSTANCE_SIZE BUCKET_NAME KEYPAIR_NAME INSTANCE_NAME"
    print "Happy deploying!"
    sys.exit(1)

ec2accesskeyid = sys.argv[1]
ec2secretkey = sys.argv[2]
amiimageid = sys.argv[3]
instancesize = sys.argv[4]
bucketname = sys.argv[5]
keypairname = sys.argv[6]
instancename = sys.argv[7]

EC2_ENDPOINT = 'https://ec2.us-east-1.amazonaws.com/'
#EC2_ENDPOINT = 'https://ec2.amazonaws.com/'

def cb(x):
    print str(x)
    if isinstance(x, Failure) and hasattr(x.value, 'response'):
        print x.value.response

d = deploy_EC2_instance(ec2accesskeyid, ec2secretkey, EC2_ENDPOINT, amiimageid, instancesize, bucketname, keypairname, instancename,
                        sys.stdout, sys.stderr)
d.addBoth(cb)
d.addCallbacks(lambda ign: os._exit(0), lambda ign: os._exit(1))
reactor.run()
Beispiel #3
0
if len(sys.argv) < 8:
    print "Usage: python deploy.py EC2_ACCESS_KEY_ID EC2_SECRET_KEY AMI_IMAGE_ID INSTANCE_SIZE BUCKET_NAME KEYPAIR_NAME INSTANCE_NAME"
    print "Happy deploying!"
    sys.exit(1)

ec2accesskeyid = sys.argv[1]
ec2secretkey = sys.argv[2]
amiimageid = sys.argv[3]
instancesize = sys.argv[4]
bucketname = sys.argv[5]
keypairname = sys.argv[6]
instancename = sys.argv[7]

EC2_ENDPOINT = 'https://ec2.us-east-1.amazonaws.com/'
#EC2_ENDPOINT = 'https://ec2.amazonaws.com/'


def cb(x):
    print str(x)
    if isinstance(x, Failure) and hasattr(x.value, 'response'):
        print x.value.response


d = deploy_EC2_instance(ec2accesskeyid, ec2secretkey, EC2_ENDPOINT, amiimageid,
                        instancesize, bucketname, keypairname, instancename,
                        sys.stdout, sys.stderr)
d.addBoth(cb)
d.addCallbacks(lambda ign: os._exit(0), lambda ign: os._exit(1))
reactor.run()
Beispiel #4
0
def deploy_server(useraccesskeyid, usersecretkey, usertoken, producttoken,
                  bucketname, oldsecrets, amiimageid, instancesize,
                  customer_name, customer_email, customer_keyinfo, stdout, stderr,
                  secretsfile, config, serverinfopath=None, ec2secretpath=None, clock=None):
    serverinfopath = serverinfopath or '../serverinfo.csv'
    ec2secretpath = ec2secretpath or '../secret_config/ec2secret'
    myclock = clock or reactor

    ec2accesskeyid = str(config.other['ec2_access_key_id'])
    ec2secretkey = FilePath(ec2secretpath).getContent().strip()

    instancename = customer_email  # need not be unique

    admin_keypair_name = str(config.other['admin_keypair_name'])
    admin_privkey_path = str(config.other['admin_privkey_path'])
    monitor_pubkey = FilePath(str(config.other['monitor_pubkey_path'])).getContent().strip()
    monitor_privkey_path = str(config.other['monitor_privkey_path'])
    #sinkname_suffix = str(config.other['sinkname_suffix'])

    # XXX Here's where we decide whether the new signup goes to a new EC2.
    d = deploy_EC2_instance(ec2accesskeyid, ec2secretkey, EC2_ENDPOINT, amiimageid,
                            instancesize, bucketname, admin_keypair_name, instancename,
                            stdout, stderr)

    def _deployed(instance):
        print >>stdout, "Waiting %d seconds for the server to be ready..." % (ADDRESS_DELAY_TIME,)
        d2 = task.deferLater(myclock, ADDRESS_DELAY_TIME, wait_for_EC2_addresses,
                             ec2accesskeyid, ec2secretkey, EC2_ENDPOINT, stdout, stderr, POLL_TIME,
                             ADDRESS_WAIT_TIME, instance.instance_id)

        def _got_addresses(addresses):
            assert len(addresses) == 1, addresses
            (publichost, privatehost) = addresses[0]
            print >>stdout, "The server's public address is %r." % (publichost,)

            d3 = verify_and_store_serverssh_pubkey(ec2accesskeyid, ec2secretkey, EC2_ENDPOINT,
                                                   publichost, VERIFY_POLL_TIME, VERIFY_TOTAL_WAIT,
                                                   stdout, stderr, instance.instance_id)

            def _got_sshfp(ignored):
                retries = LISTEN_RETRIES
                while True:
                    try:
                        install_server(publichost, admin_privkey_path, monitor_pubkey,
                                       monitor_privkey_path, stdout, stderr)
                        break
                    except NotListeningError:
                        retries -= 1
                        if retries <= 0:
                            print >>stdout, "Timed out waiting for EC2 instance to listen for ssh connections."
                            raise TimeoutError()
                        print >>stdout, "Waiting another %d seconds..." % (LISTEN_POLL_TIME)
                        time.sleep(LISTEN_POLL_TIME)
                        continue

                furl = bounce_server(publichost, admin_privkey_path, privatehost, useraccesskeyid,
                                     usersecretkey, usertoken, producttoken, bucketname, oldsecrets,
                                     stdout, stderr, secretsfile)

                # Disabled for now.
                #initialize_statmover_source(publichost, monitor_privkey_path, admin_privkey_path,
                #                            sinkname_suffix, [instance.instance_id, 'SSEC2s'])

                # XXX We probably need to rethink this:
                append_record(FilePath(serverinfopath), instance.launch_time, instance.instance_id,
                              publichost)

                print >>stderr, "Signup done."
                d4 = defer.succeed(None)
                if not oldsecrets:
                    d4.addCallback(lambda ign: send_signup_confirmation(publichost, customer_name,
                                                                        customer_email, furl,
                                                                        customer_keyinfo,
                                                                        stdout, stderr) )
                return d4
            d3.addCallback(_got_sshfp)
            return d3
        d2.addCallback(_got_addresses)
        return d2
    d.addCallback(_deployed)
    return d