Ejemplo n.º 1
0
def _make_cache_key(region_id, project_id, start_time, end_time):
    start_time = timeutils.isotime(start_time)
    end_time = timeutils.isotime(end_time)
    if region_id:
        return str("%s-%s-%s-%s" % (project_id, region_id, start_time, end_time))
    else:
        return str("%s-%s-%s" % (project_id, start_time, end_time))
Ejemplo n.º 2
0
def _make_cache_key(region_id, project_id, start_time, end_time):
    start_time = timeutils.isotime(start_time)
    end_time = timeutils.isotime(end_time)
    if region_id:
        return str("%s-%s-%s-%s" % (project_id, region_id, start_time, end_time))
    else:
        return str("%s-%s-%s" % (project_id, start_time, end_time))
Ejemplo n.º 3
0
def _make_cache_key(region_id, user_id, project_id, start_time, end_time):
    start_time = timeutils.isotime(start_time)
    end_time = timeutils.isotime(end_time)
    if project_id:
        key = "%s-%s-%s-%s" % (project_id, region_id, start_time, end_time)
    elif user_id:
        key = "%s-%s-%s-%s" % (user_id, region_id, start_time, end_time)
    # NOTE(suo): As python-memcached only accepts byte string as memcache key,
    # not unicode, so this key should be encoded using str()
    return str(key)
Ejemplo n.º 4
0
def _make_cache_key(region_id, user_id, project_id, start_time, end_time):
    start_time = timeutils.isotime(start_time)
    end_time = timeutils.isotime(end_time)
    if project_id:
        key = "%s-%s-%s-%s" % (project_id, region_id, start_time, end_time)
    elif user_id:
        key = "%s-%s-%s-%s" % (user_id, region_id, start_time, end_time)
    # NOTE(suo): As python-memcached only accepts byte string as memcache key,
    # not unicode, so this key should be encoded using str()
    return str(key)
Ejemplo n.º 5
0
    def renew(self, data):
        """renew the order manually

        1. Caculate price needed to deduct
        2. Change cron_time and deduct account in the same session
        3. Change cron job in master
        """
        self._validate_renew(data.as_dict())
        conn = pecan.request.db_conn
        try:
            order, renew_price = conn.renew_order(request.context,
                                                  self._id, data)
            self.master_api.change_monthly_job_time(
                request.context, self._id,
                timeutils.isotime(order.cron_time),
                clear_date_jobs=True)
        except exception.OrderNotFound as e:
            LOG.warn(e)
            raise
        except exception.OrderRenewError as e:
            LOG.warn(e)
            raise
        except exception.NotSufficientFund as e:
            LOG.warn(e)
            raise
        except Exception:
            msg = "Fail to renew the order %s" % self._id
            LOG.exception(msg)
            raise exception.DBError(reason=msg)
        result = models.Order.from_db_model(order)
        result.renew_price = str(renew_price)
        return result
Ejemplo n.º 6
0
    def renew(self, data):
        """renew the order manually

        1. Caculate price needed to deduct
        2. Change cron_time and deduct account in the same session
        3. Change cron job in master
        """
        self._validate_renew(data.as_dict())
        conn = pecan.request.db_conn
        try:
            order, renew_price = conn.renew_order(request.context, self._id,
                                                  data)
            self.master_api.change_monthly_job_time(request.context,
                                                    self._id,
                                                    timeutils.isotime(
                                                        order.cron_time),
                                                    clear_date_jobs=True)
        except exception.OrderNotFound as e:
            LOG.warn(e)
            raise
        except exception.OrderRenewError as e:
            LOG.warn(e)
            raise
        except exception.NotSufficientFund as e:
            LOG.warn(e)
            raise
        except Exception:
            msg = "Fail to renew the order %s" % self._id
            LOG.exception(msg)
            raise exception.DBError(reason=msg)
        result = models.Order.from_db_model(order)
        result.renew_price = str(renew_price)
        return result
Ejemplo n.º 7
0
 def post(self, data):
     conn = pecan.request.db_conn
     try:
         order = conn.create_order(request.context, **data.as_dict())
         if order.unit in ['month', 'year']:
             self.master_api.create_monthly_job(
                 request.context, order.order_id,
                 timeutils.isotime(order.cron_time))
     except Exception as e:
         LOG.exception('Fail to create order: %s, for reason %s' %
                       (data.as_dict(), e))
Ejemplo n.º 8
0
 def post(self, data):
     conn = pecan.request.db_conn
     try:
         order = conn.create_order(request.context, **data.as_dict())
         if order.unit in ['month', 'year']:
             self.master_api.create_monthly_job(
                 request.context, order.order_id,
                 timeutils.isotime(order.cron_time))
         else:
             action_time = \
                 gringutils.format_datetime(
                     timeutils.strtime(timeutils.utcnow()))
             remarks = '%s Has Been Created.' % order.type.capitalize()
             self.master_api.resource_created(request.context,
                                              order.order_id, action_time,
                                              remarks)
     except Exception as e:
         LOG.exception('Fail to create order: %s, for reason %s' %
                       (data.as_dict(), e))
Ejemplo n.º 9
0
 def post(self, data):
     conn = pecan.request.db_conn
     try:
         order = conn.create_order(request.context, **data.as_dict())
         if order.unit in ['month', 'year']:
             self.master_api.create_monthly_job(
                 request.context, order.order_id,
                 timeutils.isotime(order.cron_time))
         else:
             action_time = \
                 gringutils.format_datetime(
                     timeutils.strtime(timeutils.utcnow()))
             remarks = '%s Has Been Created.' % order.type.capitalize()
             self.master_api.resource_created(request.context,
                                              order.order_id,
                                              action_time,
                                              remarks)
     except Exception as e:
         LOG.exception('Fail to create order: %s, for reason %s' %
                       (data.as_dict(), e))
Ejemplo n.º 10
0
 def __init__(self, **kw):
     for k, v in kw.items():
         if isinstance(v, datetime.datetime):
             kw[k] = timeutils.isotime(at=v)
     super(APIBase, self).__init__(**kw)
Ejemplo n.º 11
0
 def __init__(self, **kw):
     for k, v in kw.items():
         if isinstance(v, datetime.datetime):
             kw[k] = timeutils.isotime(at=v)
     super(APIBase, self).__init__(**kw)