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
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