Tony Mack | bdb188a | 2014-04-01 20:24:47 -0400 | [diff] [blame] | 1 | from core.models import Slice, SliceDeployments, User |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 2 | from observer.deleter import Deleter |
Tony Mack | 79e78c8 | 2014-04-12 10:26:15 -0400 | [diff] [blame] | 3 | from observer.deleters.slice_deployment_deleter import SliceDeploymentDeleter |
| 4 | from util.logger import Logger, logging |
| 5 | |
| 6 | logger = Logger(level=logging.INFO) |
Sapan Bhatia | dbaf193 | 2013-09-03 11:28:52 -0400 | [diff] [blame] | 7 | |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 8 | class SliceDeleter(Deleter): |
Tony Mack | f77f140 | 2014-04-02 07:06:53 -0400 | [diff] [blame] | 9 | model='Slice' |
Sapan Bhatia | dbaf193 | 2013-09-03 11:28:52 -0400 | [diff] [blame] | 10 | |
Tony Mack | f77f140 | 2014-04-02 07:06:53 -0400 | [diff] [blame] | 11 | def call(self, pk): |
| 12 | slice = Slice.objects.get(pk=pk) |
Tony Mack | 79e78c8 | 2014-04-12 10:26:15 -0400 | [diff] [blame] | 13 | slice_deployment_deleter = SliceDeploymentDeleter() |
| 14 | for slice_deployment in SliceDeployments.objects.filter(slice=slice): |
| 15 | try: |
| 16 | slice_deployment_deleter(slice_deployment.id) |
| 17 | except: |
| 18 | logger.log_exc("Failed to delete slice_deployment %s" % slice_deployment) |
Tony Mack | 387a73f | 2013-09-18 07:59:14 -0400 | [diff] [blame] | 19 | slice.delete() |