summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
Diffstat (limited to 'bin')
-rwxr-xr-xbin/cluster67
-rw-r--r--bin/openshift-ansible-bin.spec9
2 files changed, 69 insertions, 7 deletions
diff --git a/bin/cluster b/bin/cluster
index 79f1f988f..2ea389523 100755
--- a/bin/cluster
+++ b/bin/cluster
@@ -9,8 +9,9 @@ import os
class Cluster(object):
"""
- Control and Configuration Interface for OpenShift Clusters
+ Provide Command, Control and Configuration (c3) Interface for OpenShift Clusters
"""
+
def __init__(self):
# setup ansible ssh environment
if 'ANSIBLE_SSH_ARGS' not in os.environ:
@@ -104,6 +105,21 @@ class Cluster(object):
return self.action(args, inventory, env, playbook)
+ def service(self, args):
+ """
+ Make the same service call across all nodes in the cluster
+ :param args: command line arguments provided by user
+ :return: exit status from run command
+ """
+ env = {'cluster_id': args.cluster_id,
+ 'deployment_type': self.get_deployment_type(args),
+ 'new_cluster_state': args.state}
+
+ playbook = "playbooks/{}/openshift-cluster/service.yml".format(args.provider)
+ inventory = self.setup_provider(args.provider)
+
+ return self.action(args, inventory, env, playbook)
+
def setup_provider(self, provider):
"""
Setup ansible playbook environment
@@ -127,6 +143,8 @@ class Cluster(object):
inventory = '-i inventory/aws/hosts'
elif 'libvirt' == provider:
inventory = '-i inventory/libvirt/hosts'
+ elif 'openstack' == provider:
+ inventory = '-i inventory/openstack/hosts'
else:
# this code should never be reached
raise ValueError("invalid PROVIDER {}".format(provider))
@@ -147,6 +165,11 @@ class Cluster(object):
if args.verbose > 0:
verbose = '-{}'.format('v' * args.verbose)
+ if args.option:
+ for opt in args.option:
+ k, v = opt.split('=', 1)
+ env['opt_'+k] = v
+
ansible_env = '-e \'{}\''.format(
' '.join(['%s=%s' % (key, value) for (key, value) in env.items()])
)
@@ -167,25 +190,49 @@ class Cluster(object):
if __name__ == '__main__':
"""
- Implemented to support writing unit tests
+ User command to invoke ansible playbooks in a "known" environment
+
+ Reads ~/.openshift-ansible for default configuration items
+ [DEFAULT]
+ validate_cluster_ids = False
+ cluster_ids = marketing,sales
+ providers = gce,aws,libvirt,openstack
"""
+ environment = ConfigParser.SafeConfigParser({
+ 'cluster_ids': 'marketing,sales',
+ 'validate_cluster_ids': 'False',
+ 'providers': 'gce,aws,libvirt,openstack',
+ })
+
+ path = os.path.expanduser("~/.openshift-ansible")
+ if os.path.isfile(path):
+ environment.read(path)
+
cluster = Cluster()
- providers = ['gce', 'aws', 'libvirt']
parser = argparse.ArgumentParser(
description='Python wrapper to ensure proper environment for OpenShift ansible playbooks',
)
parser.add_argument('-v', '--verbose', action='count',
help='Multiple -v options increase the verbosity')
- parser.add_argument('--version', action='version', version='%(prog)s 0.2')
+ parser.add_argument('--version', action='version', version='%(prog)s 0.3')
meta_parser = argparse.ArgumentParser(add_help=False)
+ providers = environment.get('DEFAULT', 'providers').split(',')
meta_parser.add_argument('provider', choices=providers, help='provider')
- meta_parser.add_argument('cluster_id', help='prefix for cluster VM names')
+
+ if environment.get('DEFAULT', 'validate_cluster_ids').lower() in ("yes", "true", "1"):
+ meta_parser.add_argument('cluster_id', choices=environment.get('DEFAULT', 'cluster_ids').split(','),
+ help='prefix for cluster VM names')
+ else:
+ meta_parser.add_argument('cluster_id', help='prefix for cluster VM names')
+
meta_parser.add_argument('-t', '--deployment-type',
choices=['origin', 'online', 'enterprise'],
help='Deployment type. (default: origin)')
+ meta_parser.add_argument('-o', '--option', action='append',
+ help='options')
action_parser = parser.add_subparsers(dest='action', title='actions',
description='Choose from valid actions')
@@ -221,6 +268,13 @@ if __name__ == '__main__':
parents=[meta_parser])
list_parser.set_defaults(func=cluster.list)
+ service_parser = action_parser.add_parser('service', help='service for openshift across cluster',
+ parents=[meta_parser])
+ # choices are the only ones valid for the ansible service module: http://docs.ansible.com/service_module.html
+ service_parser.add_argument('state', choices=['started', 'stopped', 'restarted', 'reloaded'],
+ help='make service call across cluster')
+ service_parser.set_defaults(func=cluster.service)
+
args = parser.parse_args()
if 'terminate' == args.action and not args.force:
@@ -230,7 +284,8 @@ if __name__ == '__main__':
exit(1)
if 'update' == args.action and not args.force:
- answer = raw_input("This is destructive and could corrupt {} environment. Continue? [y/N] ".format(args.cluster_id))
+ answer = raw_input(
+ "This is destructive and could corrupt {} environment. Continue? [y/N] ".format(args.cluster_id))
if answer not in ['y', 'Y']:
sys.stderr.write('\nACTION [update] aborted by user!\n')
exit(1)
diff --git a/bin/openshift-ansible-bin.spec b/bin/openshift-ansible-bin.spec
index 884d4eb0a..fd2386c9a 100644
--- a/bin/openshift-ansible-bin.spec
+++ b/bin/openshift-ansible-bin.spec
@@ -1,6 +1,6 @@
Summary: OpenShift Ansible Scripts for working with metadata hosts
Name: openshift-ansible-bin
-Version: 0.0.17
+Version: 0.0.18
Release: 1%{?dist}
License: ASL 2.0
URL: https://github.com/openshift/openshift-ansible
@@ -42,6 +42,13 @@ cp -p openshift_ansible.conf.example %{buildroot}/etc/openshift_ansible/openshif
%config(noreplace) /etc/openshift_ansible/
%changelog
+* Tue Jun 09 2015 Kenny Woodson <kwoodson@redhat.com> 0.0.18-1
+- Implement OpenStack provider (lhuard@amadeus.com)
+- * Update defaults and examples to track core concepts guide
+ (jhonce@redhat.com)
+- Issue 119 - Add support for ~/.openshift-ansible (jhonce@redhat.com)
+- Infrastructure - Add service action to bin/cluster (jhonce@redhat.com)
+
* Fri May 15 2015 Thomas Wiest <twiest@redhat.com> 0.0.17-1
- fixed the openshift-ansible-bin build (twiest@redhat.com)