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' })
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)
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)