'Call a glance client method.
If we get a connection error,
retry the request according to CONF.glance_num_retries.'

def call(self, context, method, *args, **kwargs):

    version = kwargs.pop('version', self.version)
    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'))
            return getattr(controller, method)(*args, **kwargs)
        except retry_excs as e:
            netloc = self.netloc
            extra = 'retrying'
            error_msg = _("Error    contacting    glance    server    '%(netloc)s'    for    '%(method)s',    %(extra)s.")
            if (attempt == num_attempts):
                extra = 'done    trying'
                LOG.exception(error_msg, {'netloc': netloc, 'method': method, 'extra': extra})
                raise exception.GlanceConnectionFailed(reason=e)
            LOG.exception(error_msg, {'netloc': netloc, 'method': method, 'extra': extra})
            time.sleep(1)
        except glanceclient.exc.HTTPOverLimit as e:
            raise exception.ImageLimitExceeded(e)
