当前位置: 首页>>代码示例>>Python>>正文


Python _i18n._函数代码示例

本文整理汇总了Python中neutron_lbaas._i18n._函数的典型用法代码示例。如果您正苦于以下问题:Python _函数的具体用法?Python _怎么用?Python _使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _validate_integer

def _validate_integer(data, valid_values=None):
    """This function validates if the data is an integer.

    It checks both number or string provided to validate it's an
    integer and returns a message with the error if it's not

    :param data: The string or number to validate as integer
    :param valid_values: None (for future usage)
    :return: Message if not an integer.
    """

    if valid_values and (data not in valid_values):
        msg = (_("'%(data)s' is not within '%(valid_values)s'") %
               {'data': data, 'valid_values': valid_values})
        return msg

    msg = _("'%s' is not an integer") % data
    try:
        fl_n = float(data)
        int_n = int(data)
    except (ValueError, TypeError, OverflowError):
        LOG.debug(msg)
        return msg
    else:
        # Fail test if non equal or boolean
        if fl_n != int_n or isinstance(data, bool):
            LOG.debug(msg)
            return msg
开发者ID:F5Networks,项目名称:neutron-lbaas,代码行数:28,代码来源:loadbalancerv2.py

示例2: _wait_for_load_balancer_status

 def _wait_for_load_balancer_status(cls, load_balancer_id,
                                    provisioning_status='ACTIVE',
                                    operating_status='ONLINE',
                                    delete=False):
     interval_time = 1
     timeout = 600
     end_time = time.time() + timeout
     lb = {}
     # When running with no-op drivers there is no actual health to
     # observe, so disable operating_status checks when running no-op.
     if CONF.lbaas.test_with_noop:
         operating_status = None
     while time.time() < end_time:
         try:
             lb = cls.load_balancers_client.get_load_balancer(
                 load_balancer_id)
             if not lb:
                     # loadbalancer not found
                 if delete:
                     break
                 else:
                     raise Exception(
                         _("loadbalancer {lb_id} not"
                           " found").format(
                               lb_id=load_balancer_id))
             if lb.get('provisioning_status') == provisioning_status:
                 if operating_status is None:
                     break
                 elif lb.get('operating_status') == operating_status:
                     break
             time.sleep(interval_time)
         except exceptions.NotFound:
             # if wait is for delete operation do break
             if delete:
                 break
             else:
                 # raise original exception
                 raise
     else:
         if delete:
             raise exceptions.TimeoutException(
                 _("Waited for load balancer {lb_id} to be deleted for "
                   "{timeout} seconds but can still observe that it "
                   "exists.").format(
                       lb_id=load_balancer_id,
                       timeout=timeout))
         else:
             raise exceptions.TimeoutException(
                 _("Wait for load balancer ran for {timeout} seconds and "
                   "did not observe {lb_id} reach {provisioning_status} "
                   "provisioning status and {operating_status} "
                   "operating status.").format(
                       timeout=timeout,
                       lb_id=load_balancer_id,
                       provisioning_status=provisioning_status,
                       operating_status=operating_status))
     return lb
开发者ID:openstack,项目名称:neutron-lbaas,代码行数:57,代码来源:base.py

示例3: _wait_for_load_balancer_status

 def _wait_for_load_balancer_status(
     cls, load_balancer_id, provisioning_status="ACTIVE", operating_status="ONLINE", delete=False
 ):
     interval_time = 1
     timeout = 600
     end_time = time.time() + timeout
     lb = {}
     while time.time() < end_time:
         try:
             lb = cls.load_balancers_client.get_load_balancer(load_balancer_id)
             if not lb:
                 # loadbalancer not found
                 if delete:
                     break
                 else:
                     raise Exception(_("loadbalancer {lb_id} not" " found").format(lb_id=load_balancer_id))
             if (
                 lb.get("provisioning_status") == provisioning_status
                 and lb.get("operating_status") == operating_status
             ):
                 break
             time.sleep(interval_time)
         except exceptions.NotFound:
             # if wait is for delete operation do break
             if delete:
                 break
             else:
                 # raise original exception
                 raise
     else:
         if delete:
             raise exceptions.TimeoutException(
                 _(
                     "Waited for load balancer {lb_id} to be deleted for "
                     "{timeout} seconds but can still observe that it "
                     "exists."
                 ).format(lb_id=load_balancer_id, timeout=timeout)
             )
         else:
             raise exceptions.TimeoutException(
                 _(
                     "Wait for load balancer ran for {timeout} seconds and "
                     "did not observe {lb_id} reach {provisioning_status} "
                     "provisioning status and {operating_status} "
                     "operating status."
                 ).format(
                     timeout=timeout,
                     lb_id=load_balancer_id,
                     provisioning_status=provisioning_status,
                     operating_status=operating_status,
                 )
             )
     return lb
