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

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

    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):
                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)
