Skip to content

Commit

Permalink
Add require support to state.py, needs testing
Browse files Browse the repository at this point in the history
  • Loading branch information
thatch45 committed May 16, 2011
1 parent 9eade72 commit b756fbe
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions salt/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self, opts):
self.functions = salt.loader.minion_mods(self.opts)
self.states = salt.loader.states(self.opts, self.functions)
self.rend = salt.loader.render(self.opts, self.functions)
self.running = {}

def verify_data(self, data):
'''
Expand Down Expand Up @@ -177,6 +178,70 @@ def call(self, data):
cdata = self.format_call(data)
return self.states[cdata['full']](*cdata['args'])

def call_chunks(self, chunks):
'''
Itterate over a list of chunks and call them, checking for requires.
'''
running = {}
for low in chunks:
running = self.call_chunk(low, running, chunks)
return running

def check_requires(self, low, running, chunks):
'''
Look into the running data to see if the requirement has been met
'''
if not low.has_key('require'):
return 'met'
reqs = []
status = 'unmet'
for req in low['require']:
for chunk in chunks:
if chunk['name'] == req[req.keys()[0]]:
if chunk['state'] == req.keys()[0]:
reqs.append(chunk)
fun_stats = []
for req in reqs:
tag = req['state'] + '.' + req['name'] + '.' + req['fun']
if not running.has_key(tag):
fun_stats.append('unmet')
else:
fun_stats.append('met' if running[tag]['result'] else 'fail')
for stat in fun_stats:
if stat == 'unmet':
return stat
elif stat == 'fail':
return stat
return 'met'

def call_chunk(self, low, running, chunks):
'''
Check if a chunk has any requires, execute the requires and then the
chunk
'''
tag = low['state'] + '.' + low['name'] + '.' + low['fun']
if low.has_key('require'):
status = self.check_requires(low, running, chunks)
if status == 'unmet':
reqs = []
for req in low['require']:
for chunk in chunks:
if chunk['name'] == req[req.keys()[0]]:
if chunk['state'] == req.keys()[0]:
reqs.append(chunk)
for chunk in reqs:
running = self.call_chunk(chunk, running, chunks)
running = self.call_chunk(low, running, chunks)
elif status == 'met':
running[tag] = call(low)
elif status == 'fail':
running[tag] = {'changes': None,
'result': False,
'comment': 'One or more require failed'}
else:
running[tag] = call(low)
return running

def call_high(self, high):
'''
Process a high data call and ensure the defined states.
Expand Down

0 comments on commit b756fbe

Please sign in to comment.