summaryrefslogtreecommitdiffstats
path: root/bin/cluster
diff options
context:
space:
mode:
authorKenny Woodson <kwoodson@redhat.com>2015-11-23 11:53:27 -0500
committerKenny Woodson <kwoodson@redhat.com>2016-01-04 09:58:39 -0500
commita21189c1f0611bff6935364c8c255a88060d882d (patch)
treea69d854a9a2ce78c6917583ff5877cf4199c8a1a /bin/cluster
parentf1951b2ca60536e81c9ff26a30b1cfbaf5ca12e9 (diff)
downloadopenshift-a21189c1f0611bff6935364c8c255a88060d882d.tar.gz
openshift-a21189c1f0611bff6935364c8c255a88060d882d.tar.bz2
openshift-a21189c1f0611bff6935364c8c255a88060d882d.tar.xz
openshift-a21189c1f0611bff6935364c8c255a88060d882d.zip
Removing environment and env tags.
Diffstat (limited to 'bin/cluster')
-rwxr-xr-xbin/cluster106
1 files changed, 61 insertions, 45 deletions
diff --git a/bin/cluster b/bin/cluster
index 9b02b4347..3081ebd4a 100755
--- a/bin/cluster
+++ b/bin/cluster
@@ -55,94 +55,108 @@ class Cluster(object):
Create an OpenShift cluster for given provider
:param args: command line arguments provided by user
"""
- env = {'cluster_id': args.cluster_id,
+ cluster = {'cluster_id': args.cluster_id,
'deployment_type': self.get_deployment_type(args)}
playbook = "playbooks/{0}/openshift-cluster/launch.yml".format(args.provider)
inventory = self.setup_provider(args.provider)
- env['num_masters'] = args.masters
- env['num_nodes'] = args.nodes
- env['num_infra'] = args.infra
- env['num_etcd'] = args.etcd
+ cluster['num_masters'] = args.masters
+ cluster['num_nodes'] = args.nodes
+ cluster['num_infra'] = args.infra
+ cluster['num_etcd'] = args.etcd
+ cluster['cluster_env'] = args.env
- self.action(args, inventory, env, playbook)
+ self.action(args, inventory, cluster, playbook)
def addNodes(self, args):
"""
Add nodes to an existing cluster for given provider
:param args: command line arguments provided by user
"""
- env = {'cluster_id': args.cluster_id,
- 'deployment_type': self.get_deployment_type(args)}
+ cluster = {'cluster_id': args.cluster_id,
+ 'deployment_type': self.get_deployment_type(args),
+ }
playbook = "playbooks/{0}/openshift-cluster/addNodes.yml".format(args.provider)
inventory = self.setup_provider(args.provider)
- env['num_nodes'] = args.nodes
- env['num_infra'] = args.infra
+ cluster['num_nodes'] = args.nodes
+ cluster['num_infra'] = args.infra
+ cluster['cluster_env'] = args.env
- self.action(args, inventory, env, playbook)
+ self.action(args, inventory, cluster, playbook)
def terminate(self, args):
"""
Destroy OpenShift cluster
:param args: command line arguments provided by user
"""
- env = {'cluster_id': args.cluster_id,
- 'deployment_type': self.get_deployment_type(args)}
+ cluster = {'cluster_id': args.cluster_id,
+ 'deployment_type': self.get_deployment_type(args),
+ 'cluster_env': args.env,
+ }
playbook = "playbooks/{0}/openshift-cluster/terminate.yml".format(args.provider)
inventory = self.setup_provider(args.provider)
- self.action(args, inventory, env, playbook)
+ self.action(args, inventory, cluster, playbook)
def list(self, args):
"""
List VMs in cluster
:param args: command line arguments provided by user
"""
- env = {'cluster_id': args.cluster_id,
- 'deployment_type': self.get_deployment_type(args)}
+ cluster = {'cluster_id': args.cluster_id,
+ 'deployment_type': self.get_deployment_type(args),
+ 'cluster_env': args.env,
+ }
playbook = "playbooks/{0}/openshift-cluster/list.yml".format(args.provider)
inventory = self.setup_provider(args.provider)
- self.action(args, inventory, env, playbook)
+ self.action(args, inventory, cluster, playbook)
def config(self, args):
"""
Configure or reconfigure OpenShift across clustered VMs
:param args: command line arguments provided by user
"""
- env = {'cluster_id': args.cluster_id,
- 'deployment_type': self.get_deployment_type(args)}
+ cluster = {'cluster_id': args.cluster_id,
+ 'deployment_type': self.get_deployment_type(args),
+ 'cluster_env': args.env,
+ }
playbook = "playbooks/{0}/openshift-cluster/config.yml".format(args.provider)
inventory = self.setup_provider(args.provider)
- self.action(args, inventory, env, playbook)
+ self.action(args, inventory, cluster, playbook)
def update(self, args):
"""
Update to latest OpenShift across clustered VMs
:param args: command line arguments provided by user
"""
- env = {'cluster_id': args.cluster_id,
- 'deployment_type': self.get_deployment_type(args)}
+ cluster = {'cluster_id': args.cluster_id,
+ 'deployment_type': self.get_deployment_type(args),
+ 'cluster_env': args.env,
+ }
+
playbook = "playbooks/{0}/openshift-cluster/update.yml".format(args.provider)
inventory = self.setup_provider(args.provider)
- self.action(args, inventory, env, playbook)
+ self.action(args, inventory, cluster, playbook)
def service(self, args):
"""
Make the same service call across all nodes in the cluster
:param args: command line arguments provided by user
"""
- env = {'cluster_id': args.cluster_id,
- 'deployment_type': self.get_deployment_type(args),
- 'new_cluster_state': args.state}
+ cluster = {'cluster_id': args.cluster_id,
+ 'deployment_type': self.get_deployment_type(args),
+ 'new_cluster_state': args.state,
+ 'cluster_env': args.env,
+ }
playbook = "playbooks/{0}/openshift-cluster/service.yml".format(args.provider)
inventory = self.setup_provider(args.provider)
- self.action(args, inventory, env, playbook)
+ self.action(args, inventory, cluster, playbook)
def setup_provider(self, provider):
"""
@@ -152,10 +166,9 @@ class Cluster(object):
"""
config = ConfigParser.ConfigParser()
if 'gce' == provider:
- gce_ini_default_path = os.path.join(
- 'inventory/gce/hosts/gce.ini')
+ gce_ini_default_path = os.path.join('inventory/gce/hosts/gce.ini')
gce_ini_path = os.environ.get('GCE_INI_PATH', gce_ini_default_path)
- if os.path.exists(gce_ini_path):
+ if os.path.exists(gce_ini_path):
config.readfp(open(gce_ini_path))
for key in config.options('gce'):
@@ -190,12 +203,12 @@ class Cluster(object):
return inventory
- def action(self, args, inventory, env, playbook):
+ def action(self, args, inventory, cluster, playbook):
"""
Build ansible-playbook command line and execute
:param args: command line arguments provided by user
:param inventory: derived provider library
- :param env: environment variables for kubernetes
+ :param cluster: cluster variables for kubernetes
:param playbook: ansible playbook to execute
"""
@@ -206,14 +219,14 @@ class Cluster(object):
if args.option:
for opt in args.option:
k, v = opt.split('=', 1)
- env['cli_' + k] = v
+ cluster['cli_' + k] = v
- ansible_env = '-e \'{0}\''.format(
- ' '.join(['%s=%s' % (key, value) for (key, value) in env.items()])
+ ansible_extra_vars = '-e \'{0}\''.format(
+ ' '.join(['%s=%s' % (key, value) for (key, value) in cluster.items()])
)
command = 'ansible-playbook {0} {1} {2} {3}'.format(
- verbose, inventory, ansible_env, playbook
+ verbose, inventory, ansible_extra_vars, playbook
)
if args.profile:
@@ -242,7 +255,7 @@ class ActionFailed(Exception):
if __name__ == '__main__':
"""
- User command to invoke ansible playbooks in a "known" environment
+ User command to invoke ansible playbooks in a "known" configuration
Reads ~/.openshift-ansible for default configuration items
[DEFAULT]
@@ -251,7 +264,7 @@ if __name__ == '__main__':
providers = gce,aws,libvirt,openstack
"""
- environment = ConfigParser.SafeConfigParser({
+ cluster_config = ConfigParser.SafeConfigParser({
'cluster_ids': 'marketing,sales',
'validate_cluster_ids': 'False',
'providers': 'gce,aws,libvirt,openstack',
@@ -259,23 +272,23 @@ if __name__ == '__main__':
path = os.path.expanduser("~/.openshift-ansible")
if os.path.isfile(path):
- environment.read(path)
+ cluster_config.read(path)
cluster = Cluster()
parser = argparse.ArgumentParser(
- description='Python wrapper to ensure proper environment for OpenShift ansible playbooks',
+ description='Python wrapper to ensure proper configuration 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.3')
meta_parser = argparse.ArgumentParser(add_help=False)
- providers = environment.get('DEFAULT', 'providers').split(',')
+ providers = cluster_config.get('DEFAULT', 'providers').split(',')
meta_parser.add_argument('provider', choices=providers, help='provider')
- 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(','),
+ if cluster_config.get('DEFAULT', 'validate_cluster_ids').lower() in ("yes", "true", "1"):
+ meta_parser.add_argument('cluster_id', choices=cluster_config.get('DEFAULT', 'cluster_ids').split(','),
help='prefix for cluster VM names')
else:
meta_parser.add_argument('cluster_id', help='prefix for cluster VM names')
@@ -289,6 +302,9 @@ if __name__ == '__main__':
meta_parser.add_argument('-o', '--option', action='append',
help='options')
+ meta_parser.add_argument('--env', default='dev', type=str,
+ help='environment for the cluster. Defaults to \'dev\'.')
+
meta_parser.add_argument('-p', '--profile', action='store_true',
help='Enable playbook profiling')
@@ -350,14 +366,14 @@ if __name__ == '__main__':
args = parser.parse_args()
if 'terminate' == args.action and not args.force:
- answer = raw_input("This will destroy the ENTIRE {0} environment. Are you sure? [y/N] ".format(args.cluster_id))
+ answer = raw_input("This will destroy the ENTIRE {0} cluster. Are you sure? [y/N] ".format(args.cluster_id))
if answer not in ['y', 'Y']:
sys.stderr.write('\nACTION [terminate] aborted by user!\n')
exit(1)
if 'update' == args.action and not args.force:
answer = raw_input(
- "This is destructive and could corrupt {0} environment. Continue? [y/N] ".format(args.cluster_id))
+ "This is destructive and could corrupt {0} cluster. Continue? [y/N] ".format(args.cluster_id))
if answer not in ['y', 'Y']:
sys.stderr.write('\nACTION [update] aborted by user!\n')
exit(1)