blob: 80685e9b5f574e3cab05905477ed5d4467fcb84a [file] [log] [blame]
Scott Baker619de672016-06-20 12:49:38 -07001import os
2import sys
3from django.db.models import Q, F
Srikanth Vavilapalli2c41ab32016-11-17 03:14:30 +00004from core.models import ModelLink, CoarseTenant
Scott Baker619de672016-06-20 12:49:38 -07005from services.exampleservice.models import ExampleService, ExampleTenant
6from synchronizers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
7
8parentdir = os.path.join(os.path.dirname(__file__), "..")
9sys.path.insert(0, parentdir)
10
11class SyncExampleTenant(SyncInstanceUsingAnsible):
12
13 provides = [ExampleTenant]
14
15 observes = ExampleTenant
16
17 requested_interval = 0
18
19 template_name = "exampletenant_playbook.yaml"
20
21 service_key_name = "/opt/xos/synchronizers/exampleservice/exampleservice_private_key"
22
Srikanth Vavilapalli2c41ab32016-11-17 03:14:30 +000023 watches = [ModelLink(CoarseTenant,via='coarsetenant')]
24
Scott Baker619de672016-06-20 12:49:38 -070025 def __init__(self, *args, **kwargs):
26 super(SyncExampleTenant, self).__init__(*args, **kwargs)
27
28 def fetch_pending(self, deleted):
29
30 if (not deleted):
31 objs = ExampleTenant.get_tenant_objects().filter(
32 Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False))
33 else:
34 # If this is a deletion we get all of the deleted tenants..
35 objs = ExampleTenant.get_deleted_tenant_objects()
36
37 return objs
38
39 def get_exampleservice(self, o):
40 if not o.provider_service:
41 return None
42
43 exampleservice = ExampleService.get_service_objects().filter(id=o.provider_service.id)
44
45 if not exampleservice:
46 return None
47
48 return exampleservice[0]
49
50 # Gets the attributes that are used by the Ansible template but are not
51 # part of the set of default attributes.
52 def get_extra_attributes(self, o):
53 fields = {}
54 fields['tenant_message'] = o.tenant_message
55 exampleservice = self.get_exampleservice(o)
56 fields['service_message'] = exampleservice.service_message
57 return fields
58
Scott Baker9b1a3eb2017-01-23 14:46:27 -080059 def delete_record(self, port):
60 # Nothing needs to be done to delete an exampleservice; it goes away
61 # when the instance holding the exampleservice is deleted.
62 pass
63