Exemple #1
0
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"})
Exemple #2
0
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"})
Exemple #3
0
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' })
Exemple #4
0
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"})
Exemple #5
0
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' })
Exemple #6
0
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' })
Exemple #7
0
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"})
Exemple #8
0
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' })
Exemple #9
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' })
Exemple #10
0
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' })
Exemple #11
0
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' })
Exemple #12
0
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' })