Sapan Bhatia | 24836f1 | 2013-08-27 10:16:05 -0400 | [diff] [blame] | 1 | import os |
| 2 | import base64 |
Tony Mack | 0ae3fe3 | 2013-10-08 08:47:53 -0400 | [diff] [blame] | 3 | from netaddr import IPAddress, IPNetwork |
Tony Mack | ae7f30c | 2013-09-25 12:46:50 -0400 | [diff] [blame] | 4 | from django.db.models import F, Q |
Sapan Bhatia | 24836f1 | 2013-08-27 10:16:05 -0400 | [diff] [blame] | 5 | from planetstack.config import Config |
Sapan Bhatia | 04c94ad | 2013-09-02 18:00:28 -0400 | [diff] [blame] | 6 | from observer.openstacksyncstep import OpenStackSyncStep |
Tony Mack | 29bf5e8 | 2014-04-29 21:40:24 -0400 | [diff] [blame] | 7 | from core.models.slice import Slice, SliceDeployments |
Andy Bavier | 5e243e1 | 2013-10-18 14:11:00 -0400 | [diff] [blame] | 8 | from util.logger import Logger, logging |
Sapan Bhatia | df8fda3 | 2014-08-19 02:59:34 -0400 | [diff] [blame] | 9 | from observer.steps.sync_slice_deployments import * |
Andy Bavier | 5e243e1 | 2013-10-18 14:11:00 -0400 | [diff] [blame] | 10 | |
Andy Bavier | 33584c5 | 2013-10-28 15:17:16 -0400 | [diff] [blame] | 11 | logger = Logger(level=logging.INFO) |
Sapan Bhatia | 24836f1 | 2013-08-27 10:16:05 -0400 | [diff] [blame] | 12 | |
| 13 | class SyncSlices(OpenStackSyncStep): |
Tony Mack | dacfb98 | 2013-09-24 21:57:16 -0400 | [diff] [blame] | 14 | provides=[Slice] |
| 15 | requested_interval=0 |
Tony Mack | 66646d5 | 2013-09-24 21:47:12 -0400 | [diff] [blame] | 16 | |
Tony Mack | dacfb98 | 2013-09-24 21:57:16 -0400 | [diff] [blame] | 17 | def sync_record(self, slice): |
Tony Mack | 29bf5e8 | 2014-04-29 21:40:24 -0400 | [diff] [blame] | 18 | for slice_deployment in SliceDeployments.objects.filter(slice=slice): |
| 19 | # bump the 'updated' timestamp and trigger observer to update |
| 20 | # slice across all deployments |
| 21 | slice_deployment.save() |
Sapan Bhatia | 88a2369 | 2014-07-23 09:33:44 -0400 | [diff] [blame] | 22 | |
| 23 | def delete_record(self, slice): |
Sapan Bhatia | df8fda3 | 2014-08-19 02:59:34 -0400 | [diff] [blame] | 24 | slice_deployment_deleter = SyncSliceDeployments().delete_record |
Sapan Bhatia | 88a2369 | 2014-07-23 09:33:44 -0400 | [diff] [blame] | 25 | for slice_deployment in SliceDeployments.objects.filter(slice=slice): |
| 26 | try: |
Sapan Bhatia | df8fda3 | 2014-08-19 02:59:34 -0400 | [diff] [blame] | 27 | slice_deployment_deleter(slice_deployment) |
Sapan Bhatia | 88a2369 | 2014-07-23 09:33:44 -0400 | [diff] [blame] | 28 | except Exception,e: |
| 29 | logger.log_exc("Failed to delete slice_deployment %s" % slice_deployment) |
| 30 | raise e |