Beispiel #1
0
    def __init__(self, *args, **kwargs):
        self.region_name = cfg.CONF.region_name
        self.gclient = client.get_client()
        self.master_api = master.API()
        self.ctxt = context.get_admin_context()
        self.notifier = notifier.NotifierService(
            cfg.CONF.checker.notifier_level)

        job_defaults = {
            'misfire_grace_time': 604800,
            'coalesce': False,
            'max_instances': 24,
        }
        self.apsched = background.BackgroundScheduler(
            job_defaults=job_defaults,
            timezone=pytz.utc)

        self.RESOURCE_LIST_METHOD = services.RESOURCE_LIST_METHOD
        self.DELETE_METHOD_MAP = services.DELETE_METHOD_MAP
        self.STOP_METHOD_MAP = services.STOP_METHOD_MAP
        self.RESOURCE_STOPPED_STATE = services.RESOURCE_STOPPED_STATE
        self.RESOURCE_GET_MAP = services.RESOURCE_GET_MAP

        # NOTE(suo): Import 'common' to invoke register_class methods.
        # Don't import this in module level, because it need to read
        # config file, so it should be imported after service initialization
        from gringotts.checker import common  # noqa

        self.RESOURCE_CREATE_MAP = services.RESOURCE_CREATE_MAP

        super(CheckerService, self).__init__(*args, **kwargs)
Beispiel #2
0
    def __init__(self, *args, **kwargs):
        self.region_name = cfg.CONF.region_name
        self.gclient = client.get_client()
        self.master_api = master.API()
        self.ctxt = context.get_admin_context()
        self.notifier = notifier.NotifierService(
            cfg.CONF.checker.notifier_level)

        job_defaults = {
            'misfire_grace_time': 604800,
            'coalesce': False,
            'max_instances': 24,
        }
        self.apsched = background.BackgroundScheduler(
            job_defaults=job_defaults, timezone=pytz.utc)

        self.RESOURCE_LIST_METHOD = services.RESOURCE_LIST_METHOD
        self.DELETE_METHOD_MAP = services.DELETE_METHOD_MAP
        self.STOP_METHOD_MAP = services.STOP_METHOD_MAP
        self.RESOURCE_STOPPED_STATE = services.RESOURCE_STOPPED_STATE
        self.RESOURCE_GET_MAP = services.RESOURCE_GET_MAP

        # NOTE(suo): Import 'common' to invoke register_class methods.
        # Don't import this in module level, because it need to read
        # config file, so it should be imported after service initialization
        from gringotts.checker import common  # noqa

        self.RESOURCE_CREATE_MAP = services.RESOURCE_CREATE_MAP

        super(CheckerService, self).__init__(*args, **kwargs)
Beispiel #3
0
 def wrapped(uuid, *args, **kwargs):
     try:
         if exc_type == 'delete' or exc_type == 'stop':
             gclient = client.get_client()
             order = gclient.get_order_by_resource_id(uuid)
             account = gclient.get_account(order['user_id'])
             if (order['unit'] == 'hour' and order['owed']
                     and account['owed']
                     and Decimal(str(account['balance'])) < 0
                     and int(account['level']) != 9) or (
                         order['unit'] in ['month', 'year']
                         and order['owed']):
                 LOG.warn(
                     "The resource: %s is indeed owed, can be execute"
                     "the action: %s", uuid, f.__name__)
                 return f(uuid, *args, **kwargs)
             else:
                 LOG.warn(
                     "The resource: %s is not owed, should not execute"
                     "the action: %s", uuid, f.__name__)
         else:
             return f(uuid, *args, **kwargs)
     except Exception as e:
         msg = None
         if exc_type == 'single' or exc_type == 'delete' or exc_type == 'stop':
             msg = 'Fail to do %s for resource: %s, reason: %s' % (
                 f.__name__, uuid, e)
         elif exc_type == 'bulk':
             msg = 'Fail to do %s for account: %s, reason: %s' % (
                 f.__name__, uuid, e)
         elif exc_type == 'list':
             msg = 'Fail to do %s for account: %s, reason: %s' % (
                 f.__name__, uuid, e)
         elif exc_type == 'get':
             msg = 'Fail to do %s for resource: %s, reason: %s' % (
                 f.__name__, uuid, e)
         elif exc_type == 'put':
             msg = 'Fail to do %s for resource: %s, reason: %s' % (
                 f.__name__, uuid, e)
         else:
             msg = 'Fail to do %s, reason: %s' % (f.__name__, e)
         if with_raise:
             raise GringottsException(message=msg)
         else:
             LOG.error(msg)
             return []
