func/overlord/client.py | 145 +++++++++++++++++++----------------- func/overlord/group/conf_backend.py | 2 func/overlord/groups.py | 14 +-- 3 files changed, 85 insertions(+), 76 deletions(-) New commits: commit da53ac8c6ff803965041d07bca69002e1f827aa1 Author: Seth Vidal <skvidal@xxxxxxxxxxxxxxxxx> Date: Wed Jul 28 17:52:55 2010 -0400 make sure we're calling the _get_hosts_for_spec that we're given by the minions class diff --git a/func/overlord/groups.py b/func/overlord/groups.py index 2b9fd1a..be769d1 100644 --- a/func/overlord/groups.py +++ b/func/overlord/groups.py @@ -94,9 +94,9 @@ class Groups(object): @param exclude_string :Glob string to be excluded you can add something like "www*" easy and fast """ - hoststring = self.get_hosts_spec(hoststring) + hoststring = self.get_hosts_for_spec(hoststring) if exclude_string : - e_s = self.get_hosts_spec(exclude_string) + e_s = self.get_hosts_for_spec(exclude_string) hoststring = hoststring.difference(e_s) #add them to backend @@ -205,12 +205,12 @@ class Groups(object): #we seek for @group:ww* thing here if group_glob.find(":")!=-1: group_str,host_str = group_glob.split(":") - hosts = self.get_hosts_spec(host_str) + hosts = self.get_hosts_for_spec(host_str) #print "The hosts are ",hosts include_host=include_host.union(set(self.get_hosts(pattern=hosts,group=group_str,exact=True))) else: - include_host=include_host.union(set(self.get_hosts(group=group_glob))) - #print "The include host is like ",include_host + for host_str in self.get_hosts(group=group_glob): + include_host = include_host.union(set(self.get_hosts_for_spec(host_str))) return include_host @@ -288,9 +288,9 @@ class Groups(object): def remove_host_glob(self,group_name,host_str,exclude_string=None): copy_host_str = host_str - host_str = self.get_hosts_spec(host_str) + host_str = self.get_hosts_for_spec(host_str) if exclude_string: - e_s = self.get_hosts_spec(exclude_string) + e_s = self.get_hosts_for_spec(exclude_string) host_str = host_str.difference(e_s) #remove the list completely commit ae785412f8b0932c73624d13e6677bde23f13853 Author: Seth Vidal <skvidal@xxxxxxxxxxxxxxxxx> Date: Wed Jul 28 17:52:10 2010 -0400 cache the hostlist and the revoked serial numbers for puppetminions - this makes runs involving groups not take a year and a day diff --git a/func/overlord/client.py b/func/overlord/client.py index b3976f7..d06bff8 100644 --- a/func/overlord/client.py +++ b/func/overlord/client.py @@ -123,7 +123,7 @@ class Minions(object): return self.new_hosts def _get_group_hosts(self,spec): - return self.group_class.get_hosts_by_group_glob(spec) + return self.group_class.get_hosts_glob(spec) def _get_hosts_for_specs(self,seperate_gloobs): """ @@ -272,6 +272,10 @@ class PuppetMinions(Minions): noglobs=None, verbose=None, just_fqdns=False, groups_backend="conf", delegate=False, minionmap={},exclude_spec=None,**kwargs): + # local host_inv cache + self._host_inv = {} + self._revoked_serials = [] + Minions.__init__(self, spec, port=port, noglobs=noglobs, verbose=verbose, just_fqdns=just_fqdns, groups_backend=groups_backend, delegate=delegate, minionmap=minionmap, @@ -284,80 +288,85 @@ class PuppetMinions(Minions): #these will be returned tmp_certs = set() tmp_hosts = set() - - # get all hosts - if os.access(self.overlord_config.puppet_inventory, os.R_OK): - fo = open(self.overlord_config.puppet_inventory, 'r') - host_inv = {} - time_format = '%Y-%m-%dT%H:%M:%S%Z' - now = time.time() - for line in fo.readlines(): - if re.match('\s*(#|$)', line): - continue - try: - (serial, before, after, cn) = line.split() - except ValueError: - continue - before = time.strftime('%s', time.strptime(before, time_format)) - if now < int(before): - continue - after = time.strftime('%s', time.strptime(after, time_format)) - if now > int(after): - continue - - hn = cn.replace('/CN=','') - hn = hn.replace('\n','') - if hn in host_inv: - if host_inv[hn] > serial: + if not self._host_inv: + # get all hosts + if os.access(self.overlord_config.puppet_inventory, os.R_OK): + fo = open(self.overlord_config.puppet_inventory, 'r') + host_inv = {} + time_format = '%Y-%m-%dT%H:%M:%S%Z' + now = time.time() + for line in fo.readlines(): + if re.match('\s*(#|$)', line): continue - host_inv[hn] = serial - fo.close() - - # revoked certs - revoked_serials = self._return_revoked_serials(self.overlord_config.puppet_crl) - for hostname in host_inv.keys(): - if int(host_inv[hostname], 16) in revoked_serials: - continue - pempath = '%s/%s.pem' % (self.overlord_config.puppet_signed_certs_dir, hostname) - if not os.path.exists(pempath): - continue - matched_gloob = False - if fnmatch.fnmatch(hostname, each_gloob): - matched_gloob = True - tmp_hosts.add(hostname) + try: + (serial, before, after, cn) = line.split() + except ValueError: + continue + before = time.strftime('%s', time.strptime(before, time_format)) + if now < int(before): + continue + after = time.strftime('%s', time.strptime(after, time_format)) + if now > int(after): + continue + + hn = cn.replace('/CN=','') + hn = hn.replace('\n','') + if hn in host_inv: + if host_inv[hn] > serial: + continue + host_inv[hn] = serial + fo.close() + self._host_inv = host_inv # store ours - # if we can't match this gloob and the gloob is not REALLY a glob - # let the gloob be the hostname we try to connect to. - if not matched_gloob and not func_utils.re_glob(each_gloob): - tmp_hosts.add(each_gloob) - # don't return certs path - just hosts + # revoked certs + self._return_revoked_serials(self.overlord_config.puppet_crl) + for hostname in self._host_inv.keys(): + if int(self._host_inv[hostname], 16) in self._revoked_serials: + continue + pempath = '%s/%s.pem' % (self.overlord_config.puppet_signed_certs_dir, hostname) + if not os.path.exists(pempath): + continue + matched_gloob = False + if fnmatch.fnmatch(hostname, each_gloob): + matched_gloob = True + tmp_hosts.add(hostname) + + # if we can't match this gloob and the gloob is not REALLY a glob + # let the gloob be the hostname we try to connect to. + if not matched_gloob and not func_utils.re_glob(each_gloob): + tmp_hosts.add(each_gloob) + # don't return certs path - just hosts return tmp_hosts,tmp_certs def _return_revoked_serials(self, crlfile): - try: - serials = [] - crltext = open(crlfile, 'r').read() - from OpenSSL import crypto - crl = crypto.load_crl(crypto.FILETYPE_PEM, crltext) - revs = crl.get_revoked() - for revoked in revs: - serials.append(str(revoked.get_serial())) - return serials - except (ImportError, AttributeError), e: - call = '/usr/bin/openssl crl -text -noout -in %s' % crlfile - call = shlex.split(call) - serials = [] - (res,err) = subprocess.Popen(call, stdout=subprocess.PIPE).communicate() - for line in res.split('\n'): - if line.find('Serial Number:') == -1: - continue - (crap, serial) = line.split(':') - serial = serial.strip() - serial = int(serial, 16) - serials.append(serial) - return serials + if not self._revoked_serials: + serials = [] + try: + crltext = open(crlfile, 'r').read() + from OpenSSL import crypto + crl = crypto.load_crl(crypto.FILETYPE_PEM, crltext) + revs = crl.get_revoked() + for revoked in revs: + serials.append(str(revoked.get_serial())) + + except (ImportError, AttributeError), e: + call = '/usr/bin/openssl crl -text -noout -in %s' % crlfile + call = shlex.split(call) + serials = [] + (res,err) = subprocess.Popen(call, stdout=subprocess.PIPE).communicate() + for line in res.split('\n'): + if line.find('Serial Number:') == -1: + continue + (crap, serial) = line.split(':') + serial = serial.strip() + serial = int(serial, 16) + serials.append(serial) + + self._revoked_serials = serials + + # does the hostnamegoo actually expand to anything? commit 037184ecd4b9a27fa2c77acb6a052acaacbc747e Author: Seth Vidal <skvidal@xxxxxxxxxxxxxxxxx> Date: Wed Jul 28 17:51:53 2010 -0400 make sure groups allow ; and ,'s for multiple entries diff --git a/func/overlord/group/conf_backend.py b/func/overlord/group/conf_backend.py index d6540fc..04968d8 100644 --- a/func/overlord/group/conf_backend.py +++ b/func/overlord/group/conf_backend.py @@ -1,4 +1,3 @@ -## func command line interface & client lib ## ## Copyright 2007,2008 Red Hat, Inc ## Adrian Likins <alikins@xxxxxxxxxx> @@ -59,6 +58,7 @@ class ConfBackend(BaseBackend): for option in options: if option == "host": hosts = self.cp.get(section,option) + hosts = hosts.replace(';',',') hosts = hosts.split(",") for h in hosts: self.add_host_to_group(section,h,save=False) _______________________________________________ Func-list mailing list Func-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/func-list