Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@valid_cluster
def remove_component(component, *, node, cluster):
"""Remove a service of a specified node in a specified cluster.
:param name: Service name
:type name: str
:param node: Machine name
:type node: str
:param cluster: Cluster name
:type cluster: str
:raises ex.LoadError: [description]
:raises ex.CreationError: [description]
"""
ss.load_config(cluster)
if not nodes.check_node(cluster=cluster, node=node):
@valid_cluster
def check_node(*, cluster, node):
"""
Check if a node with a specified name exists in a specific cluster.
:param cluster: Cluster name
:type cluster: str
:param name: Machine name
:type name: str
:raises ex.LoadError: If the cluster couldn't be loaded
:return: True if the node exists
:rtype: bool
"""
for m in ss.svars['nodes']:
if m['name'] == node:
return True
@valid_cluster
def cmd(cmd, *, cluster):
"""Run a command in the vagrantfile folder and print output
"""
ss.load_config(cluster)
ss.dump_config()
try:
res = subprocess.Popen(cmd,
cwd=os.path.join(JUMBODIR, cluster),
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT
)
for line in res.stdout:
print(line.decode('utf-8').rstrip())
@valid_cluster
def rm_pass(vault_key, password, *, cluster):
"""Remove entry from cluster vault"""
vault_file = JUMBODIR + 'clusters/' + cluster + '/inventory/group_vars/all/vault'
vault = Vault(password)
data = {}
if os.path.isfile(vault_file):
data = vault.load(open(vault_file).read())
try:
delete_key(data, vault_key)
except KeyError:
raise ex.LoadError('key', vault_key, 'NotExist')
else:
raise ex.LoadError('vault for cluster', cluster, 'NotExist')
@checks.valid_cluster
def repair_cluster(domain, *, cluster):
"""Recreate the cluster 'jumbo_config' file if it doesn't exist.
:param name: Cluster name
:type name: str
:param domain: Cluster domaine name
:type domain: str
:return: True if the 'jumbo_config' has been recreated
"""
if not check_config(cluster):
ss.clear()
ss.svars['cluster'] = cluster
ss.svars['domain'] = domain if domain else '%s.local' % cluster
ss.dump_config()
return True
@valid_cluster
def edit_node(name, ip=None, ram=None, cpus=None, *, cluster):
"""Modify an existing node in a cluster.
"""
ss.load_config(cluster=cluster)
if not check_node(cluster=cluster, node=name):
raise ex.LoadError('node', name, 'NotExist')
if check_ip(ip, cluster=cluster):
raise ex.CreationError('node', name, 'IP', ip, 'Exists')
changed = []
for i, m in enumerate(ss.svars['nodes']):
@valid_cluster
def check_service_complete(name, *, cluster):
"""Check if all the components required are installed for a service
:param name: Service name
:type name: str
:param ha: If the service is in HA mode, defaults to False
:param ha: bool, optional
:return: A list of the components missing and their cardinalities
:rtype: dict
"""
print_missing = []
missing_comp = check_service_req_comp(name)
if missing_comp:
@valid_cluster
def restart(*, cluster):
handle_cmd(['vagrant', 'halt', '--color'], cluster=cluster)
handle_cmd(['vagrant', 'up', '--color'], cluster=cluster)
@valid_cluster
def get_pass(vault_key, password, *, cluster):
"""Print YAML representation of cluster vault"""
vault_file = JUMBODIR + 'clusters/' + cluster + '/inventory/group_vars/all/vault'
vault = Vault(password)
data = {}
if os.path.isfile(vault_file):
data = vault.load(open(vault_file).read())
else:
raise ex.LoadError('vault for cluster', cluster, 'NotExist')
if vault_key == '*':
print(yaml.dump(data, default_flow_style=False))
else:
try: