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 | |
| 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 Bhat | 22afba8 | 2017-01-21 23:10:09 -0800 | [diff] [blame] | 53 | fields['image_name'] = o.image_name |
Saleil Bhat | 1c5593d | 2017-01-06 15:25:57 -0800 | [diff] [blame] | 54 | return fields |
| 55 | |