Exemplo n.º 1
0
# Copyright (c) 2012-2013 by Alexey Gladkov
# Copyright (c) 2012-2013 by Nikolay Ivanov
#
# This file is covered by the GNU General Public License,
# which should be included with billing as the file COPYING.
#
__version__ = '1.0'

import bc_jsonrpc as jsonrpc

from bc.validator import Validate as V
from bc import tariffs
from bc import log
from bc import zones

LOG = log.logger("wapi.tariffs")


@jsonrpc.method(validate=False, auth=True)
def tariffList(params):
	try:
		ret = map(lambda c: c.values, tariffs.get_all())

	except Exception, e:
		LOG.error(e)
		return jsonrpc.result_error('ServerError',
			{ 'status': 'error', 'message': 'Unable to obtain tariff list' })

	return jsonrpc.result({ 'status':'ok', 'tariffs': ret })

Exemplo n.º 2
0
#
# client.py
#
# Copyright (c) 2012-2013 by Nikolay Ivanov
#
# This file is covered by the GNU General Public License,
# which should be included with billing as the file COPYING.
#

from connectionpool import HTTPConnectionPool

from bc import log
from bc_jsonrpc import message
from bc_jsonrpc import http

LOG = log.logger("client", syslog=False)


class BillingError(Exception):
	def __init__(self, fmt, *args):
		Exception.__init__(self, fmt.format(*args))


ERRORS = dict((str(message.error_codes[i]['code']), lambda x: BillingError(i+': {0}', x)) for i in message.error_codes.keys())
ERRORS['0'] = lambda x: BillingError('Invalid return message')


class BCClient(object):
	def __init__(self, method_dict, auth, local_server=None):

		self.__dict__.update(locals())
Exemplo n.º 3
0
# which should be included with billing as the file COPYING.
#

__version__ = '1.0'

import time
import bc_jsonrpc as jsonrpc

from bc.validator import Validate as V
from bc import log
from bc import customers
from bc import rates
from bc import tasks
from bc import polinomial

LOG = log.logger("wapi.tasks")
GROUPID = iter(polinomial.permutation())

@jsonrpc.method(
	validate = V({
			# Metric
			'type':		V(basestring),

			'customer':	V(basestring, min=36, max=36),

			'value':	V(int),

			# Info
			'user':		V(basestring, min=1,  max=64),
			'uuid':		V(basestring, min=36, max=36),
			'descr':	V(basestring),
Exemplo n.º 4
0
# Copyright (c) 2012-2013 by Alexey Gladkov
# Copyright (c) 2012-2013 by Nikolay Ivanov
#
# This file is covered by the GNU General Public License,
# which should be included with billing as the file COPYING.
#
__version__ = "1.0"

import bc_jsonrpc as jsonrpc

from bc.validator import Validate as V
from bc import rates
from bc import log
from bc import zones

LOG = log.logger("wapi.rates")


@jsonrpc.method(validate=V({"tariff_id": V(basestring, required=False, min=36, max=36)}, drop_optional=True), auth=True)
def rateList(params):
    try:
        if len(params) == 0:
            ret = map(lambda c: c.values, rates.get_all())

        elif len(params) == 1:
            ret = map(lambda c: c.values, rates.get_by_tariff(params["tariff_id"]))

    except Exception, e:
        LOG.error(e)
        return jsonrpc.result_error("ServerError", {"status": "error", "message": "Unable to obtain rate list"})
Exemplo n.º 5
0
# Copyright (c) 2012-2013 by Alexey Gladkov
# Copyright (c) 2012-2013 by Nikolay Ivanov
#
# This file is covered by the GNU General Public License,
# which should be included with billing as the file COPYING.
#

__version__ = '1.0'

import bc_jsonrpc as jsonrpc

from bc.validator import Validate as V
from bc import sync as bc_sync
from bc import log

LOG = log.logger("wapi.sync")


@jsonrpc.method(
	validate = V({
		'table':  V(basestring, min=3, max=36),
		'record': V(dict),
	}),
	auth = True)
def sync(params):
	try:
		bc_sync.record(params['table'], params['record'])

	except Exception, e:
		LOG.error(e)
		return jsonrpc.result_error('ServerError',
Exemplo n.º 6
0
# Copyright (c) 2012-2013 by Alexey Gladkov
# Copyright (c) 2012-2013 by Nikolay Ivanov
#
# This file is covered by the GNU General Public License,
# which should be included with billing as the file COPYING.
#

__version__ = '1.0'

import bc_jsonrpc as jsonrpc

from bc.validator import Validate as V
from bc import metrics
from bc import log

LOG = log.logger("wapi.metrics")

@jsonrpc.method(validate = False, auth = True)
def metricList(request):
	""" Returns a list of all registered metrics """

	try:
		ret = map(lambda m: m.values, metrics.get_all())

	except Exception, e:
		LOG.error(e)
		return jsonrpc.result_error('ServerError',
			{ 'status': 'error', 'message': 'Unable to obtain metric list' })

	return jsonrpc.result({ 'status': 'ok', 'metrics': ret })
Exemplo n.º 7
0
# This file is covered by the GNU General Public License,
# which should be included with billing as the file COPYING.
#

import os
import sys
import glob
import imp
import unittest2 as unittest

sys.path.insert(0, '../lib')

from bc import log

suite = unittest.TestSuite()

LOG = log.logger("unittests", type='stderr', level='debug', init=True)

for testpath in sorted(glob.glob('./test_*.py')):
	name = os.path.basename(testpath)[:-3]

	if len(sys.argv) > 1:
		if name not in sys.argv[1:] and name + '.py' not in sys.argv[1:]:
			continue

	test = imp.load_source(name, testpath)
	suite.addTests(unittest.TestLoader().loadTestsFromTestCase(test.Test))

result = unittest.TextTestRunner(verbosity=2).run(suite)
sys.exit(not result.wasSuccessful())
Exemplo n.º 8
0
#
# wapi_testy.py
#
# Copyright (c) 2012-2013 by Alexey Gladkov
# Copyright (c) 2012-2013 by Nikolay Ivanov
#
# This file is covered by the GNU General Public License,
# which should be included with billing as the file COPYING.
#
__version__ = '1.0'

import bc_jsonrpc as jsonrpc
from bc import log

LOG = log.logger("wapi.testy")

@jsonrpc.method(auth=0)
def test(params):
	return jsonrpc.result({'status':'ok'})
Exemplo n.º 9
0
# Copyright (c) 2012-2013 by Nikolay Ivanov
#
# This file is covered by the GNU General Public License,
# which should be included with billing as the file COPYING.
#
__version__ = '1.0'

import bc_jsonrpc as jsonrpc

from bc.validator import Validate as V
from bc import customers
from bc import log
from bc import zones


LOG = log.logger("wapi.customers")


@jsonrpc.method(validate = False, auth = True)
def customerList(request):
	""" Returns a list of all registered customers """

	try:
		ret = map(lambda c: c.values, customers.get_all())

	except Exception, e:
		LOG.error(e)
		return jsonrpc.result_error('ServerError',
			{ 'status': 'error', 'message': 'Unable to obtain customer list' })

	return jsonrpc.result({ 'status':'ok', 'customers': ret })