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): |
| 12 | |
| 13 | |
| 14 | provides = [VBBUTenant] |
| 15 | |
| 16 | observes = VBBUTenant |
| 17 | |
| 18 | requested_interval = 0 |
| 19 | |
| 20 | template_name = "vbbutenant_playbook.yaml" |
| 21 | |
| 22 | service_key_name = "/opt/xos/configurations/mcord/mcord_private_key" |
| 23 | |
| 24 | def __init__(self, *args, **kwargs): |
| 25 | super(SyncVBBUTenant, self).__init__(*args, **kwargs) |
| 26 | |
| 27 | def fetch_pending(self, deleted): |
| 28 | |
| 29 | if (not deleted): |
| 30 | objs = VBBUTenant.get_tenant_objects().filter( |
| 31 | Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False)) |
| 32 | else: |
| 33 | |
| 34 | objs = VBBUTenant.get_deleted_tenant_objects() |
| 35 | |
| 36 | return objs |
| 37 | |
| 38 | def get_extra_attributes(self, o): |
| 39 | return {"display_message": o.display_message, "s1u_tag": o.s1u_tag, "s1mme_tag": o.s1mme_tag, "rru_tag": o.rru_tag} |