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 |
Saleil Bhat | fda62d4 | 2017-02-18 15:07:23 -0800 | [diff] [blame^] | 4 | from services.vmme.models import VMMEService, VMMETenant |
Saleil Bhat | 1c5593d | 2017-01-06 15:25:57 -0800 | [diff] [blame] | 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 SyncVMMETenant(SyncInstanceUsingAnsible): |
| 11 | |
| 12 | provides = [VMMETenant] |
| 13 | |
| 14 | observes = VMMETenant |
| 15 | |
| 16 | requested_interval = 0 |
| 17 | |
| 18 | template_name = "vmmetenant_playbook.yaml" |
| 19 | |
| 20 | service_key_name = "/opt/xos/synchronizers/vmme/vmme_private_key" |
| 21 | |
| 22 | def __init__(self, *args, **kwargs): |
| 23 | super(SyncVMMETenant, self).__init__(*args, **kwargs) |
| 24 | |
| 25 | def fetch_pending(self, deleted): |
| 26 | |
| 27 | if (not deleted): |
| 28 | objs = VMMETenant.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 = VMMETenant.get_deleted_tenant_objects() |
| 33 | |
| 34 | return objs |
| 35 | |
| 36 | def get_vmmeservice(self, o): |
| 37 | if not o.provider_service: |
| 38 | return None |
| 39 | |
| 40 | vmmeservice = VMMEService.get_service_objects().filter(id=o.provider_service.id) |
| 41 | |
| 42 | if not vmmeservice: |
| 43 | return None |
| 44 | |
| 45 | return vmmeservice[0] |
| 46 | |
| 47 | # Gets the attributes that are used by the Ansible template but are not |
| 48 | # part of the set of default attributes. |
| 49 | def get_extra_attributes(self, o): |
| 50 | fields = {} |
| 51 | fields['tenant_message'] = o.tenant_message |
Saleil Bhat | 22afba8 | 2017-01-21 23:10:09 -0800 | [diff] [blame] | 52 | fields['image_name'] = o.image_name |
Saleil Bhat | 1c5593d | 2017-01-06 15:25:57 -0800 | [diff] [blame] | 53 | return fields |
| 54 | |