summaryrefslogtreecommitdiffstats
path: root/certmaster/utils.py
diff options
context:
space:
mode:
authorAdrian Likins <alikins@redhat.com>2008-04-22 14:36:17 -0400
committerAdrian Likins <alikins@redhat.com>2008-04-22 14:36:17 -0400
commitece4c159e4fd726a70b1da25821493fb8a90c8b3 (patch)
treebb91bf01af39b1caf4b36efdb8a5d2373d52ddce /certmaster/utils.py
parente92972a02d0e506cb7780694642137201421a74a (diff)
downloadcertmaster-ece4c159e4fd726a70b1da25821493fb8a90c8b3.zip
certmaster-ece4c159e4fd726a70b1da25821493fb8a90c8b3.tar.gz
certmaster-ece4c159e4fd726a70b1da25821493fb8a90c8b3.tar.xz
apply triggers patch from Steve Salevan <ssalevan@redhat.com>
Steves comments: Adding in triggering functionality, changed specfile and MANIFEST.in to reflect changes. Added sub_process.py file to facilitate the subprocesses necessary for triggering to work. Modified certmaster.py to add trigger points.
Diffstat (limited to 'certmaster/utils.py')
-rwxr-xr-xcertmaster/utils.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/certmaster/utils.py b/certmaster/utils.py
index eec3d2b..209e758 100755
--- a/certmaster/utils.py
+++ b/certmaster/utils.py
@@ -24,6 +24,7 @@ import certs
from config import read_config
from commonconfig import MinionConfig
import logger
+import sub_process
# FIXME: module needs better pydoc
@@ -108,6 +109,7 @@ def get_hostname(talk_to_certmaster=True):
try:
s = socket.socket()
s.settimeout(5)
+ print "server, port", server, port
s.connect((server, port))
(intf, port) = s.getsockname()
remote_hostname = socket.gethostbyaddr(intf)[0]
@@ -191,6 +193,37 @@ def create_minion_keys():
os.write(ca_cert_fd, ca_cert_string)
os.close(ca_cert_fd)
+def run_triggers(ref, globber):
+ """
+ Runs all the trigger scripts in a given directory.
+ ref can be a certmaster object, if not None, the name will be passed
+ to the script. If ref is None, the script will be called with
+ no argumenets. Globber is a wildcard expression indicating which
+ triggers to run. Example: "/var/lib/certmaster/triggers/blah/*"
+ """
+
+ log = logger.Logger().logger
+ triggers = glob.glob(globber)
+ triggers.sort()
+ for file in triggers:
+ log.debug("Executing trigger: %s" % file)
+ try:
+ if file.find(".rpm") != -1:
+ # skip .rpmnew files that may have been installed
+ # in the triggers directory
+ continue
+ if ref:
+ rc = sub_process.call([file, ref.name], shell=False)
+ else:
+ rc = sub_process.call([file], shell=False)
+ except:
+ log.warning("Warning: failed to execute trigger: %s" % file)
+ continue
+
+ if rc != 0:
+ raise codes.CMException, "certmaster trigger failed: %(file)s returns %(code)d" % { "file" : file, "code" : rc }
+
+
def submit_csr_to_master(csr_file, master_uri):
""""
gets us our cert back from the certmaster.wait_for_cert() method