Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def create(ctx, name, domain, template):
"""Create a new cluster.
:param name: New cluster name
"""
click.echo('Creating "%s"...' % name)
try:
clusters.create_cluster(cluster=name,
domain=domain,
template=template)
except ex.CreationError as e:
print_with_color(e.message, 'red')
else:
click.echo('Cluster "{}" created (domain name = "{}").'.format(
name,
domain if domain else '%s.local' % name))
set_context(ctx, name)
def listclusters(full):
"""List clusters managed by Jumbo."""
try:
limit = 40
if full:
limit = 1000
cluster_table = PrettyTable(['Name', 'Domain Name', 'VMs',
'Services'])
cluster_table.align['Name'] = 'l'
cluster_table.align['Domain Name'] = 'l'
cluster_table.align['Services'] = 'l'
for cluster in clusters.list_clusters():
cluster_table.add_row([cluster['cluster'],
cluster['domain'],
len(cluster['nodes']),
'\n'.join(cluster['services'])])
except ex.LoadError as e:
print_with_color(e.message, 'red')
if e.type == 'NoConfFile':
click.echo('Use "repair" to regenerate "jumbo_config".')
else:
cluster_table.sortby = 'Name'
click.echo(cluster_table)
def load_config(cluster):
"""Load a cluster in the session.
:param cluster: Cluster name
:type cluster: str
:return: True on success
"""
global svars
if not checks.check_cluster(cluster):
raise ex.LoadError('cluster', cluster, 'NotExist')
if not clusters.check_config(cluster):
raise ex.LoadError('cluster', cluster, 'NoConfFile')
else:
try:
with open(JUMBODIR + cluster + '/jumbo_config', 'r') as jc:
svars = json.load(jc)
except IOError as e:
raise ex.LoadError('cluster', cluster, e.strerror)
vs.update_versions_file()
return True