Matteo Scandolo | 41ed099 | 2017-08-08 13:05:27 -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 | |
JianHao | ce45e04 | 2017-01-16 11:06:29 +0000 | [diff] [blame] | 17 | import os |
| 18 | import sys |
| 19 | from django.db.models import Q, F |
| 20 | from services.vsgw.models import VSGWService, VSGWTenant |
| 21 | from synchronizers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible |
| 22 | |
| 23 | parentdir = os.path.join(os.path.dirname(__file__), "..") |
| 24 | sys.path.insert(0, parentdir) |
| 25 | |
| 26 | class SyncVSGWTenant(SyncInstanceUsingAnsible): |
| 27 | |
| 28 | provides = [VSGWTenant] |
| 29 | |
| 30 | observes = VSGWTenant |
| 31 | |
| 32 | requested_interval = 0 |
| 33 | |
| 34 | template_name = "sync_vsgw.yaml" |
| 35 | |
| 36 | service_key_name = "/opt/xos/synchronizers/vsgw/vsgw_private_key" |
| 37 | |
| 38 | def __init__(self, *args, **kwargs): |
| 39 | super(SyncVSGWTenant, self).__init__(*args, **kwargs) |
| 40 | |
| 41 | def fetch_pending(self, deleted): |
| 42 | |
| 43 | if (not deleted): |
| 44 | objs = VSGWTenant.get_tenant_objects().filter( |
| 45 | Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False)) |
| 46 | else: |
| 47 | # If this is a deletion we get all of the deleted tenants.. |
| 48 | objs = VSGWTenant.get_deleted_tenant_objects() |
| 49 | |
| 50 | return objs |
| 51 | |
| 52 | def get_extra_attributes(self, o): |
| 53 | fields = {} |
| 54 | fields['tenant_message'] = o.tenant_message |
Saleil Bhat | 42e8c5e | 2017-02-01 15:59:54 -0800 | [diff] [blame] | 55 | fields['image_name'] = o.image_name |
JianHao | ce45e04 | 2017-01-16 11:06:29 +0000 | [diff] [blame] | 56 | return fields |
| 57 | |