Merge branch 'ordering' into develop

This commit is contained in:
Thomas S Hatch 2011-11-24 18:08:47 -07:00
commit 5a8f7eab45
2 changed files with 60 additions and 2 deletions

View file

@ -0,0 +1,32 @@
===============
Ordering States
===============
When creating salt sls files, it is often important to ensure that they run in
a specific order. While states will always execute in the same order, that
order is not nessisarily defined the way you want it.
A few tools exist in Salt to set up the corect state ordering, these tools
consist of requisite declarations and order options.
The Order Option
================
Before using the order option, remember that the majority of state ordering
should be done with requisite statements, and that a requisite statement
will override an order option.
The order option is used by adding an order number to a state declaration
with the option `order`:
.. code-block:: yaml
vim:
pkg:
- installed
- order: 1
By adding the order option to `1` this ensures that the vim package will be
installed in tandem with any other state declaration set to the order `1`.
Any state declared without an order option will be executed after all states
with order options are executed.

View file

@ -209,6 +209,32 @@ class State(object):
err += self.verify_data(chunk)
return err
def order_chunks(self, chunks):
'''
Sort the chunk list verifying that the chunks follow the order
specified in the order options.
'''
cap = 1
for chunk in chunks:
if 'order' in chunk:
if chunk['order'] > cap - 1:
cap = chunk['order'] + 100
for chunk in chunks:
if not 'order' in chunk:
chunk['order'] = cap
else:
if not isinstance(chunk['order'], int):
chunk['order'] = cap
chunks = sorted(
chunks,
key=lambda k:'{0[state]}{0[name]}{0[fun]}'.format(k)
)
chunks = sorted(
chunks,
key=lambda k: k['order']
)
return chunks
def format_call(self, data):
'''
Formats low data into a list of dict's used to actually call the state,
@ -292,8 +318,8 @@ class State(object):
for fun in funcs:
live['fun'] = fun
chunks.append(live)
return sorted(chunks, key=lambda k: k['state'] + k['name'] + k['fun'])
chunks = self.order_chunks(chunks)
return chunks
def reconcile_extend(self, high):
'''