summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCasey Dahlin <cdahlin@redhat.com>2009-01-03 01:09:24 -0500
committerCasey Dahlin <cdahlin@redhat.com>2009-01-03 01:09:24 -0500
commit27694a79fef776a949cd6b4b255963fc13c72572 (patch)
tree94b7417fe1ba66da87b673483219e87342b03db1
parent1f4da394363e5a26750c5d044deba2762a15cff6 (diff)
downloadupstate-27694a79fef776a949cd6b4b255963fc13c72572.tar.gz
upstate-27694a79fef776a949cd6b4b255963fc13c72572.tar.xz
upstate-27694a79fef776a949cd6b4b255963fc13c72572.zip
Add bring_down method to state machine, complete with depsolve
-rw-r--r--statemachine.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/statemachine.py b/statemachine.py
index 54a325c..a708e5b 100644
--- a/statemachine.py
+++ b/statemachine.py
@@ -67,6 +67,21 @@ class StateMachine:
return
self.up.add(cat)
+ def bring_down(self, cat):
+ """
+ Bring a currently "up" state down.
+ """
+ to_drop = set([ x for x in self.up if x.subset_of(cat) ])
+ if None in to_drop: to_drop.remove(None)
+ if len(to_drop) == 0: return False
+ for (dependent, dependency) in self.deps:
+ match = set([dependency.intersect(x) for x in to_drop])
+ if None in match: match.remove(None)
+ if match != None:
+ for item in match:
+ self.bring_down(dependent.fill(item.args))
+ self.up -= to_drop
+
def get_satisfied_states(self, dependents, dependencies):
"""
Given that states in `dependents` depend on states in `dependencies`,
@@ -107,3 +122,6 @@ if __name__ == "__main__":
sm.bring_up(Category("found_disk", uuid=Pattern(True, "d3adb3ef"), devname=Pattern(True, "/dev/sda"), label=Pattern(True, "myroot")))
sm.bring_up(Category("mounted", uuid=Pattern(False), type=Pattern(False), devname=Pattern(False), label=Pattern(False), mountpoint=Pattern(False)))
print sm
+ print "--"
+ sm.bring_down(Category("network_up"))
+ print sm