def rateAdd(params): """ Adds new rate """ try: srv = zones.write_zone(params["tariff_id"]) if not srv["local"]: return jsonrpc.result({"status": "redirect", "server": srv["server"]}) if "currency" in params: v = rates.constants.import_currency(params["currency"]) w = rates.constants.import_state(params["state"]) if v == None: return jsonrpc.result_error( "InvalidRequest", {"status": "error", "message": "Wrong currency: " + str(params["currency"])} ) if w == None: return jsonrpc.result_error( "InvalidRequest", {"status": "error", "message": "Wrong state: " + str(params["state"])} ) params["currency"] = v params["state"] = w o = rates.Rate(params) rates.add(o) except Exception, e: LOG.error(e) return jsonrpc.result_error("ServerError", {"status": "error", "message": "Unable to add new rate"})
def rateModify(params): """ Modify rate """ try: srv = zones.write_zone(params["tariff_id"]) if not srv["local"]: return jsonrpc.result({"status": "redirect", "server": srv["server"]}) if len(params) <= 2: return jsonrpc.result_error("InvalidRequest", {"status": "error", "message": "More arguments required"}) if "currency" in params: v = rates.constants.import_currency(params["currency"]) if v == None: return jsonrpc.result_error( "InvalidRequest", {"status": "error", "message": "Wrong currency: " + str(params["currency"])} ) params["currency"] = v tid, mid = params["tariff_id"], params["metric_id"] del params["tariff_id"], params["metric_id"] rates.modify(tid, mid, params) except Exception, e: LOG.error(e) return jsonrpc.result_error("ServerError", {"status": "error", "message": "Unable to modify rate"})
def customerModify(params): """ Modify customer's record """ try: srv = zones.write_zone(params['id']) if not srv['local']: return jsonrpc.result({ 'status':'redirect', 'server': srv['server'] }) if len(params) == 1: return jsonrpc.result({ 'status':'ok' }) if 'state' in params: v = customers.constants.import_state(params['state']) if v == None or v == customers.constants.STATE_DELETED: return jsonrpc.result_error('InvalidRequest', {'status':'error', 'message':'Wrong state: ' + str(params['state'])}) params['state'] = v if 'wallet_mode' in params: v = customers.constants.import_wallet_mode(params['wallet_mode']) if v == None: return jsonrpc.result_error('InvalidRequest', {'status':'error', 'message':'Wrong wallet_mode: ' + str(params['wallet_mode'])}) params['wallet_mode'] = v customers.modify('id', params['id'], params) except Exception, e: LOG.error(e) return jsonrpc.result_error('ServerError', { 'status': 'error', 'message': 'Unable to modify customer' })
def rateRemove(params): try: srv = zones.write_zone(params["tariff_id"]) if not srv["local"]: return jsonrpc.result({"status": "redirect", "server": srv["server"]}) rates.remove(params["tariff_id"], params["metric_id"]) except Exception, e: LOG.error(e) return jsonrpc.result_error("ServerError", {"status": "error", "message": "Unable to remove rate"})
def tariffRemove(params): try: srv = zones.write_zone(params['id']) if not srv['local']: return jsonrpc.result({ 'status':'redirect', 'server': srv['server'] }) tariffs.remove('id', params['id']) except Exception, e: LOG.error(e) return jsonrpc.result_error('ServerError', { 'status': 'error', 'message': 'Unable to remove tariff' })
def tariffAdd(params): try: srv = zones.write_zone(params['id']) if not srv['local']: return jsonrpc.result({ 'status':'redirect', 'server': srv['server'] }) c = tariffs.Tariff(params) tariffs.add(c) except Exception, e: LOG.error(e) return jsonrpc.result_error('ServerError', { 'status': 'error', 'message': 'Unable to add new tariff' })
def rateGet(params): try: ret = rates.get_by_metric(params["tariff_id"], params["metric_id"]) if not ret: srv = zones.write_zone(params["tariff_id"]) if not srv["local"]: return jsonrpc.result({"status": "redirect", "server": srv["server"]}) return jsonrpc.result_error("InvalidRequest", {"status": "error", "message": "Rate not found"}) except Exception, e: LOG.error(e) return jsonrpc.result_error("ServerError", {"status": "error", "message": "Unable to obtain rate list"})
def customerRemove(params): """ Remove customer by name """ try: srv = zones.write_zone(params['id']) if not srv['local']: return jsonrpc.result({ 'status':'redirect', 'server': srv['server'] }) c = customers.remove('id', params['id']) except Exception, e: LOG.error(e) return jsonrpc.result_error('ServerError', { 'status': 'error', 'message': 'Unable to remove customer' })
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 customerDeposit(params): """ Make deposit to customer """ try: srv = zones.write_zone(params['id']) if not srv['local']: return jsonrpc.result({ 'status':'redirect', 'server': srv['server'] }) if params['value'] != 0: customers.deposit(params['id'], params['value']) except Exception, e: LOG.error(e) return jsonrpc.result_error('ServerError', { 'status': 'error', 'message': 'Unable to make a deposit' })
def tariffModify(params): try: srv = zones.write_zone(params['id']) if not srv['local']: return jsonrpc.result({ 'status':'redirect', 'server': srv['server'] }) if len(params) == 1: return jsonrpc.result({ 'status':'ok' }) if 'state' in params: v = tariffs.constants.import_state(params['state']) if v == None or v == tariffs.constants.STATE_DELETED: return jsonrpc.result_error('InvalidRequest', { 'status':'error', 'message':'Wrong state: ' + str(params['state'])}) params['state'] = v tariffs.modify('id', params['id'], params) except Exception, e: LOG.error(e) return jsonrpc.result_error('ServerError', { 'status': 'error', 'message': 'Unable to modify tariff' })
def customerAdd(params): """ Adds new customer account """ try: srv = zones.write_zone(params['id']) if not srv['local']: return jsonrpc.result({ 'status':'redirect', 'server': srv['server'] }) wallet_mode = customers.constants.import_wallet_mode(params['wallet_mode']) if wallet_mode == None: return jsonrpc.result_error('InvalidRequest', {'status':'error', 'message':'Wrong wallet_mode: ' + str(params['wallet_mode'])}) params['wallet_mode'] = wallet_mode c = customers.Customer(params) customers.add(c) except Exception, e: LOG.error(e) return jsonrpc.result_error('ServerError', { 'status': 'error', 'message': 'Unable to add new customer' })