def __wait_for_connection(self, timeout): lurl = ldapurl.LDAPUrl(self.uri) if lurl.urlscheme == 'ldapi': wait_for_open_socket(lurl.hostport, timeout) else: (host,port) = lurl.hostport.split(':') wait_for_open_ports(host, int(port), timeout)
def __wait_for_open_ports(self, instance_name=""): """ If this is a service we need to wait for do so. """ ports = None if instance_name in base.wellknownports: ports = base.wellknownports[instance_name] else: if self.service_name in base.wellknownports: ports = base.wellknownports[self.service_name] if ports: ipautil.wait_for_open_ports('localhost', ports, api.env.startup_timeout)
def __wait_for_open_ports(self, instance_name=""): """ If this is a service we need to wait for do so. """ ports = None if instance_name in base_services.wellknownports: ports = base_services.wellknownports[instance_name] else: if self.service_name in base_services.wellknownports: ports = base_services.wellknownports[self.service_name] if ports: ipautil.wait_for_open_ports('localhost', ports, api.env.startup_timeout)
def __wait_for_open_ports(self, instance_name=""): """ If this is a service we need to wait for do so. """ ports = None if instance_name in base.wellknownports: ports = base.wellknownports[instance_name] else: elements = self.systemd_name.split("@") if elements[0] in base.wellknownports: ports = base.wellknownports[elements[0]] if ports: ipautil.wait_for_open_ports('localhost', ports, api.env.startup_timeout)
def wait_for_open_ports(self, instance_name=""): """ If this is a service we need to wait for do so. """ ports = None if instance_name in wellknownports: ports = wellknownports[instance_name] else: elements = self.systemd_name.split("@") if elements[0] in wellknownports: ports = wellknownports[elements[0]] if ports: ipautil.wait_for_open_ports('localhost', ports, self.api.env.startup_timeout)
def get_config(dirsrv): base = DN( ("cn", api.env.host), ("cn", "masters"), ("cn", "ipa"), ("cn", "etc"), api.env.basedn, ) srcfilter = LDAPClient.combine_filters( [ LDAPClient.make_filter({"objectClass": "ipaConfigObject"}), LDAPClient.make_filter( {"ipaConfigString": [ENABLED_SERVICE, HIDDEN_SERVICE]}, rules=LDAPClient.MATCH_ANY, ), ], rules=LDAPClient.MATCH_ALL, ) attrs = ["cn", "ipaConfigString"] if not dirsrv.is_running(): raise IpactlError( "Failed to get list of services to probe status:\n" "Directory Server is stopped", 3, ) try: # The start/restart functions already wait for the server to be # started. What we are doing with this wait is really checking to see # if the server is listening at all. lurl = ldapurl.LDAPUrl(api.env.ldap_uri) if lurl.urlscheme == "ldapi": wait_for_open_socket(lurl.hostport, timeout=api.env.startup_timeout) else: (host, port) = lurl.hostport.split(":") wait_for_open_ports(host, [int(port)], timeout=api.env.startup_timeout) con = LDAPClient(api.env.ldap_uri) con.external_bind() res = con.get_entries( base, filter=srcfilter, attrs_list=attrs, scope=con.SCOPE_SUBTREE, time_limit=10, ) except errors.NetworkError: # LSB status code 3: program is not running raise IpactlError( "Failed to get list of services to probe status:\n" "Directory Server is stopped", 3, ) except errors.NotFound: masters_list = [] dn = DN(("cn", "masters"), ("cn", "ipa"), ("cn", "etc"), api.env.basedn) attrs = ["cn"] try: entries = con.get_entries(dn, con.SCOPE_ONELEVEL, attrs_list=attrs) except Exception as e: masters_list.append("No master found because of error: %s" % str(e)) else: for master_entry in entries: masters_list.append(master_entry.single_value["cn"]) masters = "\n".join(masters_list) raise IpactlError( "Failed to get list of services to probe status!\n" "Configured hostname '%s' does not match any master server in " "LDAP:\n%s" % (api.env.host, masters)) except Exception as e: raise IpactlError( "Unknown error when retrieving list of services from LDAP: %s" % str(e)) svc_list = [] for entry in res: name = entry.single_value["cn"] for p in entry["ipaConfigString"]: if p.startswith("startOrder "): try: order = int(p.split()[1]) except ValueError: raise IpactlError("Expected order as integer in: %s:%s" % (name, p)) svc_list.append([order, name]) ordered_list = [] for order, svc in sorted(svc_list): if svc in service.SERVICE_LIST: ordered_list.append(service.SERVICE_LIST[svc].systemd_name) return deduplicate(ordered_list)