Beispiel #4
0
 def wrapped(uuid, *args, **kwargs):
     try:
         if exc_type == 'delete' or exc_type == 'stop':
             gclient = client.get_client()
             order = gclient.get_order_by_resource_id(uuid)
             account = gclient.get_account(order['user_id'])
             if (order['unit'] == 'hour' and
                 order['owed'] and
                 account['owed'] and
                 Decimal(str(account['balance'])) < 0 and
                 int(account['level']) != 9) or (
                 order['unit'] in ['month', 'year'] and
                 order['owed']):
                 LOG.warn("The resource: %s is indeed owed, can be execute"
                          "the action: %s", uuid, f.__name__)
                 return f(uuid, *args, **kwargs)
             else:
                 LOG.warn("The resource: %s is not owed, should not execute"
                          "the action: %s", uuid, f.__name__)
         else:
             return f(uuid, *args, **kwargs)
     except Exception as e:
         msg = None
         if exc_type == 'single' or exc_type == 'delete' or exc_type == 'stop':
             msg = 'Fail to do %s for resource: %s, reason: %s' % (f.__name__, uuid, e)
         elif exc_type == 'bulk':
             msg = 'Fail to do %s for account: %s, reason: %s' % (f.__name__, uuid, e)
         elif exc_type == 'list':
             msg = 'Fail to do %s for account: %s, reason: %s' % (f.__name__, uuid, e)
         elif exc_type == 'get':
             msg = 'Fail to do %s for resource: %s, reason: %s' % (f.__name__, uuid, e)
         elif exc_type == 'put':
             msg = 'Fail to do %s for resource: %s, reason: %s' % (f.__name__, uuid, e)
         else:
             msg = 'Fail to do %s, reason: %s' % (f.__name__, e)
         if with_raise:
             raise GringottsException(message=msg)
         else:
             LOG.error(msg)
             return []
Beispiel #5
0
    def __init__(self, *args, **kwargs):
        kwargs.update(
            host=cfg.CONF.host,
            topic=cfg.CONF.master.master_topic,
        )

        self.locks = {}
        self.gclient = client.get_client()
        self.ctxt = context.get_admin_context()

        job_defaults = {
            'misfire_grace_time': 6048000,
            'coalesce': False,
            'max_instances': 24,
        }
        self.apsched = background.BackgroundScheduler(
            job_defaults=job_defaults, timezone=pytz.utc)

        self.DELETE_METHOD_MAP = services.DELETE_METHOD_MAP
        self.STOP_METHOD_MAP = services.STOP_METHOD_MAP
        self.RESOURCE_GET_MAP = services.RESOURCE_GET_MAP

        super(MasterService, self).__init__(*args, **kwargs)
