本文整理汇总了Python中handler.Handler.handle_publish方法的典型用法代码示例。如果您正苦于以下问题:Python Handler.handle_publish方法的具体用法?Python Handler.handle_publish怎么用?Python Handler.handle_publish使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类handler.Handler
的用法示例。
在下文中一共展示了Handler.handle_publish方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: SaltJob
# 需要导入模块: from handler import Handler [as 别名]
# 或者: from handler.Handler import handle_publish [as 别名]
class SaltJob(object):
"""
Holds information pertaining to a salt job
"""
# Maps salt functions to validate functions in this class
validate_funcs = {
'state.sls': 'validate_state_sls'
}
def __init__(self, command_kwargs, retcodes=None, chain=None):
"""
Salt job constructor
@param command_kwargs - Kwarg dictionary to send to an APIClient
@param retcodes - Set of acceptable process return codes. If none
provided, only retcode 0 will be acceptable
@param chain - Optional salt job to link this job to in sequence
"""
# Kwargs passed to the salt api client
self.kwargs = command_kwargs
# Acceptable return codes
self.goodcodes = retcodes or set([0])
# Next in a sequence of SaltJob's
self.chain = chain
# Job id created by publish
self.jid = None
# Minions identified by publish
self.minions = None
# Minions that have finished so far
self.finished_minions = set()
# Response
self.ret = {}
# Events collected from salt
self.events = {}
# Handler - raises exceptions and output
self.handler = Handler()
def link(self, next_):
"""
Links next_ to the end of the sequence of salt jobs this job is in.
@param next_ - SaltJob to append to end of sequence.
"""
current = self
while current.chain is not None:
current = current.chain
current.chain = next_
def is_finished(self):
"""
Computes the difference between the set of expected minions and the
set of minions that have returned so far. The job is finished when
there are no minions in the difference set.
@param return Boolean True for yes, Boolean false otherwise
"""
return self.minions.issubset(self.finished_minions)
def set_pub_data(self, pub_data):
"""
Handles the publish data returned from a call to run on an APIClient
object
@param pub_data - Dictionary containing affected minion ids and a jid
or an empty dict representing a publish failure
"""
# Check for bad publish, emit any output
self.handler.handle_publish(self, pub_data)
# Set jid and minions
self.jid = pub_data['jid']
self.minions = set(pub_data['minions'])
def add_minion_return(self, raw):
"""
Adds a minion return or an event to the tracked data.
The return/event must have the fields 'id' and 'return' to be
considered part of the job's response
@param raw - Dictionary representing event or minion return
"""
if raw is not None:
# Save the event
self.events[raw['id']] = raw
if 'return' in raw:
self.finished_minions.add(raw['id'])
self.ret[raw['id']] = raw['return']
def validate_func(self):
"""
Returns a validate function or none based upon the salt function
used. Example: state.sls in salt has some special output that needs
to be validated a little differently.
@return - A validating function or None
#.........这里部分代码省略.........