summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSeth Vidal <skvidal@fedoraproject.org>2007-10-03 07:56:21 -0400
committerSeth Vidal <skvidal@fedoraproject.org>2007-10-03 07:56:21 -0400
commitcccce6ade18ec60ea3e5418e14f8187b3a8f789a (patch)
tree2a18667d0d9b47682a67a3076cfdf91e5a8c923e
parent66fc8600c90f5308a11de6895650441743396c8c (diff)
parent63e937cf144f0c61811bb6d842cfc22838a6b851 (diff)
downloadfunc-cccce6ade18ec60ea3e5418e14f8187b3a8f789a.tar.gz
func-cccce6ade18ec60ea3e5418e14f8187b3a8f789a.tar.xz
func-cccce6ade18ec60ea3e5418e14f8187b3a8f789a.zip
Merge branch 'master' of ssh://git.fedoraproject.org/git/hosted/func
* 'master' of ssh://git.fedoraproject.org/git/hosted/func: Fix up recursive pylint and pychecker rules. Moved code under the func namespace. Exit program after listing minions. Added func --list-minions option. changes to use the new command line modules add command.py from MOAP http://thomas.apestaart.org/moap/trac
-rwxr-xr-xMakefile8
-rwxr-xr-xfunc/Makefile5
-rw-r--r--func/config.py2
-rw-r--r--func/minion/AuthedXMLRPCServer.py (renamed from minion/AuthedXMLRPCServer.py)9
-rwxr-xr-xfunc/minion/Makefile (renamed from overlord/Makefile)11
-rw-r--r--func/minion/__init__.py (renamed from minion/__init__.py)0
-rwxr-xr-xfunc/minion/codes.py (renamed from minion/codes.py)0
-rwxr-xr-xfunc/minion/module_loader.py (renamed from minion/module_loader.py)2
-rwxr-xr-xfunc/minion/modules/Makefile (renamed from minion/Makefile)7
-rw-r--r--func/minion/modules/__init__.py (renamed from modules/__init__.py)0
-rw-r--r--func/minion/modules/command.py (renamed from modules/command.py)2
-rw-r--r--func/minion/modules/copyfile.py (renamed from modules/copyfile.py)14
-rwxr-xr-xfunc/minion/modules/func_module.py (renamed from modules/func_module.py)8
-rwxr-xr-xfunc/minion/modules/hardware.py (renamed from modules/hardware.py)25
-rwxr-xr-xfunc/minion/modules/process.py (renamed from modules/process.py)7
-rwxr-xr-xfunc/minion/modules/reboot.py (renamed from modules/reboot.py)0
-rwxr-xr-xfunc/minion/modules/service.py (renamed from modules/service.py)0
-rwxr-xr-xfunc/minion/modules/smart.py (renamed from modules/smart.py)7
-rwxr-xr-xfunc/minion/modules/test.py (renamed from modules/test.py)0
-rwxr-xr-xfunc/minion/modules/virt.py (renamed from modules/virt.py)42
-rw-r--r--func/minion/modules/yum.py (renamed from modules/yum.py)0
-rwxr-xr-xfunc/minion/server.py (renamed from minion/server.py)32
-rw-r--r--func/minion/sub_process.py (renamed from minion/sub_process.py)0
-rwxr-xr-xfunc/minion/utils.py (renamed from minion/utils.py)24
-rwxr-xr-xfunc/overlord/Makefile (renamed from modules/Makefile)7
-rw-r--r--func/overlord/__init__.py (renamed from overlord/__init__.py)0
-rwxr-xr-xfunc/overlord/client.py (renamed from overlord/client.py)165
-rw-r--r--func/overlord/command.py275
-rw-r--r--func/overlord/sslclient.py (renamed from overlord/sslclient.py)8
-rw-r--r--func/overlord/test_func.py (renamed from overlord/test_func.py)5
-rwxr-xr-xscripts/Makefile3
-rwxr-xr-xscripts/func4
-rw-r--r--setup.py5
33 files changed, 457 insertions, 220 deletions
diff --git a/Makefile b/Makefile
index 8ef2d33..5be4e59 100755
--- a/Makefile
+++ b/Makefile
@@ -5,8 +5,8 @@ NEWRELEASE = $(shell echo $$(($(RELEASE) + 1)))
MESSAGESPOT=po/messages.pot
TOPDIR = $(shell pwd)
-DIRS = modules minion overlord func docs scripts
-PYDIRS = modules minion overlord func scripts
+DIRS = func docs scripts
+PYDIRS = func scripts
EXAMPLEDIR = examples
INITDIR = init-scripts
@@ -19,8 +19,8 @@ manpage:
pod2man --center="certmaster" --release="" ./docs/certmaster.pod | gzip -c > ./docs/certmaster.1.gz
pod2man --center="certmaster-ca" --release="" ./docs/certmaster-ca.pod | gzip -c > ./docs/certmaster-ca.1.gz
-messages: minion/*.py
- xgettext -k_ -kN_ -o $(MESSAGESPOT) minion/*.py
+messages: func/minion/*.py
+ xgettext -k_ -kN_ -o $(MESSAGESPOT) func/minion/*.py
sed -i'~' -e 's/SOME DESCRIPTIVE TITLE/func/g' -e 's/YEAR THE PACKAGE'"'"'S COPYRIGHT HOLDER/2007 Red Hat, inc. /g' -e 's/FIRST AUTHOR <EMAIL@ADDRESS>, YEAR/Adrian Likins <alikins@redhat.com>, 2007/g' -e 's/PACKAGE VERSION/func $(VERSION)-$(RELEASE)/g' -e 's/PACKAGE/func/g' $(MESSAGESPOT)
diff --git a/func/Makefile b/func/Makefile
index 86a3db8..99fd546 100755
--- a/func/Makefile
+++ b/func/Makefile
@@ -1,6 +1,7 @@
PYFILES = $(wildcard *.py)
+PYDIRS = minion overlord
PYCHECKER = /usr/bin/pychecker
PYFLAKES = /usr/bin/pyflakes
@@ -17,3 +18,7 @@ pychecker::
pyflakes::
@$(PYFLAKES) $(PYFILES) || exit 0
+pychecker::
+ -for d in $(PYDIRS); do ($(MAKE) -C $$d pychecker ); done
+pyflakes::
+ -for d in $(PYDIRS); do ($(MAKE) -C $$d pyflakes ); done
diff --git a/func/config.py b/func/config.py
index f174cd7..6dbdc61 100644
--- a/func/config.py
+++ b/func/config.py
@@ -26,6 +26,8 @@ from ConfigParser import NoSectionError, NoOptionError, ConfigParser
from ConfigParser import ParsingError
import exceptions
+CONFIG_FILE = "/etc/func/certmaster.conf"
+
class ConfigError(exceptions.Exception):
def __init__(self, value=None):
exceptions.Exception.__init__(self)
diff --git a/minion/AuthedXMLRPCServer.py b/func/minion/AuthedXMLRPCServer.py
index da6b18a..265d1b2 100644
--- a/minion/AuthedXMLRPCServer.py
+++ b/func/minion/AuthedXMLRPCServer.py
@@ -39,7 +39,7 @@ class AuthedSimpleXMLRPCRequestHandler(SimpleXMLRPCServer.SimpleXMLRPCRequestHan
self.connection = self.request # for doPOST
self.rfile = socket._fileobject(self.request, "rb", self.rbufsize)
self.wfile = socket._fileobject(self.request, "wb", self.wbufsize)
-
+
def do_POST(self):
self.server._this_request = (self.request, self.client_address)
try:
@@ -101,7 +101,7 @@ class TestServer(AuthedSSLXMLRPCServer):
def __init__(self, address, pkey, cert, ca_cert):
AuthedSSLXMLRPCServer.__init__(self, address, pkey, cert, ca_cert, self.auth_cb)
-
+
def _dispatch(self, method, params):
if method == 'trait_names' or method == '_getAttributeNames':
return dir(self)
@@ -115,10 +115,10 @@ class TestServer(AuthedSSLXMLRPCServer):
print dir(p)
print p.get_subject()
else:
- print 'no cert'
+ print 'no cert'
return "your mom"
-
+
def auth_cb(self, request, client_address):
peer_cert = request.get_peer_certificate()
return peer_cert.get_subject().CN
@@ -138,4 +138,3 @@ if __name__ == '__main__':
h = ReqHandler()
server.register_instance(h)
server.serve_forever()
-
diff --git a/overlord/Makefile b/func/minion/Makefile
index 86a3db8..d630382 100755
--- a/overlord/Makefile
+++ b/func/minion/Makefile
@@ -1,19 +1,24 @@
PYFILES = $(wildcard *.py)
+PYDIRS = modules
PYCHECKER = /usr/bin/pychecker
PYFLAKES = /usr/bin/pyflakes
clean::
- @rm -fv *.pyc *~ .*~ *.pyo
+ @rm -fv *.pyc *~ .*~ *.pyo
@find . -name .\#\* -exec rm -fv {} \;
@rm -fv *.rpm
-
-pychecker::
+
+pychecker::
@$(PYCHECKER) $(PYFILES) || exit 0
pyflakes::
@$(PYFLAKES) $(PYFILES) || exit 0
+pychecker::
+ -for d in $(PYDIRS); do ($(MAKE) -C $$d pychecker ); done
+pyflakes::
+ -for d in $(PYDIRS); do ($(MAKE) -C $$d pyflakes ); done
diff --git a/minion/__init__.py b/func/minion/__init__.py
index e69de29..e69de29 100644
--- a/minion/__init__.py
+++ b/func/minion/__init__.py
diff --git a/minion/codes.py b/func/minion/codes.py
index 058ca44..058ca44 100755
--- a/minion/codes.py
+++ b/func/minion/codes.py
diff --git a/minion/module_loader.py b/func/minion/module_loader.py
index 4538fb2..1339359 100755
--- a/minion/module_loader.py
+++ b/func/minion/module_loader.py
@@ -36,7 +36,7 @@ def module_walker(topdir):
# in the module name, and foo..bar doesnt work -akl
module_files.append(os.path.normpath("%s/%s" % (root, filename)))
-
+
return module_files
def load_modules(blacklist=None):
diff --git a/minion/Makefile b/func/minion/modules/Makefile
index 86a3db8..f2bc6c4 100755
--- a/minion/Makefile
+++ b/func/minion/modules/Makefile
@@ -6,14 +6,13 @@ PYCHECKER = /usr/bin/pychecker
PYFLAKES = /usr/bin/pyflakes
clean::
- @rm -fv *.pyc *~ .*~ *.pyo
+ @rm -fv *.pyc *~ .*~ *.pyo
@find . -name .\#\* -exec rm -fv {} \;
@rm -fv *.rpm
-
-pychecker::
+
+pychecker::
@$(PYCHECKER) $(PYFILES) || exit 0
pyflakes::
@$(PYFLAKES) $(PYFILES) || exit 0
-
diff --git a/modules/__init__.py b/func/minion/modules/__init__.py
index e69de29..e69de29 100644
--- a/modules/__init__.py
+++ b/func/minion/modules/__init__.py
diff --git a/modules/command.py b/func/minion/modules/command.py
index 5dc0292..06adaaa 100644
--- a/modules/command.py
+++ b/func/minion/modules/command.py
@@ -36,5 +36,3 @@ class Command(func_module.FuncModule):
methods = Command()
register_rpc = methods.register_rpc
-
-
diff --git a/modules/copyfile.py b/func/minion/modules/copyfile.py
index 58b5ea4..a4f91f0 100644
--- a/modules/copyfile.py
+++ b/func/minion/modules/copyfile.py
@@ -27,7 +27,7 @@ class CopyFile(func_module.FuncModule):
"checksum" : self.checksum
}
func_module.FuncModule.__init__(self)
-
+
def checksum(self, thing):
CHUNK=2**16
@@ -54,17 +54,17 @@ 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)
-
+
remote_sum = self.checksum(filebuf)
local_sum = 0
if os.path.exists(filepath):
local_sum = self.checksum(filepath)
-
+
if remote_sum != local_sum or force is not None:
# back up the localone
if os.path.exists(filepath):
@@ -90,18 +90,18 @@ class CopyFile(func_module.FuncModule):
os.chown(filepath, uid, gid)
except (IOError, OSError), e:
return -1
-
+
return 1
def _backuplocal(self, fn):
"""
- make a date-marked backup of the specified file,
+ make a date-marked backup of the specified file,
return True or False on success or failure
"""
# backups named basename-YYYY-MM-DD@HH:MM~
ext = time.strftime("%Y-%m-%d@%H:%M~", time.localtime(time.time()))
backupdest = '%s.%s' % (fn, ext)
-
+
try:
shutil.copy2(fn, backupdest)
except shutil.Error, e:
diff --git a/modules/func_module.py b/func/minion/modules/func_module.py
index 32a235d..aa3c132 100755
--- a/modules/func_module.py
+++ b/func/minion/modules/func_module.py
@@ -24,11 +24,11 @@ class FuncModule(object):
version = "0.0.0"
api_version = "0.0.0"
description = "No Description provided"
-
+
def __init__(self):
config_file = '/etc/func/minion.conf'
- self.config = read_config(config_file, FuncdConfig)
+ self.config = read_config(config_file, FuncdConfig)
self.__init_log()
self.__base_methods = {
# __'s so we don't clobber useful names
@@ -37,11 +37,11 @@ class FuncModule(object):
"module_description" : self.__module_description,
"list_methods" : self.__list_methods
}
-
+
def __init_log(self):
log = logger.Logger()
self.logger = log.logger
-
+
def register_rpc(self, handlers, module_name):
# add the internal methods, note that this means they
# can get clobbbered by subclass versions
diff --git a/modules/hardware.py b/func/minion/modules/hardware.py
index e2455d1..79faf4c 100755
--- a/modules/hardware.py
+++ b/func/minion/modules/hardware.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
-##
+##
## Hardware profiler plugin
## requires the "smolt" client package be installed
## but also relies on lspci for some things
@@ -30,7 +30,7 @@ class HardwareModule(func_module.FuncModule):
def __init__(self):
self.methods = {
"info" : self.info,
- "hal_info" : self.hal_info
+ "hal_info" : self.hal_info
}
func_module.FuncModule.__init__(self)
@@ -41,10 +41,10 @@ class HardwareModule(func_module.FuncModule):
"""
cmd = sub_process.Popen(["/usr/bin/lshal"],shell=False,stdout=sub_process.PIPE)
- data = cmd.communicate()[0]
-
+ data = cmd.communicate()[0]
+
data = data.split("\n")
-
+
results = {}
current = ""
label = data[0]
@@ -56,7 +56,7 @@ class HardwareModule(func_module.FuncModule):
else:
if label == "":
label = d
- current = current + d
+ current = current + d
return results
@@ -75,7 +75,7 @@ def hw_info(with_devices=True):
# this may fail if smolt is not installed. That's ok. hal_info will
# still work.
-
+
# hack: smolt is not installed in site-packages
sys.path.append("/usr/share/smolt/client")
import smolt
@@ -92,14 +92,14 @@ def hw_info(with_devices=True):
'cpuModel' : str(host.cpuModel),
'numCpus' : str(host.numCpus),
'cpuSpeed' : str(host.cpuSpeed),
- 'systemMemory' : str(host.systemMemory),
+ 'systemMemory' : str(host.systemMemory),
'systemSwap' : str(host.systemSwap),
'kernelVersion' : str(host.kernelVersion),
'language' : str(host.language),
'platform' : str(host.platform),
'systemVendor' : str(host.systemVendor),
'systemModel' : str(host.systemModel),
- 'formfactor' : str(host.formfactor),
+ 'formfactor' : str(host.formfactor),
'selinux_enabled' : str(host.selinux_enabled),
'selinux_enforce' : str(host.selinux_enforce)
}
@@ -107,7 +107,7 @@ def hw_info(with_devices=True):
# if no hardware info requested, just return the above bits
if not with_devices:
return data
-
+
collection = data["devices"] = []
for item in hardware.deviceIter():
@@ -121,13 +121,10 @@ def hw_info(with_devices=True):
"Bus" : str(Bus),
"Driver" : str(Driver),
"Type" : str(Type),
- "Description" : str(Description)
+ "Description" : str(Description)
})
return data
methods = HardwareModule()
register_rpc = methods.register_rpc
-
-
-
diff --git a/modules/process.py b/func/minion/modules/process.py
index 94a0240..b48b910 100755
--- a/modules/process.py
+++ b/func/minion/modules/process.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
-##
+##
## Process lister (control TBA)
##
## Copyright 2007, Red Hat, Inc
@@ -46,7 +46,7 @@ class ProcessModule(func_module.FuncModule):
cmd = sub_process.Popen(["/bin/ps", flags] ,executable="/bin/ps", stdout=sub_process.PIPE,shell=False)
data = cmd.communicate()[0]
- results = []
+ results = []
for x in data.split("\n"):
tokens = x.split()
@@ -74,6 +74,3 @@ class ProcessModule(func_module.FuncModule):
methods = ProcessModule()
register_rpc = methods.register_rpc
-
-
-
diff --git a/modules/reboot.py b/func/minion/modules/reboot.py
index 8772b8f..8772b8f 100755
--- a/modules/reboot.py
+++ b/func/minion/modules/reboot.py
diff --git a/modules/service.py b/func/minion/modules/service.py
index 433d70b..433d70b 100755
--- a/modules/service.py
+++ b/func/minion/modules/service.py
diff --git a/modules/smart.py b/func/minion/modules/smart.py
index 0a7be47..c65dfb1 100755
--- a/modules/smart.py
+++ b/func/minion/modules/smart.py
@@ -1,6 +1,6 @@
#!/usr/bin/python
-##
+##
## Grabs status from SMART to see if your hard drives are ok
## Returns in the format of (return code, [line1, line2, line3,...])
##
@@ -42,7 +42,7 @@ class SmartModule(func_module.FuncModule):
cmd = sub_process.Popen("/usr/sbin/smartd %s" % flags,stdout=sub_process.PIPE,shell=True)
data = cmd.communicate()[0]
- results = []
+ results = []
for x in data.split("\n"):
results.append(x)
@@ -51,6 +51,3 @@ class SmartModule(func_module.FuncModule):
methods = SmartModule()
register_rpc = methods.register_rpc
-
-
-
diff --git a/modules/test.py b/func/minion/modules/test.py
index 55265a3..55265a3 100755
--- a/modules/test.py
+++ b/func/minion/modules/test.py
diff --git a/modules/virt.py b/func/minion/modules/virt.py
index 18ad718..07a9a87 100755
--- a/modules/virt.py
+++ b/func/minion/modules/virt.py
@@ -15,9 +15,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
"""
# warning: virt management is rather complicated
-# to see a simple example of func, look at the
+# to see a simple example of func, look at the
# service control module. API docs on how
-# to use this to come.
+# to use this to come.
# other modules
import os
@@ -102,7 +102,7 @@ class FuncLibvirtConnection(object):
def create(self, vmid):
return self.find_vm(vmid).create()
-
+
def destroy(self, vmid):
return self.find_vm(vmid).destroy()
@@ -112,8 +112,8 @@ class FuncLibvirtConnection(object):
def get_status2(self, vm):
state = vm.info()[0]
# print "DEBUG: state: %s" % state
- return VIRT_STATE_NAME_MAP.get(state,"unknown")
-
+ return VIRT_STATE_NAME_MAP.get(state,"unknown")
+
def get_status(self, vmid):
state = self.find_vm(vmid).info()[0]
return VIRT_STATE_NAME_MAP.get(state,"unknown")
@@ -121,10 +121,10 @@ class FuncLibvirtConnection(object):
class Virt(func_module.FuncModule):
-
-
+
+
def __init__(self):
-
+
"""
Constructor. Register methods and make them available.
"""
@@ -140,7 +140,7 @@ class Virt(func_module.FuncModule):
"status" : self.get_status,
"list_vms" : self.list_vms,
}
-
+
func_module.FuncModule.__init__(self)
def get_conn(self):
@@ -157,13 +157,13 @@ class Virt(func_module.FuncModule):
except:
pass
return results
-
+
def install(self, server_name, target_name, system=False):
"""
Install a new virt system by way of a named cobbler profile.
"""
-
+
# Example:
# install("bootserver.example.org", "fc7webserver", True)
@@ -192,8 +192,8 @@ class Virt(func_module.FuncModule):
return 0
else:
raise codes.FuncException("koan returned %d" % rc)
-
-
+
+
def shutdown(self, vmid):
"""
Make the machine with the given vmid stop running.
@@ -201,9 +201,9 @@ class Virt(func_module.FuncModule):
"""
self.get_conn()
self.conn.shutdown(vmid)
- return 0
+ return 0
+
-
def pause(self, vmid):
"""
@@ -213,7 +213,7 @@ class Virt(func_module.FuncModule):
self.conn.suspend(vmid)
return 0
-
+
def unpause(self, vmid):
"""
@@ -228,12 +228,12 @@ class Virt(func_module.FuncModule):
def create(self, vmid):
"""
- Start the machine via the given mac address.
+ Start the machine via the given mac address.
"""
self.get_conn()
self.conn.create(vmid)
return 0
-
+
def destroy(self, vmid):
@@ -247,7 +247,7 @@ class Virt(func_module.FuncModule):
def undefine(self, vmid):
-
+
"""
Stop a domain, and then wipe it from the face of the earth.
by deleting the disk image and it's configuration file.
@@ -263,12 +263,10 @@ class Virt(func_module.FuncModule):
"""
Return a state suitable for server consumption. Aka, codes.py values, not XM output.
"""
-
+
self.get_conn()
return self.conn.get_status(vmid)
methods = Virt()
register_rpc = methods.register_rpc
-
-
diff --git a/modules/yum.py b/func/minion/modules/yum.py
index 6600d47..6600d47 100644
--- a/modules/yum.py
+++ b/func/minion/modules/yum.py
diff --git a/minion/server.py b/func/minion/server.py
index 7a11ab8..f155dba 100755
--- a/minion/server.py
+++ b/func/minion/server.py
@@ -35,7 +35,7 @@ import codes
import module_loader
import utils
-
+
class XmlRpcInterface(object):
@@ -53,7 +53,7 @@ class XmlRpcInterface(object):
# need a reference so we can log ip's, certs, etc
# self.server = server
-
+
def __setup_handlers(self):
"""
@@ -80,7 +80,7 @@ class XmlRpcInterface(object):
def list_modules(self):
return self.modules.keys()
-
+
def list_methods(self):
return self.handlers.keys()
@@ -88,12 +88,12 @@ class XmlRpcInterface(object):
if method in self.handlers:
return FuncApiMethod(self.logger, method, self.handlers[method])
-
+
else:
self.logger.info("Unhandled method call for method: %s " % method)
raise codes.InvalidMethodException
-
+
class FuncApiMethod:
@@ -107,7 +107,7 @@ class FuncApiMethod:
self.logger = logger
self.__method = method
self.__name = name
-
+
def __log_exc(self):
"""
@@ -141,7 +141,7 @@ class FuncApiMethod:
def serve():
"""
- Code for starting the XMLRPC service.
+ Code for starting the XMLRPC service.
"""
server =FuncSSLXMLRPCServer(('', 51234))
server.logRequests = 0 # don't print stuff to console
@@ -165,13 +165,13 @@ class FuncSSLXMLRPCServer(AuthedXMLRPCServer.AuthedSSLXMLRPCServer,
def __init__(self, args):
self.allow_reuse_address = True
self.modules = module_loader.load_modules()
-
+
XmlRpcInterface.__init__(self)
hn = socket.getfqdn()
self.key = "%s/%s.pem" % (self.config.cert_dir, hn)
self.cert = "%s/%s.cert" % (self.config.cert_dir, hn)
self.ca = "%s/ca.cert" % self.config.cert_dir
-
+
AuthedXMLRPCServer.AuthedSSLXMLRPCServer.__init__(self, ("", 51234),
self.key, self.cert,
self.ca)
@@ -180,7 +180,7 @@ class FuncSSLXMLRPCServer(AuthedXMLRPCServer.AuthedSSLXMLRPCServer,
"""
the SimpleXMLRPCServer class will call _dispatch if it doesn't
- find a handler method
+ find a handler method
"""
# Recognize ipython's tab completion calls
@@ -194,19 +194,19 @@ class FuncSSLXMLRPCServer(AuthedXMLRPCServer.AuthedSSLXMLRPCServer,
cn = p.get_subject().CN
sub_hash = p.subject_name_hash()
else:
- print 'no cert'
+ print 'no cert'
# XXX FIXME - need to figure out how to dig into the server base classes
# so we can get client ip, and eventually cert id info -akl
self.audit_logger.log_call(ip, cn, sub_hash, method, params)
return self.get_dispatch_method(method)(*params)
-
+
def auth_cb(self, request, client_address):
peer_cert = request.get_peer_certificate()
return peer_cert.get_subject().CN
-
+
def main(argv):
"""
@@ -217,18 +217,16 @@ def main(argv):
utils.daemonize("/var/run/funcd.pid")
else:
print "serving...\n"
-
+
try:
utils.create_minion_keys()
serve()
except codes.FuncException, e:
print >> sys.stderr, 'error: %s' % e
sys.exit(1)
-
+
# ======================================================================================
if __name__ == "__main__":
textdomain(I18N_DOMAIN)
main(sys.argv)
-
-
diff --git a/minion/sub_process.py b/func/minion/sub_process.py
index 7c229dc..7c229dc 100644
--- a/minion/sub_process.py
+++ b/func/minion/sub_process.py
diff --git a/minion/utils.py b/func/minion/utils.py
index 7a6180d..eceb90f 100755
--- a/minion/utils.py
+++ b/func/minion/utils.py
@@ -27,21 +27,21 @@ from func.commonconfig import FuncdConfig
def create_minion_keys():
config_file = '/etc/func/minion.conf'
- config = read_config(config_file, FuncdConfig)
+ config = read_config(config_file, FuncdConfig)
cert_dir = config.cert_dir
master_uri = 'http://%s:51235/' % config.certmaster
hn = socket.getfqdn()
-
+
key_file = '%s/%s.pem' % (cert_dir, hn)
csr_file = '%s/%s.csr' % (cert_dir, hn)
cert_file = '%s/%s.cert' % (cert_dir, hn)
ca_cert_file = '%s/ca.cert' % cert_dir
-
+
if os.path.exists(cert_file) and os.path.exists(ca_cert_file):
return
- keypair = None
+ keypair = None
try:
if not os.path.exists(cert_dir):
os.makedirs(cert_dir)
@@ -53,19 +53,19 @@ def create_minion_keys():
csr = certs.make_csr(keypair, dest=csr_file)
except Exception, e: # need a little more specificity here
raise codes.FuncException, "Could not create local keypair or csr for minion funcd session"
-
+
result = False
while not result:
try:
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/"
-
+
# logging here would be nice
if not result:
- time.sleep(10)
-
-
+ time.sleep(10)
+
+
if result:
cert_fo = open(cert_file, 'w')
cert_fo.write(cert_string)
@@ -74,18 +74,18 @@ def create_minion_keys():
ca_cert_fo = open(ca_cert_file, 'w')
ca_cert_fo.write(ca_cert_string)
ca_cert_fo.close()
-
+
def submit_csr_to_master(csr_file, master_uri):
""""
gets us our cert back from the certmaster.wait_for_cert() method
takes csr_file as path location and master_uri
returns Bool, str(cert), str(ca_cert)
"""
-
+
fo = open(csr_file)
csr = fo.read()
s = xmlrpclib.ServerProxy(master_uri)
-
+
return s.wait_for_cert(csr)
diff --git a/modules/Makefile b/func/overlord/Makefile
index 86a3db8..f2bc6c4 100755
--- a/modules/Makefile
+++ b/func/overlord/Makefile
@@ -6,14 +6,13 @@ PYCHECKER = /usr/bin/pychecker
PYFLAKES = /usr/bin/pyflakes
clean::
- @rm -fv *.pyc *~ .*~ *.pyo
+ @rm -fv *.pyc *~ .*~ *.pyo
@find . -name .\#\* -exec rm -fv {} \;
@rm -fv *.rpm
-
-pychecker::
+
+pychecker::
@$(PYCHECKER) $(PYFILES) || exit 0
pyflakes::
@$(PYFLAKES) $(PYFILES) || exit 0
-
diff --git a/overlord/__init__.py b/func/overlord/__init__.py
index e69de29..e69de29 100644
--- a/overlord/__init__.py
+++ b/func/overlord/__init__.py
diff --git a/overlord/client.py b/func/overlord/client.py
index 412fbe6..3c60148 100755
--- a/overlord/client.py
+++ b/func/overlord/client.py
@@ -6,7 +6,7 @@
## Copyright 2007, Red Hat, Inc
## Michael DeHaan <mdehaan@redhat.com>
## +AUTHORS
-##
+##
## This software may be freely redistributed under the terms of the GNU
## general public license.
##
@@ -21,15 +21,16 @@ import glob
import pprint
from func.commonconfig import CMConfig
-from func.config import read_config
+from func.config import read_config, CONFIG_FILE
import sslclient
+import command
+
# ===================================
# defaults
# TO DO: some of this may want to come from config later
DEFAULT_PORT = 51234
-CONFIG_FILE = "/etc/func/certmaster.conf"
FUNC_USAGE = "Usage: %s [ --help ] [ --verbose ] target.example.org module method arg1 [...]"
# ===================================
@@ -63,22 +64,26 @@ class CommandAutomagic(object):
class Client(object):
def __init__(self, server_spec, port=DEFAULT_PORT, interactive=False,
- verbose=False, noglobs=False):
+ verbose=False, noglobs=False, config=None):
"""
Constructor.
@server_spec -- something like "*.example.org" or "foosball"
@port -- is the port where all funcd processes should be contacted
@verbose -- whether to print unneccessary things
@noglobs -- specifies server_spec is not a glob, and run should return single values
+ @config -- optional config object
"""
- self.config = read_config(CONFIG_FILE, CMConfig)
+ self.config = config
+ if config is None:
+ self.config = read_config(CONFIG_FILE, CMConfig)
+
self.server_spec = server_spec
self.port = port
self.verbose = verbose
self.interactive = interactive
self.noglobs = noglobs
self.servers = self.expand_servers(self.server_spec)
-
+
# default cert/ca/key is the same as the certmaster ca - need to
# be able to change that on the cli
self.key = '%s/funcmaster.key' % self.config.cadir
@@ -126,13 +131,13 @@ class Client(object):
to an unspecified number of machines.
So, it enables stuff like this:
-
+
Client("*.example.org").yum.install("foo")
# WARNING: any missing values in Client's source will yield
# strange errors with this engaged. Be aware of that.
"""
-
+
return CommandAutomagic(self, [name])
# -----------------------------------------------
@@ -165,13 +170,13 @@ class Client(object):
try:
# thats some pretty code right there aint it? -akl
# we can't call "call" on s, since thats a rpc, so
- # we call gettatr around it.
+ # we call gettatr around it.
meth = "%s.%s" % (module, method)
retval = getattr(conn, meth)(*args[:])
if self.interactive:
- pprint.pprint(retval)
+ pprint.pprint(retval)
except Exception, e:
- retval = e
+ retval = e
if self.interactive:
sys.stderr.write("remote exception on %s: %s\n" %
(server, str(e)))
@@ -186,7 +191,7 @@ class Client(object):
return results
- # -----------------------------------------------
+ # -----------------------------------------------
def cli_return(self,results):
"""
@@ -217,102 +222,74 @@ class Client(object):
# ===================================================================
-class FuncCommandLine(object):
-
- def __init__(self,myname,args):
- """
- Constructor. Takes name of program + arguments.
- """
- self.myname = myname
- self.args = args
- self.verbose = 0
- self.server_spec = None
- self.port = DEFAULT_PORT
-
- # -----------------------------------------------
-
- def usage(self):
- """
- Returns usage string for command line users.
- """
- return FUNC_USAGE % self.myname
-
- # -----------------------------------------------
-
- def run(self):
- """
- Engages the command line.
- """
-
- rc = self.parse_command_line()
- if rc != 0:
- return rc
-
- return self.run_command()
-
- # -----------------------------------------------
-
- def parse_command_line(self):
- """
- Parses the command line and loads up all the variables.
- """
+class Call(command.Command):
+ name = "call"
+ useage = "call nodule method name arg1 arg2..."
+ def addOptions(self):
+ self.parser.add_option("-v", "--verbose", dest="verbose",
+ action="store_true")
+ self.parser.add_option("-p", "--port", dest="port",
+ default=DEFAULT_PORT)
- # parse options
- p = optparse.OptionParser()
- p.add_option("-v","--verbose",dest="verbose",action="store_true")
- p.add_option("-p","--port",dest="port",default=DEFAULT_PORT)
- (options, args) = p.parse_args(self.args)
+ def handleOptions(self, options):
+ self.options = options
- self.args = args
self.verbose = options.verbose
- self.port = options.port
- # self.help = options.help
+ self.port = options.port
+ # I'm not really a fan of the "module methodname" approach
+ # but we'll keep it for now -akl
- # provided for free:
- #
- #if self.help:
- # print self.usage()
- # return -411
+ def do(self, args):
- # process arguments
- # a good Klingon program does not have parameters
- # it has arguments, and it always wins them.
+ # I'm not really a fan of the "module methodname" approach
+ # but we'll keep it for now -akl
- if len(args) < 3:
- print self.usage()
- return -411
+ self.server_spec = args[0]
+ self.module = args[1]
+ self.method = args[2]
+ self.method_args = args[3:]
- self.server_spec = self.args[0]
- self.module = self.args[1]
- self.method = self.args[2]
- self.method_args = self.args[3:]
-
- return 0
-
- # -----------------------------------------------
-
- def run_command(self):
- """
- Runs the actual command.
- """
client = Client(self.server_spec,port=self.port,interactive=True,
- verbose=self.verbose)
+ verbose=self.verbose, config=self.config)
results = client.run(self.module, self.method, self.method_args)
-
+
# TO DO: add multiplexer support
# probably as a higher level module.
-
+
return client.cli_return(results)
-
-# ===================================================================
+class FuncCommandLine(command.Command):
+ name = "client"
+ useage = "func is the commandline interface to a func minion"
+
+ subCommandClasses = [Call]
+
+ def __init__(self):
+
+ command.Command.__init__(self)
+
+ def do(self, args):
+ pass
+ def addOptions(self):
+ self.parser.add_option('', '--version', action="store_true",
+ help="show version information")
+ self.parser.add_option("--list-minions", dest="list_minions",
+ action="store_true", help="list all available minions")
-if __name__ == "__main__":
- # this is what /usr/bin/func will run
- myname, argv = sys.argv[0], sys.argv[1:]
- cli = FuncCommandLine(myname,argv)
- rc = cli.run()
- sys.exit(rc)
+ def handleOptions(self, options):
+ if options.version:
+ #FIXME
+ print "version is NOT IMPLEMENTED YET"
+ if options.list_minions:
+ self.list_minions()
+ sys.exit(0) # stop execution
+ def list_minions(self):
+ print "Minions:"
+ gloob = "%s/%s.cert" % (self.config.certroot, "*")
+ certs = glob.glob(gloob)
+ for cert in certs:
+ host = cert.replace(self.config.certroot, "")[1:-5]
+ print " %s" % host
diff --git a/func/overlord/command.py b/func/overlord/command.py
new file mode 100644
index 0000000..812ad8d
--- /dev/null
+++ b/func/overlord/command.py
@@ -0,0 +1,275 @@
+# -*- Mode: Python; test-case-name: test_command -*-
+# vi:si:et:sw=4:sts=4:ts=4
+
+# This file is released under the standard PSF license.
+#
+# from MOAP - https://thomas.apestaart.org/moap/trac
+# written by Thomas Vander Stichele (thomas at apestaart dot org)
+#
+
+"""
+Command class.
+"""
+
+import optparse
+import sys
+
+from func.config import read_config, CONFIG_FILE
+from func.commonconfig import CMConfig
+
+class CommandHelpFormatter(optparse.IndentedHelpFormatter):
+ """
+ I format the description as usual, but add an overview of commands
+ after it if there are any, formatted like the options.
+ """
+ _commands = None
+
+ def addCommand(self, name, description):
+ if self._commands is None:
+ self._commands = {}
+ self._commands[name] = description
+
+ ### override parent method
+ def format_description(self, description):
+ # textwrap doesn't allow for a way to preserve double newlines
+ # to separate paragraphs, so we do it here.
+ blocks = description.split('\n\n')
+ rets = []
+
+ for block in blocks:
+ rets.append(optparse.IndentedHelpFormatter.format_description(self,
+ block))
+ ret = "\n".join(rets)
+ if self._commands:
+ commandDesc = []
+ commandDesc.append("commands:")
+ keys = self._commands.keys()
+ keys.sort()
+ length = 0
+ for key in keys:
+ if len(key) > length:
+ length = len(key)
+ for name in keys:
+ format = " %-" + "%d" % length + "s %s"
+ commandDesc.append(format % (name, self._commands[name]))
+ ret += "\n" + "\n".join(commandDesc) + "\n"
+ return ret
+
+class CommandOptionParser(optparse.OptionParser):
+ """
+ I parse options as usual, but I explicitly allow setting stdout
+ so that our print_help() method (invoked by default with -h/--help)
+ defaults to writing there.
+ """
+ _stdout = sys.stdout
+
+ def set_stdout(self, stdout):
+ self._stdout = stdout
+
+ # we're overriding the built-in file, but we need to since this is
+ # the signature from the base class
+ __pychecker__ = 'no-shadowbuiltin'
+ def print_help(self, file=None):
+ # we are overriding a parent method so we can't do anything about file
+ __pychecker__ = 'no-shadowbuiltin'
+ if file is None:
+ file = self._stdout
+ file.write(self.format_help())
+
+class Command:
+ """
+ I am a class that handles a command for a program.
+ Commands can be nested underneath a command for further processing.
+
+ @cvar name: name of the command, lowercase
+ @cvar aliases: list of alternative lowercase names recognized
+ @type aliases: list of str
+ @cvar usage: short one-line usage string;
+ %command gets expanded to a sub-command or [commands]
+ as appropriate
+ @cvar summary: short one-line summary of the command
+ @cvar description: longer paragraph explaining the command
+ @cvar subCommands: dict of name -> commands below this command
+ @type subCommands: dict of str -> L{Command}
+ """
+ name = None
+ aliases = None
+ usage = None
+ summary = None
+ description = None
+ parentCommand = None
+ subCommands = None
+ subCommandClasses = None
+ aliasedSubCommands = None
+
+ def __init__(self, parentCommand=None, stdout=sys.stdout,
+ stderr=sys.stderr):
+ """
+ Create a new command instance, with the given parent.
+ Allows for redirecting stdout and stderr if needed.
+ This redirection will be passed on to child commands.
+ """
+ if not self.name:
+ self.name = str(self.__class__).split('.')[-1].lower()
+ self.stdout = stdout
+ self.stderr = stderr
+ self.parentCommand = parentCommand
+
+ self.config = read_config(CONFIG_FILE, CMConfig)
+
+ # create subcommands if we have them
+ self.subCommands = {}
+ self.aliasedSubCommands = {}
+ if self.subCommandClasses:
+ for C in self.subCommandClasses:
+ c = C(self, stdout=stdout, stderr=stderr)
+ self.subCommands[c.name] = c
+ if c.aliases:
+ for alias in c.aliases:
+ self.aliasedSubCommands[alias] = c
+
+ # create our formatter and add subcommands if we have them
+ formatter = CommandHelpFormatter()
+ if self.subCommands:
+ for name, command in self.subCommands.items():
+ formatter.addCommand(name, command.summary or
+ command.description)
+
+ # expand %command for the bottom usage
+ usage = self.usage or self.name
+ if usage.find("%command") > -1:
+ usage = usage.split("%command")[0] + '[command]'
+ usages = [usage, ]
+
+ # FIXME: abstract this into getUsage that takes an optional
+ # parentCommand on where to stop recursing up
+ # useful for implementing subshells
+
+ # walk the tree up for our usage
+ c = self.parentCommand
+ while c:
+ usage = c.usage or c.name
+ if usage.find(" %command") > -1:
+ usage = usage.split(" %command")[0]
+ usages.append(usage)
+ c = c.parentCommand
+ usages.reverse()
+ usage = " ".join(usages)
+
+ # create our parser
+ description = self.description or self.summary
+ self.parser = CommandOptionParser(
+ usage=usage, description=description,
+ formatter=formatter)
+ self.parser.set_stdout(self.stdout)
+ self.parser.disable_interspersed_args()
+
+ # allow subclasses to add options
+ self.addOptions()
+
+ def addOptions(self):
+ """
+ Override me to add options to the parser.
+ """
+ pass
+
+ def do(self, args):
+ """
+ Override me to implement the functionality of the command.
+ """
+ pass
+
+ def parse(self, argv):
+ """
+ Parse the given arguments and act on them.
+
+ @rtype: int
+ @returns: an exit code
+ """
+ self.options, args = self.parser.parse_args(argv)
+
+ # FIXME: make handleOptions not take options, since we store it
+ # in self.options now
+ ret = self.handleOptions(self.options)
+ if ret:
+ return ret
+
+ # handle pleas for help
+ if args and args[0] == 'help':
+ self.debug('Asked for help, args %r' % args)
+
+ # give help on current command if only 'help' is passed
+ if len(args) == 1:
+ self.outputHelp()
+ return 0
+
+ # complain if we were asked for help on a subcommand, but we don't
+ # have any
+ if not self.subCommands:
+ self.stderr.write('No subcommands defined.')
+ self.parser.print_usage(file=self.stderr)
+ self.stderr.write(
+ "Use --help to get more information about this command.\n")
+ return 1
+
+ # rewrite the args the other way around;
+ # help doap becomes doap help so it gets deferred to the doap
+ # command
+ args = [args[1], args[0]]
+
+ # if we don't have subcommands, defer to our do() method
+ if not self.subCommands:
+ ret = self.do(args)
+
+ # if everything's fine, we return 0
+ if not ret:
+ ret = 0
+
+ return ret
+
+ # if we do have subcommands, defer to them
+ try:
+ command = args[0]
+ except IndexError:
+ self.parser.print_usage(file=self.stderr)
+ self.stderr.write(
+ "Use --help to get a list of commands.\n")
+ return 1
+
+ if command in self.subCommands.keys():
+ return self.subCommands[command].parse(args[1:])
+
+ if self.aliasedSubCommands:
+ if command in self.aliasedSubCommands.keys():
+ return self.aliasedSubCommands[command].parse(args[1:])
+
+ self.stderr.write("Unknown command '%s'.\n" % command)
+ return 1
+
+ def outputHelp(self):
+ """
+ Output help information.
+ """
+ self.parser.print_help(file=self.stderr)
+
+ def outputUsage(self):
+ """
+ Output usage information.
+ Used when the options or arguments were missing or wrong.
+ """
+ self.parser.print_usage(file=self.stderr)
+
+ def handleOptions(self, options):
+ """
+ Handle the parsed options.
+ """
+ pass
+
+ def getRootCommand(self):
+ """
+ Return the top-level command, which is typically the program.
+ """
+ c = self
+ while c.parentCommand:
+ c = c.parentCommand
+ return c
diff --git a/overlord/sslclient.py b/func/overlord/sslclient.py
index 0ddbf58..ccb2c9c 100644
--- a/overlord/sslclient.py
+++ b/func/overlord/sslclient.py
@@ -44,15 +44,9 @@ class FuncServer(SSLXMLRPCServerProxy):
self.pem,
self.crt,
self.ca)
-
+
if __name__ == "__main__":
s = SSLXMLRPCServerProxy('https://localhost:51234/', '/etc/pki/func/slave.pem', '/etc/pki/func/slave.cert', '/etc/pki/func/ca/funcmaster.crt')
f = s.ping(1, 2)
print f
-
-
-
-
-
-
diff --git a/overlord/test_func.py b/func/overlord/test_func.py
index 4850675..2b3f041 100644
--- a/overlord/test_func.py
+++ b/func/overlord/test_func.py
@@ -38,7 +38,7 @@ if TEST_PROCESS:
# here's the service module testing
if TEST_SERVICES:
print s.service.restart("httpd")
-
+
if TEST_HARDWARE:
print s.hardware.info()
@@ -58,5 +58,4 @@ if TEST_VIRT:
if status == "shutdown":
s.virt.start(vm)
-# add more tests here
-
+# add more tests here
diff --git a/scripts/Makefile b/scripts/Makefile
index 86a3db8..a4cc7e1 100755
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -15,5 +15,6 @@ pychecker::
@$(PYCHECKER) $(PYFILES) || exit 0
pyflakes::
+ifneq ($(PYFILES)x, x)
@$(PYFLAKES) $(PYFILES) || exit 0
-
+endif
diff --git a/scripts/func b/scripts/func
index 2afb4e7..5e069f8 100755
--- a/scripts/func
+++ b/scripts/func
@@ -8,7 +8,7 @@ import distutils.sysconfig
import func.overlord.client as client
myname, argv = sys.argv[0], sys.argv[1:]
-cli = client.FuncCommandLine(myname, argv)
-cli.run()
+cli = client.FuncCommandLine()
+print cli.parse(argv)
diff --git a/setup.py b/setup.py
index c908534..41f5553 100644
--- a/setup.py
+++ b/setup.py
@@ -28,10 +28,7 @@ if __name__ == "__main__":
license = "GPL",
scripts = ["scripts/funcd", "scripts/func", "scripts/certmaster", "scripts/certmaster-ca"],
# package_data = { '' : ['*.*'] },
- package_dir = {"%s" % NAME: "%s" % NAME,
- "%s/minion" % NAME: "minion/",
- "%s/minion/modules" % NAME: "modules/",
- "%s/overlord" % NAME: "overlord/"
+ package_dir = {"%s" % NAME: "%s" % NAME
},
packages = ["%s" % NAME,
"%s/minion" % NAME,