Saleil Bhat | 1c5593d | 2017-01-06 15:25:57 -0800 | [diff] [blame] | 1 | import os |
| 2 | import sys |
| 3 | from django.db.models import Q, F |
Pingping Lin | 4cc1fae | 2017-06-09 17:42:02 -0700 | [diff] [blame] | 4 | #from services.vmme.models import VMMEService, VMMETenant |
| 5 | from synchronizers.new_base.modelaccessor import * |
| 6 | from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible |
Saleil Bhat | 1c5593d | 2017-01-06 15:25:57 -0800 | [diff] [blame] | 7 | |
| 8 | parentdir = os.path.join(os.path.dirname(__file__), "..") |
| 9 | sys.path.insert(0, parentdir) |
| 10 | |
| 11 | class SyncVMMETenant(SyncInstanceUsingAnsible): |
| 12 | |
| 13 | provides = [VMMETenant] |
| 14 | |
| 15 | observes = VMMETenant |
| 16 | |
| 17 | requested_interval = 0 |
| 18 | |
| 19 | template_name = "vmmetenant_playbook.yaml" |
| 20 | |
Omar Abdelkader | 2c16284 | 2017-08-07 19:41:59 -0600 | [diff] [blame^] | 21 | service_key_name = "/opt/xos/configurations/mcord/mcord_private_key" |
Saleil Bhat | 1c5593d | 2017-01-06 15:25:57 -0800 | [diff] [blame] | 22 | |
| 23 | def __init__(self, *args, **kwargs): |
| 24 | super(SyncVMMETenant, self).__init__(*args, **kwargs) |
| 25 | |
| 26 | def fetch_pending(self, deleted): |
| 27 | |
| 28 | if (not deleted): |
| 29 | objs = VMMETenant.get_tenant_objects().filter( |
| 30 | Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False)) |
| 31 | else: |
| 32 | # If this is a deletion we get all of the deleted tenants.. |
| 33 | objs = VMMETenant.get_deleted_tenant_objects() |
| 34 | |
| 35 | return objs |
| 36 | |
Saleil Bhat | 1c5593d | 2017-01-06 15:25:57 -0800 | [diff] [blame] | 37 | # Gets the attributes that are used by the Ansible template but are not |
| 38 | # part of the set of default attributes. |
| 39 | def get_extra_attributes(self, o): |
| 40 | fields = {} |
| 41 | fields['tenant_message'] = o.tenant_message |
Saleil Bhat | 1c5593d | 2017-01-06 15:25:57 -0800 | [diff] [blame] | 42 | return fields |
| 43 | |