Exemple #1
0
def metricGet(request):
	""" Return metric object by name """

	try:
		ret = metrics.get(request.get('id'))

		if not ret:
			return jsonrpc.result_error('InvalidRequest',
				{ 'status': 'error', 'message': 'Metric not found' })

	except Exception, e:
		LOG.error(e)
		return jsonrpc.result_error('ServerError',
			{ 'status': 'error', 'message': 'Unable to obtain metric' })
Exemple #2
0
	def test_metric_get(self):
		"""Check getting metric from db"""

		data = {
				'id':         str(uuid.uuid4()),
				'type':       str(uuid.uuid4())[:10],
				'formula':    metrics.constants.FORMULA_SPEED,
				'aggregate':  0L,
		}

		met = metrics.Metric(data)

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

		self.assertEquals(metrics.get(met.id), met)
Exemple #3
0
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)