コード例 #1
0
ファイル: database.py プロジェクト: legionus/billing
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]