def get_client(self, service, region, public=True, cached=True, client_class=None): """ Returns the client object for the specified service and region. By default the public endpoint is used. If you wish to work with a services internal endpoints, specify `public=False`. By default, if a client has already been created for the given service, region, and public values, that will be returned. To force a new client to be created, pass 'cached=False'. """ if not self.authenticated: raise exc.NotAuthenticated("You must authenticate before trying " "to create clients.") clt = ep = None mapped_service = self.service_mapping.get(service) or service svc = self.services.get(mapped_service) if svc: ep = svc.endpoints.get(region) if ep: clt = ep._get_client(public=public, cached=cached, client_class=client_class) if not clt: raise exc.NoSuchClient("There is no client available for the " "service '%s' in the region '%s'." % (service, region)) return clt
def __getattr__(self, att): """ Magic to allow for specification of client by region/service or by service/region. If a service is specified, this should return an object whose endpoints contain keys for each available region for that service. If a region is specified, an object with keys for each service available in that region should be returned. """ if not self.authenticated: raise exc.NotAuthenticated("Authentication required before " "accessing the context.") # First see if it's a service att = self.service_mapping.get(att) or att svc = self.services.get(att) if svc is not None: return svc.endpoints # Either invalid service, or a region ret = utils.DotDict([(stype, svc.endpoints.get(att)) for stype, svc in list(self.services.items()) if svc.endpoints.get(att) is not None]) ret._att_mapper.update(self.service_mapping) if ret: return ret # Invalid attribute raise AttributeError("No such attribute '%s'." % att)