def find_server(some_service): if service == 'apache2': return self.cluster.get_random_controller() server = None for cluster_host in self.cluster.hosts: if cluster_host.hostname.startswith('prx'): continue try: res = cluster_host.os.transport.exec_sync( 'pgrep {service}'.format(service=some_service)) except Exception: continue if res[0] == 0: server = cluster_host break if server is None: raise custom_exceptions.NoValidHost('') return server
def get_by_hostname(self, hostname): for host in self.hosts: if hostname in host.hostname or host.hostname == hostname: return host raise exceptions.NoValidHost( condition="hostname == {0}".format(hostname))
def get_by_address(self, address): for host in self.hosts: if host.address == address: return host return exceptions.NoValidHost( condition="address == {0}".format(address))