def minion_async_run(retriever, method, args): """ This is a simpler invocation for minion side async usage. """ # to avoid confusion of job id's (we use the same job database) # minion jobs contain the string "minion". job_id = "%s-minion" % pprint.pformat(time.time()) __update_status(job_id, JOB_ID_RUNNING, -1) pid = os.fork() if pid != 0: os.waitpid(pid, 0) return job_id else: # daemonize! os.umask(077) os.chdir('/') os.setsid() if os.fork(): os._exit(0) try: function_ref = retriever(method) rc = function_ref(*args) except Exception, e: (t, v, tb) = sys.exc_info() rc = cm_utils.nice_exception(t,v,tb) __update_status(job_id, JOB_ID_FINISHED, rc) os._exit(0)
def _dispatch(self, method, params): """ the SimpleXMLRPCServer class will call _dispatch if it doesn't find a handler method """ # take _this_request and hand it off to check out the acls of the method # being called vs the requesting host if not hasattr(self, '_this_request'): raise codes.InvalidMethodException r, a = self._this_request peer_cert = r.get_peer_certificate() ip = a[0] # generally calling conventions are: hardware.info # async convention is async.hardware.info # here we parse out the async to decide how to invoke it. # see the async docs on the Wiki for further info. async_dispatch = False if method.startswith("async."): async_dispatch = True method = method.replace("async.", "", 1) if not self.acls.check(self._our_ca, peer_cert, ip, method, params): raise codes.AccessToMethodDenied # Recognize ipython's tab completion calls if method == 'trait_names' or method == '_getAttributeNames': return self.handlers.keys() cn = peer_cert.get_subject().CN sub_hash = peer_cert.subject_name_hash() self.audit_logger.log_call(ip, cn, sub_hash, method, params) try: if not async_dispatch: #check if we send some queries if len(params) > 0 and type( params[0]) == dict and params[0].has_key('__fact__'): fact_result = self.minion_query.exec_query( params[0]['__fact__'], True) else: return self.get_dispatch_method(method)(*params) if fact_result[ 0]: #that means we have True from query so can go on method_result = self.get_dispatch_method(method)( *params[1:]) return [{'__fact__': fact_result}, method_result] else: return [{'__fact__': fact_result}] else: return jobthing.minion_async_run(self.get_dispatch_method, method, params, self.minion_query) except: (t, v, tb) = sys.exc_info() rc = utils.nice_exception(t, v, tb) return rc
def minion_async_run(retriever, method, args,minion_query=None): """ This is a simpler invocation for minion side async usage. """ # to avoid confusion of job id's (we use the same job database) # minion jobs contain the string "minion". job_id = "%s-minion" % pprint.pformat(time.time()) __update_status(job_id, JOB_ID_RUNNING, -1) pid = os.fork() if pid != 0: os.waitpid(pid, 0) return job_id else: # daemonize! os.umask(077) os.chdir('/') os.setsid() if os.fork(): os._exit(0) try: fact_result = None if args and type(args[0]) == dict and args[0].has_key('__fact__'): fact_result = minion_query.exec_query(args[0]['__fact__'],True) else: function_ref = retriever(method) #here we will append the job_id at the end of the args list #so we can pull it via some decorator and use it for other #purposes like logginng and output tracking per method which #will be useful for lots of applications ... #if you are doing something useful with decorators per methods #be aware of that please ... args = list(args) args.append({'__logger__':True,'job_id':job_id}) args = tuple(args) rc = function_ref(*args) if fact_result and fact_result[0]: #that means we have True from query so can go on function_ref = retriever(method) #here we will append the job_id at the end of the args list #so we can pull it via some decorator and use it for other #purposes like logginng and output tracking per method which #will be useful for lots of applications ... #if you are doing something useful with decorators per methods #be aware of that please ... args = list(args) args.append({'__logger__':True,'job_id':job_id}) args = tuple(args) rc = function_ref(*args[1:]) rc = [{'__fact__':fact_result},rc] elif fact_result and not fact_result[0]: rc = [{'__fact__':fact_result}] except Exception, e: (t, v, tb) = sys.exc_info() rc = cm_utils.nice_exception(t,v,tb) __update_status(job_id, JOB_ID_FINISHED, rc) os._exit(0)
def _dispatch(self, method, params): """ the SimpleXMLRPCServer class will call _dispatch if it doesn't find a handler method """ # take _this_request and hand it off to check out the acls of the method # being called vs the requesting host if not hasattr(self, '_this_request'): raise codes.InvalidMethodException r,a = self._this_request peer_cert = r.get_peer_certificate() ip = a[0] # generally calling conventions are: hardware.info # async convention is async.hardware.info # here we parse out the async to decide how to invoke it. # see the async docs on the Wiki for further info. async_dispatch = False if method.startswith("async."): async_dispatch = True method = method.replace("async.","",1) if not self.acls.check(self._our_ca, peer_cert, ip, method, params): raise codes.AccessToMethodDenied # Recognize ipython's tab completion calls if method == 'trait_names' or method == '_getAttributeNames': return self.handlers.keys() cn = peer_cert.get_subject().CN sub_hash = peer_cert.subject_name_hash() self.audit_logger.log_call(ip, cn, sub_hash, method, params) try: if not async_dispatch: #check if we send some queries if len(params)>0 and type(params[0]) == dict and params[0].has_key('__fact__'): fact_result = self.minion_query.exec_query(params[0]['__fact__'],True) else: return self.get_dispatch_method(method)(*params) if fact_result[0]: #that means we have True from query so can go on method_result = self.get_dispatch_method(method)(*params[1:]) return [{'__fact__':fact_result},method_result] else: return [{'__fact__':fact_result}] else: return jobthing.minion_async_run(self.get_dispatch_method, method, params,self.minion_query) except: (t, v, tb) = sys.exc_info() rc = utils.nice_exception(t, v, tb) return rc
def __call__(self, *args): self.logger.debug("(X) -------------------------------------------") try: rc = self.__method(*args) except codes.FuncException, e: self.__log_exc() (t, v, tb) = sys.exc_info() rc = utils.nice_exception(t,v,tb)
def __call__(self, *args): self.logger.debug("(X) -------------------------------------------") try: rc = self.__method(*args) except codes.FuncException, e: self.__log_exc() (t, v, tb) = sys.exc_info() rc = utils.nice_exception(t, v, tb)
def minion_async_run(retriever, method, args, minion_query=None): """ This is a simpler invocation for minion side async usage. """ # to avoid confusion of job id's (we use the same job database) # minion jobs contain the string "minion". job_id = "%s-minion" % pprint.pformat(time.time()) __update_status(job_id, JOB_ID_RUNNING, -1) pid = os.fork() if pid != 0: os.waitpid(pid, 0) return job_id else: # daemonize! os.umask(077) os.chdir('/') os.setsid() if os.fork(): os._exit(0) try: fact_result = None if args and type(args[0]) == dict and args[0].has_key('__fact__'): fact_result = minion_query.exec_query(args[0]['__fact__'], True) else: function_ref = retriever(method) rc = function_ref(*args) if fact_result and fact_result[ 0]: #that means we have True from query so can go on function_ref = retriever(method) rc = function_ref(*args[1:]) rc = [{'__fact__': fact_result}, rc] elif fact_result and not fact_result[0]: rc = [{'__fact__': fact_result}] except Exception, e: (t, v, tb) = sys.exc_info() rc = cm_utils.nice_exception(t, v, tb) __update_status(job_id, JOB_ID_FINISHED, rc) os._exit(0)
def minion_async_run(retriever, method, args,minion_query=None): """ This is a simpler invocation for minion side async usage. """ # to avoid confusion of job id's (we use the same job database) # minion jobs contain the string "minion". job_id = "%s-minion" % pprint.pformat(time.time()) __update_status(job_id, JOB_ID_RUNNING, -1) pid = os.fork() if pid != 0: os.waitpid(pid, 0) return job_id else: # daemonize! os.umask(077) os.chdir('/') os.setsid() if os.fork(): os._exit(0) try: fact_result = None if args and type(args[0]) == dict and args[0].has_key('__fact__'): fact_result = minion_query.exec_query(args[0]['__fact__'],True) else: function_ref = retriever(method) rc = function_ref(*args) if fact_result and fact_result[0]: #that means we have True from query so can go on function_ref = retriever(method) rc = function_ref(*args[1:]) rc = [{'__fact__':fact_result},rc] elif fact_result and not fact_result[0]: rc = [{'__fact__':fact_result}] except Exception, e: (t, v, tb) = sys.exc_info() rc = cm_utils.nice_exception(t,v,tb) __update_status(job_id, JOB_ID_FINISHED, rc) os._exit(0)
self.logger.info("Exception Info:\n%s" % string.join(traceback.format_list(traceback.extract_tb(tb)))) def __call__(self, *args): self.logger.debug("(X) -------------------------------------------") try: rc = self.__method(*args) except codes.FuncException, e: self.__log_exc() (t, v, tb) = sys.exc_info() rc = utils.nice_exception(t,v,tb) except: self.__log_exc() (t, v, tb) = sys.exc_info() rc = utils.nice_exception(t,v,tb) self.logger.debug("Return code for %s: %s" % (self.__name, rc)) return rc def serve(): """ Code for starting the XMLRPC service. """ config = read_config("/etc/func/minion.conf", FuncdConfig) listen_addr = config.listen_addr listen_port = config.listen_port if listen_port == '': listen_port = 51234
string.join(traceback.format_list(traceback.extract_tb(tb)))) def __call__(self, *args): self.logger.debug("(X) -------------------------------------------") try: rc = self.__method(*args) except codes.FuncException, e: self.__log_exc() (t, v, tb) = sys.exc_info() rc = utils.nice_exception(t, v, tb) except: self.__log_exc() (t, v, tb) = sys.exc_info() rc = utils.nice_exception(t, v, tb) self.logger.debug("Return code for %s: %s" % (self.__name, rc)) return rc def serve(): """ Code for starting the XMLRPC service. """ server = FuncSSLXMLRPCServer(('', 51234)) server.logRequests = 0 # don't print stuff to console server.serve_forever() class FuncXMLRPCServer(SimpleXMLRPCServer.SimpleXMLRPCServer, XmlRpcInterface):
def minion_async_run(retriever, method, args, minion_query=None): """ This is a simpler invocation for minion side async usage. """ # to avoid confusion of job id's (we use the same job database) # minion jobs contain the string "minion". job_id = "%s-minion" % pprint.pformat(time.time()) __update_status(job_id, JOB_ID_RUNNING, -1) pid = os.fork() if pid != 0: os.waitpid(pid, 0) return job_id else: # daemonize! os.umask(077) os.chdir('/') os.setsid() if os.fork(): os._exit(0) try: fact_result = None if args and type(args[0]) == dict and args[0].has_key('__fact__'): fact_result = minion_query.exec_query(args[0]['__fact__'], True) else: function_ref = retriever(method) #here we will append the job_id at the end of the args list #so we can pull it via some decorator and use it for other #purposes like logginng and output tracking per method which #will be useful for lots of applications ... #if you are doing something useful with decorators per methods #be aware of that please ... args = list(args) args.append({'__logger__': True, 'job_id': job_id}) args = tuple(args) rc = function_ref(*args) if fact_result and fact_result[ 0]: #that means we have True from query so can go on function_ref = retriever(method) #here we will append the job_id at the end of the args list #so we can pull it via some decorator and use it for other #purposes like logginng and output tracking per method which #will be useful for lots of applications ... #if you are doing something useful with decorators per methods #be aware of that please ... args = list(args) args.append({'__logger__': True, 'job_id': job_id}) args = tuple(args) rc = function_ref(*args[1:]) rc = [{'__fact__': fact_result}, rc] elif fact_result and not fact_result[0]: rc = [{'__fact__': fact_result}] except Exception, e: (t, v, tb) = sys.exc_info() rc = cm_utils.nice_exception(t, v, tb) __update_status(job_id, JOB_ID_FINISHED, rc) os._exit(0)