Gabe Black | 4c040b7 | 2016-11-17 22:35:04 +0000 | [diff] [blame] | 1 | import os |
| 2 | import sys |
| 3 | from django.db.models import Q, F |
| 4 | from services.activetest.models import VtaTenant |
| 5 | from synchronizers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible |
| 6 | |
| 7 | parentdir = os.path.join(os.path.dirname(__file__), "..") |
| 8 | sys.path.insert(0, parentdir) |
| 9 | |
| 10 | class SyncVtaTenant(SyncInstanceUsingAnsible): |
| 11 | |
| 12 | provides = [VtaTenant] |
| 13 | |
| 14 | observes = VtaTenant |
| 15 | |
| 16 | requested_interval = 0 |
| 17 | |
| 18 | template_name = "vtatenant_playbook.yaml" |
| 19 | |
| 20 | service_key_name = "/opt/xos/synchronizers/activetest/activetest_private_key" |
| 21 | |
| 22 | def __init__(self, *args, **kwargs): |
| 23 | super(SyncVtaTenant, self).__init__(*args, **kwargs) |
| 24 | |
| 25 | def fetch_pending(self, deleted): |
| 26 | |
| 27 | if (not deleted): |
| 28 | objs = VtaTenant.get_tenant_objects().filter( |
| 29 | Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False)) |
| 30 | else: |
| 31 | # If this is a deletion we get all of the deleted tenants.. |
| 32 | objs = VtaTenant.get_deleted_tenant_objects() |
| 33 | |
| 34 | return objs |
| 35 | |
| 36 | # Gets the attributes that are used by the Ansible template but are not |
| 37 | # part of the set of default attributes. |
| 38 | def get_extra_attributes(self, o): |
| 39 | return { "private_ip":o.private_ip, |
| 40 | "public_ip":o.public_ip, |
| 41 | "controller_ip":o.controller_ip |
| 42 | } |
| 43 | |
| 44 | |