mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 01:18:58 +00:00
add fire_event
option to salt state compiler
Adding `- fire_event: True` to a state will cause an event to be sent with the event `name` in the tag and the state return as the event data. Adding `- fire_event: my/custom/event/tag` to a state will cause an event to be sent with 'my/custom/event/tag` in the tag and the state return as the event data.
This commit is contained in:
parent
c5b46d05c3
commit
4a7b686557
@ -1775,16 +1775,36 @@ class State(object):
|
||||
|
||||
return status, reqs
|
||||
|
||||
def event(self, chunk_ret, length):
|
||||
def event(self, chunk_ret, length, fire_event_flag=False):
|
||||
'''
|
||||
Fire an event on the master bus
|
||||
|
||||
If `fire_event_flag` is set to True an event will be sent with the
|
||||
chunk name in the tag and the chunk result in the event data.
|
||||
|
||||
If `fire_event_flag` is set to a string such as `mystate/is/finished`,
|
||||
an event will be sent with the string added to the tag and the chunk
|
||||
result in the event data.
|
||||
|
||||
If the `state_events` is set to True in the config, then after the
|
||||
chunk is evaluated an event will be set up to the master with the
|
||||
results.
|
||||
'''
|
||||
if not self.opts.get('local') and self.opts.get('state_events', True) and self.opts.get('master_uri'):
|
||||
ret = {'ret': chunk_ret,
|
||||
'len': length}
|
||||
tag = salt.utils.event.tagify(
|
||||
[self.jid, 'prog', self.opts['id'], str(chunk_ret['__run_num__'])], 'job'
|
||||
)
|
||||
if not self.opts.get('local') and (self.opts.get('state_events', True) or fire_event_flag) and self.opts.get('master_uri'):
|
||||
ret = {'ret': chunk_ret}
|
||||
if fire_event_flag is True:
|
||||
tag = salt.utils.event.tagify(
|
||||
[self.jid, self.opts['id'], str(chunk_ret['name'])], 'state_result'
|
||||
)
|
||||
elif isinstance(fire_event_flag, six.string_types):
|
||||
tag = salt.utils.event.tagify(
|
||||
[self.jid, self.opts['id'], str(fire_event_flag)], 'state_result'
|
||||
)
|
||||
else:
|
||||
tag = salt.utils.event.tagify(
|
||||
[self.jid, 'prog', self.opts['id'], str(chunk_ret['__run_num__'])], 'job'
|
||||
)
|
||||
ret['len'] = length
|
||||
preload = {'jid': self.jid}
|
||||
self.functions['event.fire_master'](ret, tag, preload=preload)
|
||||
|
||||
@ -1856,7 +1876,7 @@ class State(object):
|
||||
'__run_num__': self.__run_num,
|
||||
'__sls__': low['__sls__']}
|
||||
self.__run_num += 1
|
||||
self.event(running[tag], len(chunks))
|
||||
self.event(running[tag], len(chunks), fire_event_flag=low.get('fire_event'))
|
||||
return running
|
||||
for chunk in reqs:
|
||||
# Check to see if the chunk has been run, only run it if
|
||||
@ -1881,7 +1901,7 @@ class State(object):
|
||||
'__run_num__': self.__run_num,
|
||||
'__sls__': low['__sls__']}
|
||||
self.__run_num += 1
|
||||
self.event(running[tag], len(chunks))
|
||||
self.event(running[tag], len(chunks), fire_event_flag=low.get('fire_event'))
|
||||
return running
|
||||
running = self.call_chunk(chunk, running, chunks)
|
||||
if self.check_failhard(chunk, running):
|
||||
@ -1980,7 +2000,7 @@ class State(object):
|
||||
else:
|
||||
running[tag] = self.call(low, chunks, running)
|
||||
if tag in running:
|
||||
self.event(running[tag], len(chunks))
|
||||
self.event(running[tag], len(chunks), fire_event_flag=low.get('fire_event'))
|
||||
return running
|
||||
|
||||
def call_listen(self, chunks, running):
|
||||
|
Loading…
Reference in New Issue
Block a user