summaryrefslogtreecommitdiffstats
path: root/bin/cluster
diff options
context:
space:
mode:
Diffstat (limited to 'bin/cluster')
-rwxr-xr-xbin/cluster38
1 files changed, 33 insertions, 5 deletions
diff --git a/bin/cluster b/bin/cluster
index 2ea389523..746c0349a 100755
--- a/bin/cluster
+++ b/bin/cluster
@@ -3,8 +3,9 @@
import argparse
import ConfigParser
-import sys
import os
+import sys
+import traceback
class Cluster(object):
@@ -50,6 +51,7 @@ class Cluster(object):
env['num_masters'] = args.masters
env['num_nodes'] = args.nodes
+ env['num_etcd'] = args.etcd
return self.action(args, inventory, env, playbook)
@@ -141,6 +143,17 @@ class Cluster(object):
os.environ[key] = config.get('ec2', key)
inventory = '-i inventory/aws/hosts'
+
+ key_vars = ['AWS_ACCESS_KEY_ID', 'AWS_SECRET_ACCESS_KEY']
+ key_missing = [key for key in key_vars if key not in os.environ]
+
+ boto_conf_files = ['~/.aws/credentials', '~/.boto']
+ conf_exists = lambda conf: os.path.isfile(os.path.expanduser(conf))
+ boto_configs = [ conf for conf in boto_conf_files if conf_exists(conf)]
+
+ if len(key_missing) > 0 and len(boto_configs) == 0:
+ raise ValueError("PROVIDER aws requires {} environment variable(s). See README_AWS.md".format(missing))
+
elif 'libvirt' == provider:
inventory = '-i inventory/libvirt/hosts'
elif 'openstack' == provider:
@@ -168,7 +181,7 @@ class Cluster(object):
if args.option:
for opt in args.option:
k, v = opt.split('=', 1)
- env['opt_'+k] = v
+ env['cli_' + k] = v
ansible_env = '-e \'{}\''.format(
' '.join(['%s=%s' % (key, value) for (key, value) in env.items()])
@@ -178,6 +191,9 @@ class Cluster(object):
verbose, inventory, ansible_env, playbook
)
+ if args.profile:
+ command = 'ANSIBLE_CALLBACK_PLUGINS=ansible-profile/callback_plugins ' + command
+
if args.verbose > 1:
command = 'time {}'.format(command)
@@ -234,6 +250,9 @@ if __name__ == '__main__':
meta_parser.add_argument('-o', '--option', action='append',
help='options')
+ meta_parser.add_argument('-p', '--profile', action='store_true',
+ help='Enable playbook profiling')
+
action_parser = parser.add_subparsers(dest='action', title='actions',
description='Choose from valid actions')
@@ -243,6 +262,8 @@ if __name__ == '__main__':
help='number of masters to create in cluster')
create_parser.add_argument('-n', '--nodes', default=2, type=int,
help='number of nodes to create in cluster')
+ create_parser.add_argument('-e', '--etcd', default=0, type=int,
+ help='number of external etcd hosts to create in cluster')
create_parser.set_defaults(func=cluster.create)
config_parser = action_parser.add_parser('config',
@@ -290,7 +311,14 @@ if __name__ == '__main__':
sys.stderr.write('\nACTION [update] aborted by user!\n')
exit(1)
- status = args.func(args)
- if status != 0:
- sys.stderr.write("ACTION [{}] failed with exit status {}\n".format(args.action, status))
+ status = 1
+ try:
+ status = args.func(args)
+ if status != 0:
+ sys.stderr.write("ACTION [{}] failed with exit status {}\n".format(args.action, status))
+ except Exception, e:
+ if args.verbose:
+ traceback.print_exc(file=sys.stderr)
+ else:
+ sys.stderr.write("{}\n".format(e))
exit(status)