blob: ebb1ef380d7b111f4e0e2c2d412cb54ecd467bdb [file] [log] [blame]
Saleil Bhat1c5593d2017-01-06 15:25:57 -08001import os
2import sys
3from django.db.models import Q, F
Pingping Lin4cc1fae2017-06-09 17:42:02 -07004#from services.vmme.models import VMMEService, VMMETenant
5from synchronizers.new_base.modelaccessor import *
6from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
Saleil Bhat1c5593d2017-01-06 15:25:57 -08007
8parentdir = os.path.join(os.path.dirname(__file__), "..")
9sys.path.insert(0, parentdir)
10
11class SyncVMMETenant(SyncInstanceUsingAnsible):
12
13 provides = [VMMETenant]
14
15 observes = VMMETenant
16
17 requested_interval = 0
18
19 template_name = "vmmetenant_playbook.yaml"
20
Omar Abdelkader2c162842017-08-07 19:41:59 -060021 service_key_name = "/opt/xos/configurations/mcord/mcord_private_key"
Saleil Bhat1c5593d2017-01-06 15:25:57 -080022
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 Bhat1c5593d2017-01-06 15:25:57 -080037 # 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 Bhat1c5593d2017-01-06 15:25:57 -080042 return fields
43