blob: 719ca187aca21191076b2077e18fb0ba806bd0e8 [file] [log] [blame]
import os
import sys
from django.db.models import Q, F
from synchronizers.new_base.modelaccessor import *
from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
parentdir = os.path.join(os.path.dirname(__file__), "..")
sys.path.insert(0, parentdir)
class SyncVSGWUTenant(SyncInstanceUsingAnsible):
provides = [VSGWUTenant]
observes = VSGWUTenant
requested_interval = 0
template_name = "vsgwutenant_playbook.yaml"
service_key_name = "/opt/xos/configurations/mcord/mcord_private_key"
def __init__(self, *args, **kwargs):
super(SyncVSGWUTenant, self).__init__(*args, **kwargs)
# def fetch_pending(self, deleted):
# if (not deleted):
# objs = VSGWUTenant.get_tenant_objects().filter(
# Q(enacted__lt=F('updated')) | Q(enacted=None), Q(lazy_blocked=False))
# else:
# # If this is a deletion we get all of the deleted tenants..
# objs = VSGWUTenant.get_deleted_tenant_objects()
#
# return objs
# Gets the attributes that are used by the Ansible template but are not
# part of the set of default attributes
def get_extra_attributes(self, o):
fields = {}
shared_net_id = Network.objects.get(name='shared_network').id
wan_net_id = Network.objects.get(name='wan_network').id
try:
sgwu = Port.objects.get(network_id=shared_net_id, instance_id=o.instance_id)
fields['sgwu_shared_ip'] = sgwu.ip
fields['sgwu_shared_mac'] = sgwu.mac
except Exception:
print '{} does not have an instance'.format(o.name)
try:
pgwu = TenantWithContainer.objects.get(provider_service_id=Service.objects.get(name='vpgwu').id, subscriber_tenant_id=o.subscriber_tenant_id)
fields['pgwu_wan_ip'] = Port.objects.get(network_id=wan_net_id, instance_id=pgwu.instance_id).ip
fields['pgwu_wan_mac'] = Port.objects.get(network_id=wan_net_id, instance_id=pgwu.instance_id).mac
except Exception:
print '{} does not have a VPGWU instance'.format(o.subscriber_tenant.name)
return fields