Created
April 2, 2013 18:55
-
-
Save jtriley/5295096 to your computer and use it in GitHub Desktop.
Plugin for StarCluster that configures a boto credentials file for the cluster user
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from starcluster import clustersetup | |
from starcluster.logger import log | |
BOTO_CFG_TEMPLATE = """\ | |
[Credentials] | |
aws_access_key_id = %(aws_access_key_id)s | |
aws_secret_access_key = %(aws_secret_access_key)s | |
[Boto] | |
https_validate_certificates=True | |
""" | |
class BotoPlugin(clustersetup.ClusterSetup): | |
""" | |
Plugin that configures a ~/.boto file for CLUSTER_USER | |
""" | |
def __init__(self, boto_cfg=None): | |
self.boto_cfg = os.path.expanduser(boto_cfg or '') or None | |
def run(self, nodes, master, user, shell, volumes): | |
mssh = master.ssh | |
mssh.switch_user(user) | |
botocfg = '/home/%s/.boto' % user | |
if not mssh.path_exists(botocfg): | |
log.info("Installing AWS credentials for user: %s" % user) | |
if self.boto_cfg: | |
log.info("Copying %s to %s" % (self.boto_cfg, botocfg)) | |
mssh.put(self.boto_cfg, botocfg) | |
else: | |
log.info("Installing current credentials to: %s" % botocfg) | |
f = mssh.remote_file(botocfg, 'w') | |
f.write(BOTO_CFG_TEMPLATE % master.ec2.__dict__) | |
f.close() | |
mssh.chmod(0400, botocfg) | |
else: | |
log.warn("AWS credentials already present - skipping install") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use the following plugin config to build and install a ~/.boto file using the credentials defined in the StarCluster config (ie from the [aws] section):
If you'd rather maintain your own boto file instead simply set
boto_cfg
to the path of your.boto
file: