Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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')
print(yaml.dump(data, default_flow_style=False))
vault.dump(data, open(vault_file, 'wb'))
def get_yaml_config(cluster=None):
"""Get the versions to use for each service/platform/ressource
:raises ex.LoadError: If the file versions.json doesn't exist
:return: The versions to use
:rtype: dict
"""
yaml_versions = {
'services': {},
'platform': {}
}
if not os.path.isfile(JUMBODIR + 'versions.json'):
raise ex.LoadError('file', JUMBODIR + 'versions.json', 'NotExist')
# Global versions settings
with open(JUMBODIR + 'versions.json', 'r') as vs:
jumbo_versions = json.load(vs)
yaml_versions = update_yaml_versions(yaml_versions, jumbo_versions)
if not cluster:
return yaml_versions
# Cluster versions settings
if os.path.isfile(JUMBODIR + cluster + '/versions.json'):
with open(
JUMBODIR + cluster + '/versions.json', 'r') as vs:
cluster_versions = json.load(vs)
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
def auto_assign(service, ha, *, cluster):
"""Auto-install a service and its components on the best fitting hosts.
:param service: Service name
:type service: str
:param cluster: Cluster name
:type cluster: str
:raises ex.LoadError: If the cluster doesn't exist
:raises ex.CreationError: If the requirements are not met to install
"""
ss.load_config(cluster)
scfg = check_service(service)
if not scfg:
raise ex.LoadError('service', service, 'NotExist')
# dist is 'default' or 'ha'
dist = 'ha' if ha else 'default'
# Check loop for atomicity
for component in scfg['components']:
left = auto_assign_service_comp(component, dist, cluster, check=True)
if left == -1:
raise ex.CreationError('component', component['name'],
'hosts type (need at least 1 of them)',
(' - %s'
% c for c in component['hosts_types']),
'ReqNotMet')
elif left > 0:
raise ex.CreationError('component', component['name'],
'hosts type (need ' + str(left) +
' of them)',
:param cluster: Cluster name
:type cluster: str
:raises ex.LoadError: [description]
:raises ex.CreationError: [description]
"""
for i, m in enumerate(ss.svars['nodes']):
if m['name'] == node:
m_index = i
break
else:
raise ex.LoadError('node', node, 'NotExist')
service = check_component(name)
if not service:
raise ex.LoadError('component', name, 'NotExist')
if not check_service_cluster(service):
raise ex.CreationError(
'cluster', cluster, 'service', service, 'NotInstalled')
for i, m in enumerate(ss.svars['nodes']):
if m['name'] == node:
m_index = i
if ha is None:
ha = check_comp_number(service, name)
missing_serv, missing_comp = check_service_req_service(service, ha)
if missing_serv:
raise ex.CreationError('component', name, 'services', missing_serv,
'ReqNotMet')
for l in cluster:
if l not in allowed_chars:
raise ex.CreationError('cluster', cluster, 'name',
'Allowed characters: ' + allowed_chars,
'NameNotAllowed')
ss.clear()
data_dir = os.path.dirname(os.path.abspath(__file__)) + '/data/'
config_dir = os.path.dirname(os.path.abspath(__file__)) + '/config/'
if template:
try:
with open(config_dir + 'templates/' + template + '.json') \
as template_file:
ss.svars = json.load(template_file)
except:
raise ex.LoadError('template', template, 'NotExist')
pathlib.Path(JUMBODIR + cluster).mkdir(parents=True)
dir_util.copy_tree(data_dir, JUMBODIR + cluster)
dir_util._path_created = {}
ss.svars['cluster'] = cluster
ss.svars['domain'] = domain if domain else '%s.local' % cluster
services_components_hosts = None
if template:
services_components_hosts = services.get_services_components_hosts()
ss.dump_config(services_components_hosts)
return True
req_number = comp['number'][req] if comp['number'][req] != -1 \
else 1
missing_count = req_number - comp_count[comp['name']]
if missing_count > 0:
missing['default'][comp['name']] = missing_count
req = 'ha'
req_number = comp['number'][req] if comp['number'][req] != -1 \
else 1
missing_count = req_number - comp_count[comp['name']]
if missing_count > 0:
missing['ha'][comp['name']] = missing_count
if not missing['ha'] or not missing['default']:
return {}
return missing
raise ex.LoadError('service', name, 'NotExist')
if serv_comp_host[service].get(comp['name']):
n = len(serv_comp_host[service][comp['name']])
if n > max_n and max_n != -1:
to_remove[comp['name']] = n - max_n
if to_remove:
print_remove = []
for k, v in to_remove.items():
print_remove.append('{} {}'.format(v, k))
raise ex.CreationError('service',
service,
'components',
print_remove,
'TooManyHA')
return True
return False
raise ex.LoadError('component', component, 'NotExist')
raise ex.LoadError('service', service, 'NotExist')