Beispiel #1
0
def init(opts, conf):
    ec2 = aws.get_ec2_conn(conf)

    #    create ssh key pair
    if not opts.no_ssh_keys:
        try:
            ssh_key_name = conf.get("SSH_KEY_NAME", "brenda")
            if not opts.aws_ssh_pull and aws.local_ssh_keys_exist(opts, conf):
                #    push local ssh public key to AWS
                pubkey_fn = aws.get_ssh_pubkey_fn(opts, conf)
                print "Pushing ssh public key %r to AWS under %r key pair." % (
                    pubkey_fn, ssh_key_name)
                with open(pubkey_fn) as f:
                    pubkey = f.read()
                    res = ec2.import_key_pair(ssh_key_name, pubkey)
                    print res
            else:
                #    get new ssh public key pair from AWS
                brenda_ssh_ident_fn = aws.get_brenda_ssh_identity_fn(
                    opts, conf, mkdir=True)
                print "Fetching ssh private key from AWS into %r under %r key pair." % (
                    brenda_ssh_ident_fn, ssh_key_name)
                keypair = ec2.create_key_pair(key_name=ssh_key_name)
                with open(brenda_ssh_ident_fn, 'w') as f:
                    pass
                os.chmod(brenda_ssh_ident_fn, 0600)
                with open(brenda_ssh_ident_fn, 'w') as f:
                    f.write(keypair.material)
        except Exception, e:
            print "Error creating ssh key pair", e
Beispiel #2
0
def init(opts, conf):
    ec2 = aws.get_ec2_conn(conf)

    # create ssh key pair
    if not opts.no_ssh_keys:
        try:
            ssh_key_name = conf.get("SSH_KEY_NAME", "brenda")
            if not opts.aws_ssh_pull and aws.local_ssh_keys_exist(opts, conf):
                # push local ssh public key to AWS
                pubkey_fn = aws.get_ssh_pubkey_fn(opts, conf)
                print "Pushing ssh public key %r to AWS under %r key pair." % (pubkey_fn, ssh_key_name)
                with open(pubkey_fn) as f:
                    pubkey = f.read()
                    res = ec2.import_key_pair(ssh_key_name, pubkey)
                    print res
            else:
                # get new ssh public key pair from AWS
                brenda_ssh_ident_fn = aws.get_brenda_ssh_identity_fn(opts, conf, mkdir=True)
                print "Fetching ssh private key from AWS into %r under %r key pair." % (brenda_ssh_ident_fn, ssh_key_name)
                keypair = ec2.create_key_pair(key_name=ssh_key_name)
                with open(brenda_ssh_ident_fn, 'w') as f:
                    pass
                os.chmod(brenda_ssh_ident_fn, 0600)
                with open(brenda_ssh_ident_fn, 'w') as f:
                    f.write(keypair.material)
        except Exception, e:
            print "Error creating ssh key pair", e
Beispiel #3
0
def reset_keys(opts, conf):
    ec2 = aws.get_ec2_conn(conf)

    # remove ssh keys
    if not opts.no_ssh_keys:
        try:
            ssh_key_name = conf.get("SSH_KEY_NAME", "brenda")
            print "Removing AWS ssh key pair %r." % (ssh_key_name,)
            ec2.delete_key_pair(key_name=ssh_key_name)
            brenda_ssh_ident_fn = aws.get_brenda_ssh_identity_fn(opts, conf)
            if os.path.exists(brenda_ssh_ident_fn):
                print "Removing AWS local ssh identity %r." % (brenda_ssh_ident_fn,)
                os.remove(brenda_ssh_ident_fn)
        except Exception, e:
            print "Error removing ssh key pair", e
Beispiel #4
0
def reset_keys(opts, conf):
    ec2 = aws.get_ec2_conn(conf)

    # remove ssh keys
    if not opts.no_ssh_keys:
        try:
            ssh_key_name = conf.get("SSH_KEY_NAME", "brenda")
            print "Removing AWS ssh key pair %r." % (ssh_key_name,)
            ec2.delete_key_pair(key_name=ssh_key_name)
            brenda_ssh_ident_fn = aws.get_brenda_ssh_identity_fn(opts, conf)
            if os.path.exists(brenda_ssh_ident_fn):
                print "Removing AWS local ssh identity %r." % (brenda_ssh_ident_fn,)
                os.remove(brenda_ssh_ident_fn)
        except Exception, e:
            print "Error removing ssh key pair", e