Example #1
0
def get_node_list(service_name, ports=[], minimum=1, labels = []):
	# It takes in a service name and an optional list of port names and returns the list of IP addresses/hostname of the containers of that service. For each port specified, in order, it will append :<port number> to each host with the external port number. For example, if you want to return the list of ZooKeeper endpoints with their client ports:
	# get_node_list('zookeeper', ports=['client']) -> ['c414.ore1.domain.com:2181', 'c415.ore1.domain.com:2181']
	nodes = []
	service_groups = etcd_driver.get_service_groups(service_name)	
	for group in service_groups:
		try:
			group_labels = ast.literal_eval(group)
			fits_label_query = Set(labels).issubset(Set(group_labels))
			if fits_label_query:
				group_containers = etcd_driver.get_group_container_names(service_name, group)
				for container_name in group_containers:
					container_info = etcd_driver.get_container_info(service_name, group, container_name)
					host = str(container_info['instance_host'])
					portlist = ""
					for port in ports:
						p = get_specific_port(container_info['service_name'], container_info['instance_name'], port)
						p = ":" + p
						portlist = portlist + p
					nodes.append(str(host + portlist))
		except Exception as failure:
			# print 'getting group labels failed '+str(failure)
			print 'failed'
			print failure
	return nodes
Example #2
0
def get_specific_port(service, container, port, default='default'):
	# to retrieve the external port number of a specific named port of a given container.
	container_encoded_labels = str(sorted(decode_marathon_id(container)['labels']))
	container_info = etcd_driver.get_container_info(service, container_encoded_labels, container)
	port_mappings = container_info['port_mapping']
	port_mapping = port_mappings.get(port)
	if port_mapping is None:
		return default
	return port_mapping['external'][1].replace('/tcp', '')
Example #3
0
def get_all_data():
	data = {}
	service_names = etcd_driver.get_service_names()
	for service_name in service_names:
		service_dict = {}
		service_groups = etcd_driver.get_service_groups(service_name)
		for group in service_groups:
			group_containers = []
			for container_name in etcd_driver.get_group_container_names(service_name, group):
				container_data = {}
				container_data['name'] = container_name
				container_data['info'] = etcd_driver.get_container_info(service_name, group, container_name)
				group_containers.append(container_data)
			service_dict[group] = group_containers
		data[service_name]  = service_dict
	return data
Example #4
0
def get_all_etcd_data():
	data = {}
	service_names = etcd_driver.get_service_names()
	for service_name in service_names:
		service_dict = {}
		service_groups = etcd_driver.get_service_groups(service_name)
		for group in service_groups:
			if etcd_driver.group_exists(service_name, group) and group != "":
				print 'adding this group'
				print service_name
				print group
				group_containers = []
				for container_name in etcd_driver.get_group_container_names(service_name, group):
					container_data = {}
					container_data['name'] = container_name
					container_data['info'] = etcd_driver.get_container_info(service_name, group, container_name)
					group_containers.append(container_data)
				group_config = etcd_driver.get_group_config(service_name, group)
				service_dict[group] = {'containers': group_containers, 'config':group_config}
		data[service_name]  = service_dict
	return data
Example #5
0
def get_specific_host(service, container):
	# which can be used to return the hostname or IP address of a specific container from a given service, and
	container_encoded_labels = str(sorted(decode_marathon_id(container)['labels']))
	container_info = etcd_driver.get_container_info(service, container_encoded_labels, container)
	return container_info['instance_host']