Skip to content

Commit

Permalink
Add a destroy_before function to allow resources to specify which res…
Browse files Browse the repository at this point in the history
…ources should be destroyed after them

Signed-off-by: Shea Levy <[email protected]>
  • Loading branch information
shlevy authored and rbvermaa committed Oct 7, 2013
1 parent b93e2de commit cb7d3d5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions nixops/deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -941,10 +941,24 @@ def destroy_resources(self, include=[], exclude=[], wipe=False):
"""Destroy all active or obsolete resources."""

with self._get_deployment_lock():
for r in self.resources.itervalues():
r._destroyed_event = threading.Event()
for rev_dep in r.destroy_before(self.resources.itervalues()):
try:
rev_dep._wait_for.append(r)
except AttributeError:
rev_dep._wait_for = [ r ]

def worker(m):
if not should_do(m, include, exclude): return
try:
for dep in m._wait_for:
if should_do(dep, include, exclude):
dep._destroyed_event.wait()
except AttributeError:
pass
if m.destroy(wipe=wipe): self.delete_resource(m)
m._destroyed_event.set()

nixops.parallel.run_tasks(nr_workers=-1, tasks=self.resources.values(), worker_fun=worker)

Expand Down
4 changes: 4 additions & 0 deletions nixops/resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ def create_after(self, resources):
"""Return a set of resources that should be created before this one."""
return {}

def destroy_before(self, resources):
"""Return a set of resources that should be destroyed after this one."""
return self.create_after(resources)

def create(self, defn, check, allow_reboot, allow_recreate):
"""Create or update the resource defined by ‘defn’."""
assert False
Expand Down

0 comments on commit cb7d3d5

Please sign in to comment.