开发者ID:F5Networks,项目名称:neutron-lbaas,代码行数:53,代码来源:base.py

示例4: _check_session_persistence_info

    def _check_session_persistence_info(self, info):
        """Performs sanity check on session persistence info.

        :param info: Session persistence info
        """
        if info['type'] == 'APP_COOKIE':
            if not info.get('cookie_name'):
                raise ValueError(_("'cookie_name' should be specified for this"
                                   " type of session persistence."))
        else:
            if 'cookie_name' in info:
                raise ValueError(_("'cookie_name' is not allowed for this type"
                                   " of session persistence"))
开发者ID:Stef1010,项目名称:neutron-lbaas,代码行数:13,代码来源:loadbalancer_db.py

示例5: get_session

def get_session():
    """Initializes a Keystone session.

    :returns: a Keystone Session object
    :raises Exception: if the session cannot be established
    """
    global _SESSION
    if not _SESSION:

        auth_url = cfg.CONF.service_auth.auth_url
        kwargs = {'auth_url': auth_url,
                  'username': cfg.CONF.service_auth.admin_user,
                  'password': cfg.CONF.service_auth.admin_password}

        if cfg.CONF.service_auth.auth_version == '2':
            client = v2_client
            kwargs['tenant_name'] = cfg.CONF.service_auth.admin_tenant_name
        elif cfg.CONF.service_auth.auth_version == '3':
            client = v3_client
            kwargs['project_name'] = cfg.CONF.service_auth.admin_tenant_name
            kwargs['user_domain_name'] = (cfg.CONF.service_auth.
                                          admin_user_domain)
            kwargs['project_domain_name'] = (cfg.CONF.service_auth.
                                             admin_project_domain)
        else:
            raise Exception(_('Unknown keystone version!'))

        try:
            kc = client.Password(**kwargs)
            _SESSION = session.Session(auth=kc)
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.exception(_LE("Error creating Keystone session."))

    return _SESSION
开发者ID:F5Networks,项目名称:neutron-lbaas,代码行数:35,代码来源:keystone.py

示例6: update_status

 def update_status(self, context, obj_type, obj_id,
                   provisioning_status=None, operating_status=None):
     if not provisioning_status and not operating_status:
         LOG.warning('update_status for %(obj_type)s %(obj_id)s called '
                     'without specifying provisioning_status or '
                     'operating_status' % {'obj_type': obj_type,
                                           'obj_id': obj_id})
         return
     model_mapping = {
         'loadbalancer': db_models.LoadBalancer,
         'pool': db_models.PoolV2,
         'listener': db_models.Listener,
         'member': db_models.MemberV2,
         'healthmonitor': db_models.HealthMonitorV2
     }
     if obj_type not in model_mapping:
         raise n_exc.Invalid(_('Unknown object type: %s') % obj_type)
     try:
         self.plugin.db.update_status(
             context, model_mapping[obj_type], obj_id,
             provisioning_status=provisioning_status,
             operating_status=operating_status)
     except n_exc.NotFound:
         # update_status may come from agent on an object which was
         # already deleted from db with other request
         LOG.warning('Cannot update status: %(obj_type)s %(obj_id)s '
                     'not found in the DB, it was probably deleted '
                     'concurrently',
                     {'obj_type': obj_type, 'obj_id': obj_id})
开发者ID:openstack,项目名称:neutron-lbaas,代码行数:29,代码来源:agent_callbacks.py

示例7: _validate_connection_limit

def _validate_connection_limit(data, min_value=lb_const.MIN_CONNECT_VALUE):
    if int(data) < min_value:
        msg = (_("'%(data)s' is not a valid value, "
                 "because it cannot be less than %(min_value)s") %
               {'data': data, 'min_value': min_value})
        LOG.debug(msg)
        return msg
