Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
raise RuntimeError(
'addbundle: invalid arguments. Name required.')
(active, available) = list_bundles()
if name in active:
raise Warning('addbundle: bundle `% s` already active. '
'Nothing to be done.' % name)
# IDEA: --force option (case of bundle called multiple time)
if name not in available:
raise RuntimeError('addbundle: bundle `%s` does not exist.' % name)
if position == 'last':
ss.svars['bundles'].append(name)
elif position == 'first':
ss.svars['bundles'].insert(0, name)
else:
if not position.isdigit():
raise RuntimeError(
'addbundle: invalid value for position. '
'Can be `last` (default), `first`, or a number.')
ss.svars['bundles'].insert(int(position), name)
services.config = services.load_services_conf(cluster=cluster)
ss.dump_config(services.get_services_components_hosts(),
services.config)
ip = None
for node in ss.svars['nodes']:
for comp in node['components']:
if comp == 'AMBARI_SERVER':
ip = node['ip']
break
if ip:
cmd = ('curl -u admin:admin -H "X-Requested-By: ambari" '
'-X PUT '
'-d \'{\"RequestInfo\": '
'{\"context\":\"Start all services\"}, '
'\"Body\":{\"ServiceInfo\": '
'{\"state\":\"STARTED\"}}}\' ' +
ip + ':8080/api/v1/clusters/' +
ss.svars['domain'].replace('.', '') + '/services')
retries = 0
accepted = False
res = subprocess.Popen(cmd,
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
for line in res.stdout:
if "Accepted" in line.decode('utf-8').rstrip():
accepted = True
break
while not accepted and retries < max_retries:
print('Server is not up yet. Retrying to start services...')
time.sleep(5)
res = subprocess.Popen(cmd,
def list_components(*, node, cluster):
"""List the components installed on a node of a specified cluster.
:param node: Machine name
:type node: str
:param cluster: Cluster name
:type cluster: str
:raises ex.LoadError: [description]
:return: The list of the components installed on the node
:rtype: list
"""
if not nodes.check_node(cluster=cluster, node=node):
raise ex.LoadError('node', node, 'NotExist')
if cluster != ss.svars['cluster']:
try:
with open(JUMBODIR + cluster + '/jumbo_config', 'r') as clf:
cluster_conf = json.load(clf)
except IOError as e:
raise ex.LoadError('cluster', cluster, e.strerror)
else:
cluster_conf = ss.svars
for m in cluster_conf['nodes']:
if m['name'] == node:
m_conf = m
break
return m_conf['components']
:raises ex.LoadError: [description]
:return: The list of the components installed on the node
:rtype: list
"""
if not nodes.check_node(cluster=cluster, node=node):
raise ex.LoadError('node', node, 'NotExist')
if cluster != ss.svars['cluster']:
try:
with open(JUMBODIR + cluster + '/jumbo_config', 'r') as clf:
cluster_conf = json.load(clf)
except IOError as e:
raise ex.LoadError('cluster', cluster, e.strerror)
else:
cluster_conf = ss.svars
for m in cluster_conf['nodes']:
if m['name'] == node:
m_conf = m
break
return m_conf['components']
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
raise ex.CreationError('node', name, 'IP', ip, 'Exists')
changed = []
for i, m in enumerate(ss.svars['nodes']):
if m['name'] == name:
if ip:
changed.append(["IP", ss.svars['nodes'][i]['ip'], ip])
ss.svars['nodes'][i]['ip'] = ip
if ram:
changed.append(["RAM", ss.svars['nodes'][i]['ram'], ram])
ss.svars['nodes'][i]['ram'] = ram
if cpus:
changed.append(["CPUs", ss.svars['nodes'][i]['cpus'], cpus])
ss.svars['nodes'][i]['cpus'] = cpus
ss.dump_config()
return changed
:param name: Service name
:type name: str
:param ha: Weither the service is in HA, defaults to False
:raises ex.LoadError: If the service doesn't exist
:return: The misssing services and components needed to install the service
:rtype: dict
"""
req = 'ha' if ha else 'default'
missing_serv = []
missing_comp = {}
for s in config['services']:
if s['name'] == name:
for req_s in s['requirements']['services'][req]:
if req_s not in ss.svars['services']:
missing_serv.append(req_s)
missing_comp.update(check_service_req_comp(req_s))
return missing_serv, missing_comp
raise ex.LoadError('service', name, 'NotExist')
allowed_chars = string.ascii_letters + string.digits + '-'
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