blob: 138ac104f3bcac5138478cd4a3ad8f37dd1ca33e [file] [log] [blame]
Matteo Scandolo86d63692017-08-08 13:05:26 -07001
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 Lind07e26c2016-09-06 23:06:01 +000017import os
18import sys
19from django.db.models import Q, F
Pingping Linc537fd92017-01-17 20:52:09 -080020from services.vpgwc.models import VPGWCService, VPGWCTenant
Pingping Lind07e26c2016-09-06 23:06:01 +000021from synchronizers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
22
23parentdir = os.path.join(os.path.dirname(__file__), "..")
24sys.path.insert(0, parentdir)
25
Pingping Linc537fd92017-01-17 20:52:09 -080026class SyncVPGWCTenant(SyncInstanceUsingAnsible):
Pingping Lind07e26c2016-09-06 23:06:01 +000027
Pingping Linc537fd92017-01-17 20:52:09 -080028 provides = [VPGWCTenant]
Pingping Lind07e26c2016-09-06 23:06:01 +000029
Pingping Linc537fd92017-01-17 20:52:09 -080030 observes = VPGWCTenant
Pingping Lind07e26c2016-09-06 23:06:01 +000031
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 Linc537fd92017-01-17 20:52:09 -080039 super(SyncVPGWCTenant, self).__init__(*args, **kwargs)
Pingping Lind07e26c2016-09-06 23:06:01 +000040
41 def fetch_pending(self, deleted):
42
43 if (not deleted):
Pingping Linc537fd92017-01-17 20:52:09 -080044 objs = VPGWCTenant.get_tenant_objects().filter(
Pingping Lind07e26c2016-09-06 23:06:01 +000045 Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False))
46 else:
47
Pingping Linc537fd92017-01-17 20:52:09 -080048 objs = VPGWCTenant.get_deleted_tenant_objects()
Pingping Lind07e26c2016-09-06 23:06:01 +000049
50 return objs
51
Pingping Linc537fd92017-01-17 20:52:09 -080052 # Gets the attributes that are used by the Ansible template but are not
53 # part of the set of default attributes.
Pingping Lind07e26c2016-09-06 23:06:01 +000054 def get_extra_attributes(self, o):
Saleil Bhat4f45a4f2017-02-01 17:04:22 -080055 return {"display_message": o.display_message,
56 "s5s8_pgw_tag": o.s5s8_pgw_tag,
57 "image_name": o.image_name,
58 }