开发者ID:richbrowne,项目名称:neutron-lbaas,代码行数:7,代码来源:loadbalancerv2.py

示例8: run

    def run(self):
        while not self.stoprequest.isSet():
            try:
                oper = self.queue.get(timeout=1)

                # Get the current queue size (N) and set the counter with it.
                # Handle N operations with no intermission.
                # Once N operations handles, get the size again and repeat.
                if self.opers_to_handle_before_rest <= 0:
                    self.opers_to_handle_before_rest = self.queue.qsize() + 1

                LOG.debug('Operation consumed from the queue: %s', oper)
                # check the status - if oper is done: update the db ,
                # else push the oper again to the queue
                if not self.handle_operation_completion(oper):
                    LOG.debug('Operation %s is not completed yet..', oper)
                    # Not completed - push to the queue again
                    self.queue.put_nowait(oper)

                self.queue.task_done()
                self.opers_to_handle_before_rest -= 1

                # Take one second rest before start handling
                # new operations or operations handled before
                if self.opers_to_handle_before_rest <= 0:
                    time.sleep(1)

            except Queue.Empty:
                continue
            except Exception:
                m = _("Exception was thrown inside OperationCompletionHandler")
                LOG.exception(m)
开发者ID:F5Networks,项目名称:neutron-lbaas,代码行数:32,代码来源:driver.py

示例9: l7policy_rule

    def l7policy_rule(self, l7policy_id, fmt=None, value='value1',
                      type=lb_const.L7_RULE_TYPE_HOST_NAME,
                      compare_type=lb_const.L7_RULE_COMPARE_TYPE_EQUAL_TO,
                      no_delete=False, **kwargs):
        if not fmt:
            fmt = self.fmt
        res = self._create_l7policy_rule(fmt,
                                         l7policy_id=l7policy_id,
                                         type=type,
                                         compare_type=compare_type,
                                         value=value,
                                         **kwargs)
        if res.status_int >= webob.exc.HTTPClientError.code:
            raise webob.exc.HTTPClientError(
                explanation=_("Unexpected error code: %s") % res.status_int
            )

        rule = self.deserialize(fmt or self.fmt, res)
        yield rule
        if not no_delete:
            self.plugin.db.update_status(context.get_admin_context(),
                                         models.L7Rule,
                                         rule['rule']['id'],
                                         constants.ACTIVE)
            del_req = self.new_delete_request(
                'l7policies',
                fmt=fmt,
                id=l7policy_id,
                subresource='rules',
                sub_id=rule['rule']['id'])
            del_res = del_req.get_response(self.ext_api)
            self.assertEqual(del_res.status_int,
                             webob.exc.HTTPNoContent.code)
开发者ID:openstack,项目名称:neutron-lbaas,代码行数:33,代码来源:util.py

示例10: l7policy

    def l7policy(self, listener_id, fmt=None,
                 action=lb_const.L7_POLICY_ACTION_REJECT,
                 no_delete=False, **kwargs):
        if not fmt:
            fmt = self.fmt

        res = self._create_l7policy(fmt,
                                    listener_id=listener_id,
                                    action=action,
                                    **kwargs)
        if res.status_int >= webob.exc.HTTPClientError.code:
            raise webob.exc.HTTPClientError(
                explanation=_("Unexpected error code: %s") % res.status_int
            )

        l7policy = self.deserialize(fmt or self.fmt, res)
        yield l7policy
        if not no_delete:
            self.plugin.db.update_status(context.get_admin_context(),
                                         models.L7Policy,
                                         l7policy['l7policy']['id'],
                                         constants.ACTIVE)
            del_req = self.new_delete_request(
                'l7policies',
                fmt=fmt,
                id=l7policy['l7policy']['id'])
            del_res = del_req.get_response(self.ext_api)
            self.assertEqual(del_res.status_int,
                             webob.exc.HTTPNoContent.code)
开发者ID:openstack,项目名称:neutron-lbaas,代码行数:29,代码来源:util.py

