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 | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 7 | from core.models.slice import Slice, ControllerSlices |
Andy Bavier | 5e243e1 | 2013-10-18 14:11:00 -0400 | [diff] [blame] | 8 | from util.logger import Logger, logging |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 9 | from observer.steps.sync_controller_slices 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 | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 18 | for controller_slice in ControllerSlices.objects.filter(slice=slice): |
Tony Mack | 29bf5e8 | 2014-04-29 21:40:24 -0400 | [diff] [blame] | 19 | # bump the 'updated' timestamp and trigger observer to update |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 20 | # slice across all controllers |
| 21 | controller_slice.save() |
Sapan Bhatia | 88a2369 | 2014-07-23 09:33:44 -0400 | [diff] [blame] | 22 | |
| 23 | def delete_record(self, slice): |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 24 | controller_slice_deleter = SyncControllerSlices().delete_record |
| 25 | for controller_slice in ControllerSlices.objects.filter(slice=slice): |
Sapan Bhatia | 88a2369 | 2014-07-23 09:33:44 -0400 | [diff] [blame] | 26 | try: |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 27 | controller_slice_deleter(controller_slice) |
Sapan Bhatia | 88a2369 | 2014-07-23 09:33:44 -0400 | [diff] [blame] | 28 | except Exception,e: |
Tony Mack | 336e0f9 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 29 | logger.log_exc("Failed to delete controller_slice %s" % controller_slice) |
Sapan Bhatia | 88a2369 | 2014-07-23 09:33:44 -0400 | [diff] [blame] | 30 | raise e |