Matteo Scandolo | 86d6369 | 2017-08-08 13:05:26 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
Pingping Lin | d07e26c | 2016-09-06 23:06:01 +0000 | [diff] [blame] | 17 | import os |
| 18 | import sys |
| 19 | from django.db.models import Q, F |
Pingping Lin | c537fd9 | 2017-01-17 20:52:09 -0800 | [diff] [blame] | 20 | from services.vpgwc.models import VPGWCService, VPGWCTenant |
Pingping Lin | d07e26c | 2016-09-06 23:06:01 +0000 | [diff] [blame] | 21 | from synchronizers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible |
| 22 | |
| 23 | parentdir = os.path.join(os.path.dirname(__file__), "..") |
| 24 | sys.path.insert(0, parentdir) |
| 25 | |
Pingping Lin | c537fd9 | 2017-01-17 20:52:09 -0800 | [diff] [blame] | 26 | class SyncVPGWCTenant(SyncInstanceUsingAnsible): |
Pingping Lin | d07e26c | 2016-09-06 23:06:01 +0000 | [diff] [blame] | 27 | |
Pingping Lin | c537fd9 | 2017-01-17 20:52:09 -0800 | [diff] [blame] | 28 | provides = [VPGWCTenant] |
Pingping Lin | d07e26c | 2016-09-06 23:06:01 +0000 | [diff] [blame] | 29 | |
Pingping Lin | c537fd9 | 2017-01-17 20:52:09 -0800 | [diff] [blame] | 30 | observes = VPGWCTenant |
Pingping Lin | d07e26c | 2016-09-06 23:06:01 +0000 | [diff] [blame] | 31 | |
| 32 | requested_interval = 0 |
| 33 | |
| 34 | template_name = "sync_vpgwc.yaml" |
| 35 | |
| 36 | service_key_name = "/opt/xos/configurations/mcord/mcord_private_key" |
| 37 | |
| 38 | def __init__(self, *args, **kwargs): |
Pingping Lin | c537fd9 | 2017-01-17 20:52:09 -0800 | [diff] [blame] | 39 | super(SyncVPGWCTenant, self).__init__(*args, **kwargs) |
Pingping Lin | d07e26c | 2016-09-06 23:06:01 +0000 | [diff] [blame] | 40 | |
| 41 | def fetch_pending(self, deleted): |
| 42 | |
| 43 | if (not deleted): |
Pingping Lin | c537fd9 | 2017-01-17 20:52:09 -0800 | [diff] [blame] | 44 | objs = VPGWCTenant.get_tenant_objects().filter( |
Pingping Lin | d07e26c | 2016-09-06 23:06:01 +0000 | [diff] [blame] | 45 | Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False)) |
| 46 | else: |
| 47 | |
Pingping Lin | c537fd9 | 2017-01-17 20:52:09 -0800 | [diff] [blame] | 48 | objs = VPGWCTenant.get_deleted_tenant_objects() |
Pingping Lin | d07e26c | 2016-09-06 23:06:01 +0000 | [diff] [blame] | 49 | |
| 50 | return objs |
| 51 | |
Pingping Lin | c537fd9 | 2017-01-17 20:52:09 -0800 | [diff] [blame] | 52 | # Gets the attributes that are used by the Ansible template but are not |
| 53 | # part of the set of default attributes. |
Pingping Lin | d07e26c | 2016-09-06 23:06:01 +0000 | [diff] [blame] | 54 | def get_extra_attributes(self, o): |
Saleil Bhat | 4f45a4f | 2017-02-01 17:04:22 -0800 | [diff] [blame] | 55 | return {"display_message": o.display_message, |
| 56 | "s5s8_pgw_tag": o.s5s8_pgw_tag, |
| 57 | "image_name": o.image_name, |
| 58 | } |