示例11: member

    def member(self, fmt=None, pool_id='pool1id', address='127.0.0.1',
               protocol_port=80, subnet=None, no_delete=False,
               **kwargs):
        if not fmt:
            fmt = self.fmt
        subnet = subnet or self.test_subnet
        with test_db_base_plugin_v2.optional_ctx(
                subnet, self.subnet) as tmp_subnet:

            res = self._create_member(fmt,
                                      pool_id=pool_id,
                                      address=address,
                                      protocol_port=protocol_port,
                                      subnet_id=tmp_subnet['subnet']['id'],
                                      **kwargs)
            if res.status_int >= webob.exc.HTTPClientError.code:
                raise webob.exc.HTTPClientError(
                    explanation=_("Unexpected error code: %s") % res.status_int
                )

            member = self.deserialize(fmt or self.fmt, res)
        yield member
        if not no_delete:
            self._delete('pools', id=pool_id, subresource='members',
                         sub_id=member['member']['id'])
开发者ID:openstack,项目名称:neutron-lbaas,代码行数:25,代码来源:util.py

示例12: pool

    def pool(self, fmt=None, protocol='HTTP', lb_algorithm='ROUND_ROBIN',
             no_delete=False, listener_id=None,
             loadbalancer_id=None, **kwargs):
        if not fmt:
            fmt = self.fmt

        if listener_id and loadbalancer_id:
            res = self._create_pool(fmt,
                                    protocol=protocol,
                                    lb_algorithm=lb_algorithm,
                                    listener_id=listener_id,
                                    loadbalancer_id=loadbalancer_id,
                                    **kwargs)
        elif listener_id:
            res = self._create_pool(fmt,
                                    protocol=protocol,
                                    lb_algorithm=lb_algorithm,
                                    listener_id=listener_id,
                                    **kwargs)
        else:
            res = self._create_pool(fmt,
                                    protocol=protocol,
                                    lb_algorithm=lb_algorithm,
                                    loadbalancer_id=loadbalancer_id,
                                    **kwargs)
        if res.status_int >= webob.exc.HTTPClientError.code:
            raise webob.exc.HTTPClientError(
                explanation=_("Unexpected error code: %s") % res.status_int
            )

        pool = self.deserialize(fmt or self.fmt, res)
        yield pool
        if not no_delete:
            self._delete('pools', pool['pool']['id'])
开发者ID:openstack,项目名称:neutron-lbaas,代码行数:34,代码来源:util.py

示例13: listener

    def listener(self, fmt=None, protocol='HTTP', loadbalancer_id=None,
                 protocol_port=80, default_pool_id=None, no_delete=False,
                 **kwargs):
        if not fmt:
            fmt = self.fmt

        if loadbalancer_id and default_pool_id:
            res = self._create_listener(fmt, protocol, protocol_port,
                                        loadbalancer_id=loadbalancer_id,
                                        default_pool_id=default_pool_id,
                                        **kwargs)
        elif loadbalancer_id:
            res = self._create_listener(fmt, protocol, protocol_port,
                                        loadbalancer_id=loadbalancer_id,
                                        **kwargs)
        else:
            res = self._create_listener(fmt, protocol, protocol_port,
                                        default_pool_id=default_pool_id,
                                        **kwargs)
        if res.status_int >= webob.exc.HTTPClientError.code:
            raise webob.exc.HTTPClientError(
                explanation=_("Unexpected error code: %s") % res.status_int
            )

        listener = self.deserialize(fmt or self.fmt, res)
        yield listener
        if not no_delete:
            self._delete('listeners', listener['listener']['id'])
开发者ID:openstack,项目名称:neutron-lbaas,代码行数:28,代码来源:util.py

示例14: _validate_db_limit

def _validate_db_limit(data, max_value=db_const.DB_INTEGER_MAX_VALUE):
    if int(data) > max_value:
        msg = (_("'%(data)s' is not a valid value, "
                 "because it is more than %(max_value)s") %
               {'data': data, 'max_value': max_value})
        LOG.debug(msg)
        return msg
开发者ID:openstack,项目名称:neutron-lbaas,代码行数:7,代码来源:loadbalancerv2.py

示例15: __init__

 def __init__(self, cert_container):
     if not isinstance(cert_container,
                       barbican_client.containers.CertificateContainer):
         raise TypeError(_(
             "Retrieved Barbican Container is not of the correct type "
             "(certificate)."))
     self._cert_container = cert_container
开发者ID:openstack,项目名称:neutron-lbaas,代码行数:7,代码来源:barbican_cert_manager.py


注:本文中的neutron_lbaas._i18n._函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。