Beispiel #6
0
 def wrapped(uuid, *args, **kwargs):
     try:
         if exc_type == "delete" or exc_type == "stop":
             gclient = client.get_client()
             order = gclient.get_order_by_resource_id(uuid)
             account = gclient.get_account(order["user_id"])
             if (
                 order["unit"] == "hour"
                 and order["owed"]
                 and account["owed"]
                 and Decimal(str(account["balance"])) < 0
                 and int(account["level"]) != 9
             ) or (order["unit"] in ["month", "year"] and order["owed"]):
                 LOG.warn("The resource: %s is indeed owed, can be execute" "the action: %s", uuid, f.__name__)
                 return f(uuid, *args, **kwargs)
             else:
                 LOG.warn("The resource: %s is not owed, should not execute" "the action: %s", uuid, f.__name__)
         else:
             return f(uuid, *args, **kwargs)
     except Exception as e:
         msg = None
         if exc_type == "single" or exc_type == "delete" or exc_type == "stop":
             msg = "Fail to do %s for resource: %s, reason: %s" % (f.__name__, uuid, e)
         elif exc_type == "bulk":
             msg = "Fail to do %s for account: %s, reason: %s" % (f.__name__, uuid, e)
         elif exc_type == "list":
             msg = "Fail to do %s for account: %s, reason: %s" % (f.__name__, uuid, e)
         elif exc_type == "get":
             msg = "Fail to do %s for resource: %s, reason: %s" % (f.__name__, uuid, e)
         elif exc_type == "put":
             msg = "Fail to do %s for resource: %s, reason: %s" % (f.__name__, uuid, e)
         else:
             msg = "Fail to do %s, reason: %s" % (f.__name__, e)
         if with_raise:
             raise GringottsException(message=msg)
         else:
             LOG.error(msg)
Beispiel #7
0
    def __init__(self, *args, **kwargs):
        kwargs.update(
            host=cfg.CONF.host,
            topic=cfg.CONF.master.master_topic,
        )

        self.locks = {}
        self.gclient = client.get_client()
        self.ctxt = context.get_admin_context()

        job_defaults = {
            'misfire_grace_time': 6048000,
            'coalesce': False,
            'max_instances': 24,
        }
        self.apsched = background.BackgroundScheduler(
            job_defaults=job_defaults,
            timezone=pytz.utc)

        self.DELETE_METHOD_MAP = services.DELETE_METHOD_MAP
        self.STOP_METHOD_MAP = services.STOP_METHOD_MAP
        self.RESOURCE_GET_MAP = services.RESOURCE_GET_MAP

        super(MasterService, self).__init__(*args, **kwargs)
Beispiel #8
0
import six

from oslo_config import cfg
from stevedore import extension

from gringotts.client import client
from gringotts import constants as const
from gringotts.openstack.common import uuidutils
from gringotts.price import pricing
from gringotts.services import keystone as ks_client
from gringotts.services import register_class


CONF = cfg.CONF

GCLIENT = client.get_client()

RESOURCE_SERVICE_TYPE = ["network", "network", "network", "compute", "volume", "volume", "image"]
RESOURCE = ["floatingip", "router", "listener", "instance", "volume", "snapshot", "image"]

register_class = functools.partial(register_class, ks_client)


class Resource(object):

    """TODO(chengkun): Maybe put it in public area?  """

    def __init__(self, resource_id, resource_name, type, status, user_id, project_id):
        self.resource_id = resource_id
        self.resource_name = resource_name
        self.type = type
Beispiel #9
0
 def __init__(self):
     self.gclient = client.get_client()
Beispiel #10
0
 def __init__(self):
     self.gclient = client.get_client()
     self.master_api = master.API()
Beispiel #11
0
import functools
import six

from oslo_config import cfg
from stevedore import extension

from gringotts.client import client
from gringotts import constants as const
from gringotts.openstack.common import uuidutils
from gringotts.price import pricing
from gringotts.services import keystone as ks_client
from gringotts.services import register_class

CONF = cfg.CONF

GCLIENT = client.get_client()

RESOURCE_SERVICE_TYPE = [
    'network', 'network', 'network', 'compute', 'volume', 'volume', 'image'
]
RESOURCE = [
    'floatingip', 'router', 'listener', 'instance', 'volume', 'snapshot',
    'image'
]

register_class = functools.partial(register_class, ks_client)


class Resource(object):
    """TODO(chengkun): Maybe put it in public area?  """
    def __init__(self, resource_id, resource_name, type, status, user_id,
Beispiel #12
0
 def __init__(self):
     self.gclient = client.get_client()
Beispiel #13
0
 def __init__(self):
     self.gclient = client.get_client()
     self.master_api = master.API()