Pingping Lin | d07e26c | 2016-09-06 23:06:01 +0000 | [diff] [blame] | 1 | import os |
| 2 | import sys |
| 3 | from django.db.models import Q, F |
Pingping Lin | c537fd9 | 2017-01-17 20:52:09 -0800 | [diff] [blame^] | 4 | from services.vpgwc.models import VPGWCService, VPGWCTenant |
Pingping Lin | d07e26c | 2016-09-06 23:06:01 +0000 | [diff] [blame] | 5 | from synchronizers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible |
| 6 | |
| 7 | parentdir = os.path.join(os.path.dirname(__file__), "..") |
| 8 | sys.path.insert(0, parentdir) |
| 9 | |
Pingping Lin | c537fd9 | 2017-01-17 20:52:09 -0800 | [diff] [blame^] | 10 | class SyncVPGWCTenant(SyncInstanceUsingAnsible): |
Pingping Lin | d07e26c | 2016-09-06 23:06:01 +0000 | [diff] [blame] | 11 | |
Pingping Lin | c537fd9 | 2017-01-17 20:52:09 -0800 | [diff] [blame^] | 12 | provides = [VPGWCTenant] |
Pingping Lin | d07e26c | 2016-09-06 23:06:01 +0000 | [diff] [blame] | 13 | |
Pingping Lin | c537fd9 | 2017-01-17 20:52:09 -0800 | [diff] [blame^] | 14 | observes = VPGWCTenant |
Pingping Lin | d07e26c | 2016-09-06 23:06:01 +0000 | [diff] [blame] | 15 | |
| 16 | requested_interval = 0 |
| 17 | |
| 18 | template_name = "sync_vpgwc.yaml" |
| 19 | |
| 20 | service_key_name = "/opt/xos/configurations/mcord/mcord_private_key" |
| 21 | |
| 22 | def __init__(self, *args, **kwargs): |
Pingping Lin | c537fd9 | 2017-01-17 20:52:09 -0800 | [diff] [blame^] | 23 | super(SyncVPGWCTenant, self).__init__(*args, **kwargs) |
Pingping Lin | d07e26c | 2016-09-06 23:06:01 +0000 | [diff] [blame] | 24 | |
| 25 | def fetch_pending(self, deleted): |
| 26 | |
| 27 | if (not deleted): |
Pingping Lin | c537fd9 | 2017-01-17 20:52:09 -0800 | [diff] [blame^] | 28 | objs = VPGWCTenant.get_tenant_objects().filter( |
Pingping Lin | d07e26c | 2016-09-06 23:06:01 +0000 | [diff] [blame] | 29 | Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False)) |
| 30 | else: |
| 31 | |
Pingping Lin | c537fd9 | 2017-01-17 20:52:09 -0800 | [diff] [blame^] | 32 | objs = VPGWCTenant.get_deleted_tenant_objects() |
Pingping Lin | d07e26c | 2016-09-06 23:06:01 +0000 | [diff] [blame] | 33 | |
| 34 | return objs |
| 35 | |
Pingping Lin | c537fd9 | 2017-01-17 20:52:09 -0800 | [diff] [blame^] | 36 | # Gets the attributes that are used by the Ansible template but are not |
| 37 | # part of the set of default attributes. |
Pingping Lin | d07e26c | 2016-09-06 23:06:01 +0000 | [diff] [blame] | 38 | def get_extra_attributes(self, o): |
| 39 | return {"display_message": o.display_message, "s5s8_pgw_tag": o.s5s8_pgw_tag} |