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)
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 []
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 []
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)
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)
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
def __init__(self): self.gclient = client.get_client()
def __init__(self): self.gclient = client.get_client() self.master_api = master.API()
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,