def __init__(self, servers, port, path, subtype): # Fixed server list, there is no point to a retry on failed ops. self.should_retry = False # Replace any occurrence of locahost with output of gethostname() # before parsing to match Machine fields of QMF objects later on. host = socket.gethostname() servers = string.replace(servers, "localhost", host) self.servers = host_list(servers, default_scheme="http", default_port=port, default_path=path) try: self.nice = _nice[subtype] except: self.nice = subtype
def _find_server(self, machine, refresh=False): ''' Search the cached server list for machine using _get_host. If the server list is empty or refresh is True, get a new list of endpoints from the Aviary locator object and generate a new server list. ''' # If we already have a list of values then return that list unless # refresh is True self._lock.acquire() try: if self.servers is None or refresh: log.debug("AviaryOperations: refresh server list for %s %s" \ % (self.resource, self.subtype)) try: result = self.locator.get_endpoints(self.resource, self.subtype) except Exception, e: result = _AviaryCommon._pretty_result(e, self.locator.locator_uri) log.debug("AviaryOperations: failed to get endpoints, " \ "exception message '%s'" % result.message) raise result urls = [] # If it's not okay, we just produce an empty sever list if result.status.code == "OK": for r in result.resources: urls.extend(r.location) urls = ",".join(urls) if urls == "": log.info("AviaryOperations: locator returned " \ "no endpoints for %s %s" % (self.resource, self.subtype)) # Parse the urls and produce a dictionary of # sage_URLs by machine self.servers = host_list(urls) scheme, host = _get_host(machine, self.servers)