Initial thoughts on PG service

This commit is contained in:
Endre Karlson 2013-03-07 11:29:03 +00:00
parent b4ee207181
commit 161720becc
2 changed files with 101 additions and 0 deletions

View File

@ -0,0 +1,68 @@
"""
A service that does calls towards the PGP web endpoint or so
"""
import functools
import re
from oslo.config import cfg
from billingstack.openstack.common import log as logging
from billingstack.openstack.common import rpc
from billingstack.openstack.common.rpc import service as rpc_service
from stevedore.named import NamedExtensionManager
from billingstack import exceptions
from billingstack import utils
from billingstack.central.rpcapi import CentralAPI
cfg.CONF.import_opt('host', 'billingstack.netconf')
cfg.CONF.import_opt('host', 'billingstack.payment_gateway.rpcapi')
LOG = logging.getLogger(__name__)
class Service(rpc_service.Service):
def __init__(self, *args, **kwargs):
kwargs.update(
host=cfg.CONF.host,
topic=cfg.CONF.central_topic,
)
super(Service, self).__init__(*args, **kwargs)
# Get a storage connection
self.central_api = CentralAPI()
def pg_provider_get(self, ctxt, pg_info):
"""
Work out a PGC config either from pg_info or via ctxt fetching it from central.
Return the appropriate PGP for this info.
:param ctxt: Request context
:param pg_info: Payment Gateway Config...
"""
def account_add(self, ctxt, values, pg_config=None):
"""
Create an Account on the underlying provider
:param values: The account values
"""
def __getattr__(self, name):
"""
Proxy onto the storage api if there is no local method present..
For now to avoid to have to write up every method once more here...
"""
if hasattr(self, name):
return getattr(self, name)
f = getattr(self.provider, name)
if not f:
raise AttributeError
@functools.wraps(f)
def _wrapper(*args, **kw):
return f(*args, **kw)
setattr(self, name, _wrapper)
return _wrapper

View File

@ -0,0 +1,33 @@
#!/usr/bin/env python
# Copyright 2012 Managed I.T.
#
# Author: Kiall Mac Innes <kiall@managedit.ie>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import sys
import eventlet
from oslo.config import cfg
from billingstack.openstack.common import log as logging
from billingstack.openstack.common import service
from billingstack import utils
from billingstack.central import service as central_service
eventlet.monkey_patch()
utils.read_config('billingstack', sys.argv)
logging.setup('billingstack')
launcher = service.launch(central_service.Service(),
cfg.CONF['service:payment_gateway'].workers)
launcher.wait()