summaryrefslogtreecommitdiffstats
path: root/func/overlord
diff options
context:
space:
mode:
authorAdrian Likins <alikins@grimlock.devel.redhat.com>2008-01-23 15:49:12 -0500
committerAdrian Likins <alikins@grimlock.devel.redhat.com>2008-01-23 15:49:12 -0500
commita712f2fb93526f5df83231748b65a102feb0bf9d (patch)
treefef6882801f0a6f1bddfe0fcfe0e67bfdf8dd428 /func/overlord
parentbf8fcc5ebd930a241ce56216e7e610d456be6a69 (diff)
downloadthird_party-func-a712f2fb93526f5df83231748b65a102feb0bf9d.tar.gz
third_party-func-a712f2fb93526f5df83231748b65a102feb0bf9d.tar.xz
third_party-func-a712f2fb93526f5df83231748b65a102feb0bf9d.zip
first pass at allowing "groups" to be specified.
Currently a ini style file in /etc/func/groups and they can be specified on the commandline as "@group"
Diffstat (limited to 'func/overlord')
-rwxr-xr-xfunc/overlord/client.py26
-rw-r--r--func/overlord/groups.py95
2 files changed, 119 insertions, 2 deletions
diff --git a/func/overlord/client.py b/func/overlord/client.py
index 60b5c24..c5358bb 100755
--- a/func/overlord/client.py
+++ b/func/overlord/client.py
@@ -23,8 +23,10 @@ import sslclient
import command
import forkbomb
+import groups
import jobthing
+
# ===================================
# defaults
# TO DO: some of this may want to come from config later
@@ -68,6 +70,11 @@ def expand_servers(spec, port=51234, noglobs=None, verbose=None, just_fqdns=Fals
Given a regex/blob of servers, expand to a list
of server ids.
"""
+
+
+ # FIXME: we need to refactor expand_servers, it seems to do
+ # weird things, reload the config and groups config everytime it's
+ # called for one, which may or may not be bad... -akl
config = read_config(CONFIG_FILE, CMConfig)
if noglobs:
@@ -76,9 +83,23 @@ def expand_servers(spec, port=51234, noglobs=None, verbose=None, just_fqdns=Fals
else:
return spec
+ group_class = groups.Groups()
+ group_dict = group_class.get_groups()
+
all_hosts = []
all_certs = []
seperate_gloobs = spec.split(";")
+ new_hosts = []
+
+ # we notate groups with @foo annotation, so look for that in the hostnamegoo
+ for each_gloob in seperate_gloobs:
+ if each_gloob[0] == '@':
+ if group_dict.has_key(each_gloob[1:]):
+ new_hosts = new_hosts + group_dict[each_gloob[1:]]
+ else:
+ print "group %s not defined" % each_gloob
+
+ seperate_gloobs = seperate_gloobs + new_hosts
for each_gloob in seperate_gloobs:
actual_gloob = "%s/%s.cert" % (config.certroot, each_gloob)
certs = glob.glob(actual_gloob)
@@ -235,8 +256,9 @@ class Client(object):
else:
# globbing is not being used, but still need to make sure
# URI is well formed.
- expanded = expand_servers(self.server_spec, port=self.port, noglobs=True, verbose=self.verbose)[0]
- results = process_server(0, 0, expanded)
+ results = process_server(0, 0, self.servers)
+ #expanded = expand_servers(self.server_spec, port=self.port, noglobs=True, verbose=self.verbose)[0]
+# results = process_server(0, 0, expanded)
return results
diff --git a/func/overlord/groups.py b/func/overlord/groups.py
new file mode 100644
index 0000000..8eaf28e
--- /dev/null
+++ b/func/overlord/groups.py
@@ -0,0 +1,95 @@
+#!/usr/bin/python
+
+## func command line interface & client lib
+##
+## Copyright 2007,2008 Red Hat, Inc
+## Adrian Likins <alikins@redhat.com>
+## +AUTHORS
+##
+## This software may be freely redistributed under the terms of the GNU
+## general public license.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+##
+
+
+# this module lets you define groups of systems to work with from the
+# commandline. It uses an "ini" style config parser like:
+
+#[groupname]
+#host = foobar, baz, blip
+#subgroup = blippy
+
+
+import ConfigParser
+import os
+
+
+class Groups(object):
+
+ def __init__(self, filename="/etc/func/groups"):
+ self.filename = filename
+ self.group_names = {}
+ self.groups = {}
+ self.__parse()
+
+ def __parse(self):
+
+ self.cp = ConfigParser.SafeConfigParser()
+ self.cp.read(self.filename)
+
+ for section in self.cp.sections():
+ self.add_group(section)
+ options = self.cp.options(section)
+ for option in options:
+ if option == "host":
+ self.add_hosts_to_group(section, self.cp.get(section, option))
+ if option == "subgroup":
+ pass
+
+
+ def show(self):
+ print self.cp.sections()
+ print self.groups
+
+ def add_group(self, group):
+ pass
+
+ def __parse_hoststrings(self, hoststring):
+ hosts = []
+ bits = hoststring.split(';')
+ for bit in bits:
+ blip = bit.strip().split(' ')
+ for host in blip:
+ if host not in hosts:
+ hosts.append(host.strip())
+
+ return hosts
+
+ def add_hosts_to_group(self, group, hoststring):
+ hosts = self.__parse_hoststrings(hoststring)
+ for host in hosts:
+ self.add_host_to_group(group, host)
+
+
+
+ def add_host_to_group(self, group, host):
+ if not self.groups.has_key(group):
+ self.groups[group] = []
+ self.groups[group].append(host)
+
+ def get_groups(self):
+ return self.groups
+
+
+
+def main():
+ g = Groups("/tmp/testgroups")
+ print g.show()
+
+
+
+if __name__ == "__main__":
+ main()