示例#1
0
def get_host(dbtype, key=None):
	"""Returns database server"""

	conf = config.read()

	if key != None:
		data = config.subdict(conf['database']['shards'], field='weight')
		ring = hashing.HashRing(data.keys(), data)
		return conf['database']['shards'][ring.get_node(key)]['server']
	elif dbtype == 'local':
		for shard in conf['database']['shards'].itervalues():
			if shard['local'] == True:
				return shard['server']
	elif dbtype == 'global':
		return conf['database']['server']
示例#2
0
文件: zones.py 项目: legionus/billing
def write_zone(key):
	conf = config.read()
	data = config.subdict(conf['zones'], field='weight')
	ring = hashing.HashRing(data.keys(), data)
	res  = ring.get_node(key)
	return conf['zones'][res]