diff options
| author | Michael DeHaan <mdehaan@redhat.com> | 2008-01-17 11:55:12 -0500 |
|---|---|---|
| committer | Michael DeHaan <mdehaan@redhat.com> | 2008-01-17 11:55:12 -0500 |
| commit | eb67b305060e9e962d6a90766e8a39ca80065af2 (patch) | |
| tree | e5c0821bdf499de192d31821d0311049444cb2ce /func | |
| parent | 3c11b8cd0d91e0c4cd5aa007eddc330452b3ace7 (diff) | |
| parent | aee6076dd78dfb1b88ab4d369e24fb1bbf710816 (diff) | |
Merge branch 'master' of ssh://git.fedoraproject.org/git/hosted/func
Diffstat (limited to 'func')
| -rw-r--r-- | func/certs.py | 8 | ||||
| -rwxr-xr-x | func/minion/module_loader.py | 16 | ||||
| -rw-r--r-- | func/minion/modules/command.py | 16 | ||||
| -rw-r--r-- | func/minion/modules/copyfile.py | 22 | ||||
| -rw-r--r-- | func/minion/modules/filetracker.py | 23 | ||||
| -rw-r--r-- | func/minion/modules/func_module.py | 27 | ||||
| -rw-r--r-- | func/minion/modules/hardware.py | 16 | ||||
| -rw-r--r-- | func/minion/modules/mount.py | 18 | ||||
| -rw-r--r-- | func/minion/modules/nagios-check.py | 16 | ||||
| -rw-r--r-- | func/minion/modules/networktest.py | 18 | ||||
| -rw-r--r-- | func/minion/modules/process.py | 17 | ||||
| -rw-r--r-- | func/minion/modules/reboot.py | 16 | ||||
| -rw-r--r-- | func/minion/modules/rpms.py | 14 | ||||
| -rw-r--r-- | func/minion/modules/service.py | 20 | ||||
| -rw-r--r-- | func/minion/modules/smart.py | 15 | ||||
| -rw-r--r-- | func/minion/modules/snmp.py | 16 | ||||
| -rw-r--r-- | func/minion/modules/test.py | 12 | ||||
| -rw-r--r-- | func/minion/modules/virt.py | 59 | ||||
| -rw-r--r-- | func/minion/modules/yumcmd.py | 16 | ||||
| -rwxr-xr-x | func/minion/utils.py | 25 | ||||
| -rwxr-xr-x | func/overlord/client.py | 2 | ||||
| -rw-r--r-- | func/overlord/func_command.py | 15 | ||||
| -rwxr-xr-x | func/overlord/inventory.py | 2 |
23 files changed, 142 insertions, 267 deletions
diff --git a/func/certs.py b/func/certs.py index e454cc4..22af866 100644 --- a/func/certs.py +++ b/func/certs.py @@ -54,9 +54,9 @@ def make_csr(pkey, dest=None, cn=None): req.set_pubkey(pkey) req.sign(pkey, 'md5') if dest: - destfo = open(dest, 'w') - destfo.write(crypto.dump_certificate_request(crypto.FILETYPE_PEM, req)) - destfo.close() + destfd = os.open(dest, os.O_RDWR|os.O_CREAT, 0644) + os.write(destfd, crypto.dump_certificate_request(crypto.FILETYPE_PEM, req)) + os.close(destfd) return req @@ -118,7 +118,7 @@ def _get_serial_number(cadir): def _set_serial_number(cadir, last): serial = '%s/serial.txt' % cadir f = open(serial, 'w') - f.write(str(last)) + f.write(str(last) + '\n') f.close() diff --git a/func/minion/module_loader.py b/func/minion/module_loader.py index 6fb2a6b..37bc515 100755 --- a/func/minion/module_loader.py +++ b/func/minion/module_loader.py @@ -19,10 +19,11 @@ import sys from gettext import gettext _ = gettext - from func import logger logger = logger.Logger().logger +from inspect import isclass +from func.minion.modules import func_module def module_walker(topdir): module_files = [] @@ -80,13 +81,14 @@ def load_modules(blacklist=None): continue try: + # Auto-detect and load all FuncModules blip = __import__("modules.%s" % ( mod_imp_name), globals(), locals(), [mod_imp_name]) - if not hasattr(blip, "register_rpc"): - errmsg = _("%(module_path)s%(modname)s module not a proper module") - logger.warning(errmsg % {'module_path': module_file_path, 'modname':mod_imp_name}) - bad_mods[mod_imp_name] = True - continue - mods[mod_imp_name] = blip + for obj in dir(blip): + attr = getattr(blip, obj) + if isclass(attr) and issubclass(attr, func_module.FuncModule): + logger.debug("Loading %s module" % attr) + mods[mod_imp_name] = attr() + except ImportError, e: # A module that raises an ImportError is (for now) simply not loaded. errmsg = _("Could not load %s module: %s") diff --git a/func/minion/modules/command.py b/func/minion/modules/command.py index 3329927..cc463cf 100644 --- a/func/minion/modules/command.py +++ b/func/minion/modules/command.py @@ -13,18 +13,14 @@ Abitrary command execution module for func. """ -from modules import func_module - +import func_module import sub_process class Command(func_module.FuncModule): - def __init__(self): - self.methods = { - "run" : self.run, - "exists" : self.exists, - } - func_module.FuncModule.__init__(self) + version = "0.0.1" + api_version = "0.0.1" + description = "Works with shell commands." def run(self, command): """ @@ -46,7 +42,3 @@ class Command(func_module.FuncModule): if os.access(command, os.X_OK): return True return False - - -methods = Command() -register_rpc = methods.register_rpc
\ No newline at end of file diff --git a/func/minion/modules/copyfile.py b/func/minion/modules/copyfile.py index 6c81098..150af88 100644 --- a/func/minion/modules/copyfile.py +++ b/func/minion/modules/copyfile.py @@ -14,26 +14,16 @@ import os import time import shutil -from modules import func_module - - +import func_module class CopyFile(func_module.FuncModule): + version = "0.0.1" api_version = "0.0.2" - - - - def __init__(self): - self.methods = { - "copyfile" : self.copyfile, - "checksum" : self.checksum - } - func_module.FuncModule.__init__(self) + description = "Allows for smart copying of a file." def _checksum_blob(self, blob): - CHUNK=2**16 thissum = sha.new() thissum.update(blob) return thissum.hexdigest() @@ -66,7 +56,6 @@ class CopyFile(func_module.FuncModule): # we should probably verify mode,uid,gid are valid as well dirpath = os.path.dirname(filepath) - basepath = os.path.basename(filepath) if not os.path.exists(dirpath): os.makedirs(dirpath) @@ -118,8 +107,3 @@ class CopyFile(func_module.FuncModule): #XXX logger output here return False return True - - - -methods = CopyFile() -register_rpc = methods.register_rpc diff --git a/func/minion/modules/filetracker.py b/func/minion/modules/filetracker.py index 0aa4a49..f5f9dbb 100644 --- a/func/minion/modules/filetracker.py +++ b/func/minion/modules/filetracker.py @@ -16,13 +16,12 @@ ## # func modules -from modules import func_module +import func_module # other modules from stat import * import glob import os -import sys import md5 # defaults @@ -30,16 +29,9 @@ CONFIG_FILE='/etc/func/modules/filetracker.conf' class FileTracker(func_module.FuncModule): - def __init__(self): - self.methods = { - "track" : self.track, - "untrack" : self.untrack, - "info" : self.inventory, - "inventory" : self.inventory, - } - func_module.FuncModule.__init__(self) - - #========================================================== + version = "0.0.1" + api_version = "0.0.1" + description = "Maintains a manifest of files to keep track of." def __load(self): """ @@ -145,7 +137,7 @@ class FileTracker(func_module.FuncModule): gid = filestat[ST_GID] if not os.path.isdir(file_name) and checksum_enabled: sum_handle = open(file_name) - hash = self.sumfile(sum_handle) + hash = self.__sumfile(sum_handle) sum_handle.close() else: hash = "N/A" @@ -185,7 +177,7 @@ class FileTracker(func_module.FuncModule): #========================================================== - def sumfile(self, fobj): + def __sumfile(self, fobj): """ Returns an md5 hash for an object with read() method. credit: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/266486 @@ -198,6 +190,3 @@ class FileTracker(func_module.FuncModule): break m.update(d) return m.hexdigest() - -methods = FileTracker() -register_rpc = methods.register_rpc diff --git a/func/minion/modules/func_module.py b/func/minion/modules/func_module.py index 5965e24..7d476dc 100644 --- a/func/minion/modules/func_module.py +++ b/func/minion/modules/func_module.py @@ -10,6 +10,7 @@ ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## +import inspect from func import logger from func.config import read_config @@ -34,7 +35,7 @@ class FuncModule(object): "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods - } + } def __init_log(self): log = logger.Logger() @@ -45,11 +46,25 @@ class FuncModule(object): # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] - for meth in self.methods: - handlers["%s.%s" % (module_name,meth)] = self.methods[meth] + + # register our module's handlers + for name, handler in self.__list_handlers().items(): + handlers["%s.%s" % (module_name, name)] = handler + + def __list_handlers(self): + """ Return a dict of { handler_name, method, ... }. + All methods that do not being with an underscore will be exposed. + We also make sure to not expose our register_rpc method. + """ + handlers = {} + for attr in dir(self): + if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and \ + attr != 'register_rpc': + handlers[attr] = getattr(self, attr) + return handlers def __list_methods(self): - return self.methods.keys() + self.__base_methods.keys() + return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version @@ -59,7 +74,3 @@ class FuncModule(object): def __module_description(self): return self.description - - -methods = FuncModule() -register_rpc = methods.register_rpc diff --git a/func/minion/modules/hardware.py b/func/minion/modules/hardware.py index acf5988..46b1821 100644 --- a/func/minion/modules/hardware.py +++ b/func/minion/modules/hardware.py @@ -20,18 +20,15 @@ import sys # our modules import sub_process -from modules import func_module +import func_module # ================================= class HardwareModule(func_module.FuncModule): - def __init__(self): - self.methods = { - "info" : self.info, - "inventory" : self.inventory, # for func-inventory - "hal_info" : self.hal_info - } - func_module.FuncModule.__init__(self) + + version = "0.0.1" + api_version = "0.0.1" + description = "Hardware profiler." def hal_info(self): """ @@ -131,6 +128,3 @@ def hw_info(with_devices=True): }) return data - -methods = HardwareModule() -register_rpc = methods.register_rpc diff --git a/func/minion/modules/mount.py b/func/minion/modules/mount.py index e8e41ce..0db914f 100644 --- a/func/minion/modules/mount.py +++ b/func/minion/modules/mount.py @@ -13,18 +13,14 @@ ## import sub_process, os -from modules import func_module +import func_module class MountModule(func_module.FuncModule): - def __init__(self): - self.methods = { - "list": self.list, - "mount": self.mount, - "umount": self.umount, - "inventory": self.inventory, - } - func_module.FuncModule.__init__(self) + + version = "0.0.1" + api_version = "0.0.1" + description = "Mounting, unmounting and getting information on mounted filesystems." def list(self): cmd = sub_process.Popen(["/bin/cat", "/proc/mounts"], executable="/bin/cat", stdout=sub_process.PIPE, shell=False) @@ -86,7 +82,3 @@ class MountModule(func_module.FuncModule): def inventory(self, flatten=True): return self.list() - - -methods = MountModule() -register_rpc = methods.register_rpc diff --git a/func/minion/modules/nagios-check.py b/func/minion/modules/nagios-check.py index a902762..f1c0714 100644 --- a/func/minion/modules/nagios-check.py +++ b/func/minion/modules/nagios-check.py @@ -13,17 +13,14 @@ Abitrary command execution module for func. """ -from modules import func_module - +import func_module import sub_process class Nagios(func_module.FuncModule): - def __init__(self): - self.methods = { - "run" : self.run - } - func_module.FuncModule.__init__(self) + version = "0.0.1" + api_version = "0.0.1" + description = "Runs nagios checks." def run(self, check_command): """ @@ -35,8 +32,3 @@ class Nagios(func_module.FuncModule): cmdref = sub_process.Popen(command.split(),stdout=sub_process.PIPE,stderr=sub_process.PIPE, shell=False) data = cmdref.communicate() return (cmdref.returncode, data[0], data[1]) - -methods = Nagios() -register_rpc = methods.register_rpc - - diff --git a/func/minion/modules/networktest.py b/func/minion/modules/networktest.py index e88c169..5f54c5e 100644 --- a/func/minion/modules/networktest.py +++ b/func/minion/modules/networktest.py @@ -9,22 +9,16 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -from modules import func_module +import func_module from codes import FuncException import sub_process class NetworkTest(func_module.FuncModule): - def __init__(self): - self.methods = { - "ping" : self.ping, - "netstat" : self.netstat, - "traceroute" : self.traceroute, - "dig" : self.dig, - "isportopen" : self.isportopen, - } - func_module.FuncModule.__init__(self) + version = "0.0.1" + api_version = "0.0.1" + description = "Defines various network testing tools." def ping(self, *args): if '-c' not in args: @@ -58,7 +52,3 @@ class NetworkTest(func_module.FuncModule): full_cmd = [command] + opts cmd = sub_process.Popen(full_cmd, stdout=sub_process.PIPE) return [line for line in cmd.communicate()[0].split('\n')] - - -methods = NetworkTest() -register_rpc = methods.register_rpc diff --git a/func/minion/modules/process.py b/func/minion/modules/process.py index bdd5193..50900b4 100644 --- a/func/minion/modules/process.py +++ b/func/minion/modules/process.py @@ -18,19 +18,15 @@ import sub_process import codes # our modules -from modules import func_module +import func_module # ================================= class ProcessModule(func_module.FuncModule): - def __init__(self): - self.methods = { - "info" : self.info, - "kill" : self.kill, - "pkill" : self.pkill, - "mem" : self.mem - } - func_module.FuncModule.__init__(self) + + version = "0.0.1" + api_version = "0.0.1" + description = "Process related reporting and control." def info(self, flags="-auxh"): """ @@ -216,6 +212,3 @@ class ProcessModule(func_module.FuncModule): rc = sub_process.call(["/usr/bin/pkill", name, level], executable="/usr/bin/pkill", shell=False) return rc - -methods = ProcessModule() -register_rpc = methods.register_rpc diff --git a/func/minion/modules/reboot.py b/func/minion/modules/reboot.py index 8772b8f..c4fb275 100644 --- a/func/minion/modules/reboot.py +++ b/func/minion/modules/reboot.py @@ -8,22 +8,14 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -from modules import func_module - +import func_module import sub_process class Reboot(func_module.FuncModule): - def __init__(self): - self.methods = { - "reboot" : self.reboot - } - func_module.FuncModule.__init__(self) + version = "0.0.1" + api_version = "0.0.1" + description = "Reboots a machine." def reboot(self, when='now', message=''): return sub_process.call(["/sbin/shutdown", '-r', when, message]) - - -methods = Reboot() -register_rpc = methods.register_rpc diff --git a/func/minion/modules/rpms.py b/func/minion/modules/rpms.py index 901a9d6..34c4d50 100644 --- a/func/minion/modules/rpms.py +++ b/func/minion/modules/rpms.py @@ -8,17 +8,14 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -from modules import func_module +import func_module import rpm class RpmModule(func_module.FuncModule): - def __init__(self): - self.methods = { - "inventory" : self.inventory, - "info" : self.inventory - } - func_module.FuncModule.__init__(self) + version = "0.0.1" + api_version = "0.0.1" + description = "RPM related commands." def inventory(self, flatten=True): """ @@ -43,6 +40,3 @@ class RpmModule(func_module.FuncModule): else: results.append([name,epoch,version,release,arch]) return results - -methods = RpmModule() -register_rpc = methods.register_rpc diff --git a/func/minion/modules/service.py b/func/minion/modules/service.py index d088907..062aea5 100644 --- a/func/minion/modules/service.py +++ b/func/minion/modules/service.py @@ -13,25 +13,16 @@ ## import codes -from modules import func_module +import func_module import sub_process import os class Service(func_module.FuncModule): - def __init__(self): - self.methods = { - "start" : self.start, - "stop" : self.stop, - "restart" : self.restart, - "reload" : self.reload, - "status" : self.status, - "get_enabled" : self.get_enabled, - "get_running" : self.get_running, - "inventory" : self.inventory, - } - func_module.FuncModule.__init__(self) + version = "0.0.1" + api_version = "0.0.1" + description = "Allows for service control via func." def __command(self, service_name, command): @@ -95,6 +86,3 @@ class Service(func_module.FuncModule): tokens = line.split() results.append((tokens[0], tokens[-1].replace("...",""))) return results - -methods = Service() -register_rpc = methods.register_rpc diff --git a/func/minion/modules/smart.py b/func/minion/modules/smart.py index e85b90c..f410f09 100644 --- a/func/minion/modules/smart.py +++ b/func/minion/modules/smart.py @@ -17,17 +17,15 @@ import sub_process # our modules -from modules import func_module +import func_module # ================================= class SmartModule(func_module.FuncModule): - def __init__(self): - self.methods = { - "info" : self.info, - "inventory" : self.info, # for func-inventory - } - func_module.FuncModule.__init__(self) + + version = "0.0.1" + api_version = "0.0.1" + description = "Grabs status from SMART to see if your hard drives are ok." def info(self,flags="-q onecheck"): """ @@ -47,6 +45,3 @@ class SmartModule(func_module.FuncModule): results.append(x) return (cmd.returncode, results) - -methods = SmartModule() -register_rpc = methods.register_rpc diff --git a/func/minion/modules/snmp.py b/func/minion/modules/snmp.py index 3144144..c992db1 100644 --- a/func/minion/modules/snmp.py +++ b/func/minion/modules/snmp.py @@ -13,18 +13,15 @@ Abitrary command execution module for func. """ -from modules import func_module - +import func_module import sub_process base_snmp_command = '/usr/bin/snmpget -v2c -Ov -OQ' class Snmp(func_module.FuncModule): - def __init__(self): - self.methods = { - "get" : self.get - } - func_module.FuncModule.__init__(self) + version = "0.0.1" + api_version = "0.0.1" + description = "SNMP related calls through func." def get(self, oid, rocommunity, hostname='localhost'): """ @@ -39,8 +36,3 @@ class Snmp(func_module.FuncModule): #def walk(self, oid, rocommunity): #def table(self, oid, rocommunity): - -methods = Snmp() -register_rpc = methods.register_rpc - - diff --git a/func/minion/modules/test.py b/func/minion/modules/test.py index 24af03e..6718fed 100644 --- a/func/minion/modules/test.py +++ b/func/minion/modules/test.py @@ -1,17 +1,10 @@ -from modules import func_module +import func_module import time class Test(func_module.FuncModule): version = "11.11.11" api_version = "0.0.1" description = "Just a very simple example module" - def __init__(self): - self.methods = { - "add": self.add, - "ping": self.ping, - "sleep": self.sleep - } - func_module.FuncModule.__init__(self) def add(self, numb1, numb2): return numb1 + numb2 @@ -27,6 +20,3 @@ class Test(func_module.FuncModule): t = int(t) time.sleep(t) return time.time() - -methods = Test() -register_rpc = methods.register_rpc diff --git a/func/minion/modules/virt.py b/func/minion/modules/virt.py index ba888ec..04d36bd 100644 --- a/func/minion/modules/virt.py +++ b/func/minion/modules/virt.py @@ -38,6 +38,10 @@ VIRT_STATE_NAME_MAP = { class FuncLibvirtConnection(object): + version = "0.0.1" + api_version = "0.0.1" + description = "Virtualization items through func." + def __init__(self): cmd = sub_process.Popen("uname -r", shell=True, stdout=sub_process.PIPE) @@ -80,16 +84,16 @@ class FuncLibvirtConnection(object): if vm.name() == vmid: return vm - raise codes.FuncException("virtual machine %s not found" % needle) + raise codes.FuncException("virtual machine %s not found" % vmid) def shutdown(self, vmid): return self.find_vm(vmid).shutdown() def pause(self, vmid): - return suspend(self.conn,vmid) + return self.suspend(self.conn,vmid) def unpause(self, vmid): - return resume(self.conn,vmid) + return self.resume(self.conn,vmid) def suspend(self, vmid): return self.find_vm(vmid).suspend() @@ -119,31 +123,8 @@ class FuncLibvirtConnection(object): class Virt(func_module.FuncModule): - - def __init__(self): - - """ - Constructor. Register methods and make them available. - """ - - self.methods = { - "install" : self.install, - "shutdown" : self.shutdown, - "destroy" : self.destroy, - "start" : self.create, - "pause" : self.pause, - "unpause" : self.unpause, - "delete" : self.undefine, - "status" : self.get_status, - "info" : self.info, - "inventory" : self.info, # for func-inventory - "list_vms" : self.list_vms, - } - - func_module.FuncModule.__init__(self) - - def get_conn(self): - self.conn = FuncLibvirtConnection() + def __get_conn(self): + self.conn = FuncLibvirtConnection() return self.conn def state(self): @@ -176,7 +157,7 @@ class Virt(func_module.FuncModule): def list_vms(self): - self.conn = self.get_conn() + self.conn = self.__get_conn() vms = self.conn.find_vm(-1) results = [] for x in vms: @@ -195,7 +176,7 @@ class Virt(func_module.FuncModule): # Example: # install("bootserver.example.org", "fc7webserver", True) - conn = self.get_conn() + conn = self.__get_conn() if conn is None: raise codes.FuncException("no connection") @@ -227,7 +208,7 @@ class Virt(func_module.FuncModule): Make the machine with the given vmid stop running. Whatever that takes. """ - self.get_conn() + self.__get_conn() self.conn.shutdown(vmid) return 0 @@ -237,7 +218,7 @@ class Virt(func_module.FuncModule): """ Pause the machine with the given vmid. """ - self.get_conn() + self.__get_conn() self.conn.suspend(vmid) return 0 @@ -248,7 +229,7 @@ class Virt(func_module.FuncModule): Unpause the machine with the given vmid. """ - self.get_conn() + self.__get_conn() self.conn.resume(vmid) return 0 @@ -258,7 +239,7 @@ class Virt(func_module.FuncModule): """ Start the machine via the given mac address. """ - self.get_conn() + self.__get_conn() self.conn.create(vmid) return 0 @@ -269,7 +250,7 @@ class Virt(func_module.FuncModule): Pull the virtual power from the virtual domain, giving it virtually no time to virtually shut down. """ - self.get_conn() + self.__get_conn() self.conn.destroy(vmid) return 0 @@ -281,7 +262,7 @@ class Virt(func_module.FuncModule): by deleting the disk image and it's configuration file. """ - self.get_conn() + self.__get_conn() self.conn.undefine(vmid) return 0 @@ -292,9 +273,5 @@ class Virt(func_module.FuncModule): Return a state suitable for server consumption. Aka, codes.py values, not XM output. """ - self.get_conn() + self.__get_conn() return self.conn.get_status(vmid) - - -methods = Virt() -register_rpc = methods.register_rpc diff --git a/func/minion/modules/yumcmd.py b/func/minion/modules/yumcmd.py index b3976fb..7677c9a 100644 --- a/func/minion/modules/yumcmd.py +++ b/func/minion/modules/yumcmd.py @@ -8,8 +8,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - -from modules import func_module +import func_module import yum from yum import repos @@ -22,12 +21,9 @@ class DummyCallback(object): class Yum(func_module.FuncModule): - def __init__(self): - self.methods = { - "update" : self.update, - "check_update" : self.check_update - } - func_module.FuncModule.__init__(self) + version = "0.0.1" + api_version = "0.0.1" + description = "Package updates through yum." def update(self): # XXX support updating specific rpms @@ -52,7 +48,3 @@ class Yum(func_module.FuncModule): ayum.doTsSetup() ayum.repos.enableRepo(repo) return map(str, ayum.doPackageLists('updates').updates) - - -methods = Yum() -register_rpc = methods.register_rpc diff --git a/func/minion/utils.py b/func/minion/utils.py index 4ed0bf4..a7ea788 100755 --- a/func/minion/utils.py +++ b/func/minion/utils.py @@ -18,11 +18,13 @@ import time import traceback import xmlrpclib import glob +import traceback import codes from func import certs from func.config import read_config from func.commonconfig import FuncdConfig +from func import logger # "localhost" is a lame hostname to use for a key, so try to get # a more meaningful hostname. We do this by connecting to the certmaster @@ -93,29 +95,34 @@ def create_minion_keys(): if not keypair: keypair = certs.retrieve_key_from_file(key_file) csr = certs.make_csr(keypair, dest=csr_file) - except Exception, e: # need a little more specificity here + except Exception, e: + traceback.print_exc() raise codes.FuncException, "Could not create local keypair or csr for minion funcd session" result = False + log = logger.Logger().logger while not result: try: + log.debug("submitting CSR to certmaster %s" % master_uri) result, cert_string, ca_cert_string = submit_csr_to_master(csr_file, master_uri) except socket.gaierror, e: - raise codes.FuncException, "Could not locate certmaster at: http://certmaster:51235/" + raise codes.FuncException, "Could not locate certmaster at %s" % master_uri # logging here would be nice if not result: + log.warning("no response from certmaster %s, sleeping 10 seconds" % master_uri) time.sleep(10) if result: - cert_fo = open(cert_file, 'w') - cert_fo.write(cert_string) - cert_fo.close() - - ca_cert_fo = open(ca_cert_file, 'w') - ca_cert_fo.write(ca_cert_string) - ca_cert_fo.close() + log.debug("received certificate from certmaster %s, storing" % master_uri) + cert_fd = os.open(cert_file, os.O_RDWR|os.O_CREAT, 0644) + os.write(cert_fd, cert_string) + os.close(cert_fd) + + ca_cert_fd = os.open(ca_cert_file, os.O_RDWR|os.O_CREAT, 0644) + os.write(ca_cert_fd, ca_cert_string) + os.close(ca_cert_fd) def submit_csr_to_master(csr_file, master_uri): """" diff --git a/func/overlord/client.py b/func/overlord/client.py index 1021078..60b5c24 100755 --- a/func/overlord/client.py +++ b/func/overlord/client.py @@ -13,10 +13,8 @@ ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## -import optparse import sys import glob -import pprint from func.commonconfig import CMConfig from func.config import read_config, CONFIG_FILE diff --git a/func/overlord/func_command.py b/func/overlord/func_command.py index 09b324a..4cec8a0 100644 --- a/func/overlord/func_command.py +++ b/func/overlord/func_command.py @@ -1,4 +1,17 @@ -import glob +#!/usr/bin/python + +## func command line interface & client lib +## +## Copyright 2007,2008 Red Hat, Inc +## +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. + import sys diff --git a/func/overlord/inventory.py b/func/overlord/inventory.py index e5319ee..47fff6a 100755 --- a/func/overlord/inventory.py +++ b/func/overlord/inventory.py @@ -18,9 +18,7 @@ import os.path import time import optparse import sys -import glob import pprint -import exceptions import xmlrpclib from func.minion import sub_process |
