blob: 7147e3ff1dceb6a18a25070da5a19d0c758ce1c6 [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
21 service_key_name = "/opt/xos/synchronizers/vmme/vmme_private_key"
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
37 def get_vmmeservice(self, o):
38 if not o.provider_service:
39 return None
40
41 vmmeservice = VMMEService.get_service_objects().filter(id=o.provider_service.id)
42
43 if not vmmeservice:
44 return None
45
46 return vmmeservice[0]
47
48 # Gets the attributes that are used by the Ansible template but are not
49 # part of the set of default attributes.
50 def get_extra_attributes(self, o):
51 fields = {}
52 fields['tenant_message'] = o.tenant_message
Saleil Bhat22afba82017-01-21 23:10:09 -080053 fields['image_name'] = o.image_name
Saleil Bhat1c5593d2017-01-06 15:25:57 -080054 return fields
55