コード例 #1
0
ファイル: glance.py プロジェクト: bopopescu/nova-week
    def call(self, context, version, method, *args, **kwargs):
        """Call a glance client method.  If we get a connection error,
        retry the request according to CONF.glance_num_retries.
        """
        retry_excs = (glanceclient.exc.ServiceUnavailable,
                      glanceclient.exc.InvalidEndpoint,
                      glanceclient.exc.CommunicationError)
        num_attempts = 1 + CONF.glance_num_retries

        for attempt in xrange(1, num_attempts + 1):
            client = self.client or self._create_onetime_client(
                context, version)
            try:
                return getattr(client.images, method)(*args, **kwargs)
            except retry_excs as e:
                host = self.host
                port = self.port
                extra = "retrying"
                error_msg = (_("Error contacting glance server "
                               "'%(host)s:%(port)s' for '%(method)s', "
                               "%(extra)s.") % {
                                   'host': host,
                                   'port': port,
                                   'method': method,
                                   'extra': extra
                               })
                if attempt == num_attempts:
                    extra = 'done trying'
                    LOG.exception(error_msg)
                    raise exception.GlanceConnectionFailed(host=host,
                                                           port=port,
                                                           reason=str(e))
                LOG.exception(error_msg)
                time.sleep(1)
コード例 #2
0
    def call(self, context, version, method, *args, **kwargs):
        """Call a glance client method.  If we get a connection error,
        retry the request according to CONF.glance.num_retries.
        """
        retry_excs = (glanceclient.exc.ServiceUnavailable,
                glanceclient.exc.InvalidEndpoint,
                glanceclient.exc.CommunicationError)
        retries = CONF.glance.num_retries
        if retries < 0:
            LOG.warning(_LW("Treating negative config value (%(retries)s) for "
                            "'glance.num_retries' as 0."),
                        {'retries': retries})
            retries = 0
        num_attempts = retries + 1

        for attempt in range(1, num_attempts + 1):
            client = self.client or self._create_onetime_client(context,
                                                                version)
            try:
                return getattr(client.images, method)(*args, **kwargs)
            except retry_excs as e:
                if attempt < num_attempts:
                    extra = "retrying"
                else:
                    extra = 'done trying'

                LOG.exception(_LE("Error contacting glance server "
                                  "'%(server)s' for '%(method)s', "
                                  "%(extra)s."),
                              {'server': self.api_server,
                               'method': method, 'extra': extra})
                if attempt == num_attempts:
                    raise exception.GlanceConnectionFailed(
                        server=str(self.api_server), reason=six.text_type(e))
                time.sleep(1)
コード例 #3
0
ファイル: glance.py プロジェクト: panguan737/nova
    def call(self,
             context,
             version,
             method,
             controller=None,
             args=None,
             kwargs=None):
        """Call a glance client method.  If we get a connection error,
        retry the request according to CONF.glance.num_retries.

        :param context: RequestContext to use
        :param version: Numeric version of the *Glance API* to use
        :param method: string method name to execute on the glanceclient
        :param controller: optional string name of the client controller to
                           use. Default (None) is to use the 'images'
                           controller
        :param args: optional iterable of arguments to pass to the
                     glanceclient method, splatted as positional args
        :param kwargs: optional dict of arguments to pass to the glanceclient,
                       splatted into named arguments
        """
        args = args or []
        kwargs = kwargs or {}
        retry_excs = (glanceclient.exc.ServiceUnavailable,
                      glanceclient.exc.InvalidEndpoint,
                      glanceclient.exc.CommunicationError)
        num_attempts = 1 + CONF.glance.num_retries
        controller_name = controller or 'images'

        for attempt in range(1, num_attempts + 1):
            client = self.client or self._create_onetime_client(
                context, version)
            try:
                controller = getattr(client, controller_name)
                result = getattr(controller, method)(*args, **kwargs)
                if inspect.isgenerator(result):
                    # Convert generator results to a list, so that we can
                    # catch any potential exceptions now and retry the call.
                    return list(result)
                return result
            except retry_excs as e:
                if attempt < num_attempts:
                    extra = "retrying"
                else:
                    extra = 'done trying'

                LOG.exception(
                    "Error contacting glance server "
                    "'%(server)s' for '%(method)s', "
                    "%(extra)s.", {
                        'server': self.api_server,
                        'method': method,
                        'extra': extra
                    })
                if attempt == num_attempts:
                    raise exception.GlanceConnectionFailed(
                        server=str(self.api_server), reason=six.text_type(e))
                time.sleep(1)
コード例 #4
0
ファイル: glance.py プロジェクト: justinsb/nova
    def _call_retry(self, context, name, *args, **kwargs):
        """Retry call to glance server if there is a connection error.
        Suitable only for idempotent calls."""
        for i in xrange(FLAGS.glance_num_retries + 1):
            client = self._get_client(context)
            try:
                return getattr(client, name)(*args, **kwargs)
            except glance_exception.ClientConnectionError as e:
                LOG.exception(_('Connection error contacting glance'
                                ' server, retrying'))

                time.sleep(1)

        raise exception.GlanceConnectionFailed(
                reason=_('Maximum attempts reached'))
コード例 #5
0
    def call(self, context, version, method, *args, **kwargs):
        """Call a glance client method.  If we get a connection error,
        retry the request according to CONF.glance.num_retries.
        """
        retry_excs = (glanceclient.exc.ServiceUnavailable,
                      glanceclient.exc.InvalidEndpoint,
                      glanceclient.exc.CommunicationError)
        retries = CONF.glance.num_retries
        if retries < 0:
            LOG.warning(
                _LW("Treating negative config value (%(retries)s) for "
                    "'glance.num_retries' as 0."), {'retries': retries})
            retries = 0
        num_attempts = retries + 1

        for attempt in range(1, num_attempts + 1):
            client = self.client or self._create_onetime_client(
                context, version)
            try:
                result = getattr(client.images, method)(*args, **kwargs)
                if inspect.isgenerator(result):
                    # Convert generator results to a list, so that we can
                    # catch any potential exceptions now and retry the call.
                    return list(result)
                return result
            except retry_excs as e:
                host = self.host
                port = self.port

                if attempt < num_attempts:
                    extra = "retrying"
                else:
                    extra = 'done trying'

                LOG.exception(
                    _LE("Error contacting glance server "
                        "'%(host)s:%(port)s' for '%(method)s', "
                        "%(extra)s."), {
                            'host': host,
                            'port': port,
                            'method': method,
                            'extra': extra
                        })
                if attempt == num_attempts:
                    raise exception.GlanceConnectionFailed(
                        host=host, port=port, reason=six.text_type(e))
                time.sleep(1)
コード例 #6
0
    def call(self, context, version, method, *args, **kwargs):
        """Call a glance client method.  If we get a connection error,
        retry the request according to CONF.glance.num_retries.
        """
        retry_excs = (glanceclient.exc.ServiceUnavailable,
                      glanceclient.exc.InvalidEndpoint,
                      glanceclient.exc.CommunicationError)
        num_attempts = 1 + CONF.glance.num_retries

        for attempt in range(1, num_attempts + 1):
            client = self.client or self._create_onetime_client(
                context, version)
            try:
                controller = getattr(client,
                                     kwargs.pop('controller', 'images'))
                result = getattr(controller, method)(*args, **kwargs)
                if inspect.isgenerator(result):
                    # Convert generator results to a list, so that we can
                    # catch any potential exceptions now and retry the call.
                    return list(result)
                return result
            except retry_excs as e:
                if attempt < num_attempts:
                    extra = "retrying"
                else:
                    extra = 'done trying'

                LOG.exception(
                    "Error contacting glance server "
                    "'%(server)s' for '%(method)s', "
                    "%(extra)s.", {
                        'server': self.api_server,
                        'method': method,
                        'extra': extra
                    })
                if attempt == num_attempts:
                    raise exception.GlanceConnectionFailed(
                        server=str(self.api_server), reason=six.text_type(e))
                time.sleep(1)