示例#1
0
def tariffGet(params):
	try:
		ret = tariffs.get(params['id'])

		if not ret:
			srv = zones.write_zone(params['id'])
			if not srv['local']:
				return jsonrpc.result({ 'status':'redirect', 'server': srv['server'] })

			return jsonrpc.result_error('InvalidRequest',
				{ 'status': 'error', 'message': 'Tariff not found' })
	except Exception, e:
		LOG.error(e)
		return jsonrpc.result_error('ServerError',
			{ 'status': 'error', 'message': 'Unable to obtain tariff' })
示例#2
0
	def test_tariff_get(self):
		"""Check getting tariff from db"""

		data = {
			'id':           unicode(uuid.uuid4()),
			'name':         str(uuid.uuid4()),
			'description':  str(uuid.uuid4()),
			'state':        tariffs.constants.STATE_ENABLED,
			'time_create':  int(time.time()),
			'time_destroy': 0,
		}

		tar = tariffs.Tariff(data)

		with database.DBConnect() as db:
			db.insert('tariffs', data)

		self.assertEquals(tariffs.get(tar.id), tar)
示例#3
0
文件: rates.py 项目: legionus/billing
def add(obj):
	"""Creates new metrics rate for tariff"""

	c = RateConstants()

	if obj.state < 0 or obj.state >= c.STATE_MAXVALUE:
		raise TypeError('Wrong state')

	with database.DBConnect() as db:
		r = tariffs.get(obj.tariff_id)
		if not r:
			raise ValueError("Wrong tariff")

		r = metrics.get(obj.metric_id)
		if not r:
			raise ValueError("Wrong metric")

		r = db.find_one('rates', { 'id': obj.id }, fields=['id'])
		if not r:
			db.insert('rates', obj.values)