Yunpeng Zhang | d01f3ce | 2017-07-06 20:06:35 -0400 | [diff] [blame] | 1 | import os |
| 2 | import sys |
| 3 | from django.db.models import Q, F |
| 4 | # from services.vbbu.models import MCORDService, VBBUTenant |
| 5 | from synchronizers.new_base.modelaccessor import * |
| 6 | from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible |
| 7 | |
| 8 | parentdir = os.path.join(os.path.dirname(__file__), "..") |
| 9 | sys.path.insert(0, parentdir) |
| 10 | |
| 11 | class SyncVBBUTenant(SyncInstanceUsingAnsible): |
Yunpeng Zhang | d01f3ce | 2017-07-06 20:06:35 -0400 | [diff] [blame] | 12 | provides = [VBBUTenant] |
| 13 | |
| 14 | observes = VBBUTenant |
| 15 | |
| 16 | requested_interval = 0 |
| 17 | |
| 18 | template_name = "vbbutenant_playbook.yaml" |
| 19 | |
| 20 | service_key_name = "/opt/xos/configurations/mcord/mcord_private_key" |
| 21 | |
| 22 | def __init__(self, *args, **kwargs): |
| 23 | super(SyncVBBUTenant, self).__init__(*args, **kwargs) |
| 24 | |
| 25 | def fetch_pending(self, deleted): |
Yunpeng Zhang | d01f3ce | 2017-07-06 20:06:35 -0400 | [diff] [blame] | 26 | if (not deleted): |
| 27 | objs = VBBUTenant.get_tenant_objects().filter( |
| 28 | Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False)) |
| 29 | else: |
Yunpeng Zhang | d01f3ce | 2017-07-06 20:06:35 -0400 | [diff] [blame] | 30 | objs = VBBUTenant.get_deleted_tenant_objects() |
| 31 | |
| 32 | return objs |
| 33 | |