def _get_client(self, public=True, cached=True, client_class=None): client_att = "_client" if public else "_client_private" clt = getattr(self, client_att) if isinstance(clt, exc.NoClientForService): # Already failed raise clt if cached and clt is not None: if client_class and not isinstance(clt, client_class): clt = None else: return clt # Create the client special_class = bool(client_class) if special_class: clt_class = client_class else: clt_class = pyrax.client_class_for_service(self.service) if clt_class is None: noclass = exc.NoClientForService("No client for the '%s' service " "has been registered." % self.service) setattr(self, client_att, noclass) raise noclass url_att = "public_url" if public else "private_url" url = getattr(self, url_att) if not url: nourl = exc.NoEndpointForService("No %s endpoint is available for " "the '%s' service." % (url_att, self.service)) setattr(self, client_att, nourl) raise nourl clt = self._create_client(clt_class, url, public=public, special=special_class) setattr(self, client_att, clt) return clt