blob: 78167f83a89495a299fc5cb6efa5209b85e1cb68 [file] [log] [blame]
Omar Abdelkader760d0a72017-07-10 13:24:46 -07001import os
2import sys
3from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
4from synchronizers.new_base.modelaccessor import *
Omar Abdelkader21ee0aa2017-07-24 10:48:39 -07005#from xos.logger import Logger, logging
Omar Abdelkader760d0a72017-07-10 13:24:46 -07006
7parentdir = os.path.join(os.path.dirname(__file__), "..")
8sys.path.insert(0, parentdir)
9
Omar Abdelkader21ee0aa2017-07-24 10:48:39 -070010#logger = Logger(level=logging.INFO)
Omar Abdelkader760d0a72017-07-10 13:24:46 -070011
12class SyncVHSSTenant(SyncInstanceUsingAnsible):
13
14 provides = [VHSSTenant]
15
16 observes = VHSSTenant
17
18 requested_interval = 0
19
20 template_name = "sync_vhss.yaml"
21
22 service_key_name = "/opt/xos/synchronizers/mcord/mcord_private_key"
23
24 #watches = [ModelLink(ServiceDependency,via='servicedependency'), ModelLink(ServiceMonitoringAgentInfo,via='monitoringagentinfo')]
25
26 def __init__(self, *args, **kwargs):
27 super(SyncVHSSTenant, self).__init__(*args, **kwargs)
28
29 def get_vhss(self, o):
30 if not o.provider_service:
31 return None
32
33 vhss = VHSSService.objects.filter(id=o.provider_service.id)
34
35 if not vhss:
36 return None
37
38 return vhss[0]
39
Omar Abdelkader21ee0aa2017-07-24 10:48:39 -070040 #Gets the attributes that are used by the Ansible template but are not
41 #part of the set of default attributes.
Omar Abdelkader760d0a72017-07-10 13:24:46 -070042
Omar Abdelkader21ee0aa2017-07-24 10:48:39 -070043 def get_extra_attributes(self, o):
44 fields = {}
45 fields['tenant_message'] = o.tenant_message
46 vhss = self.get_vhss(o)
47 fields['service_message'] = vhss.service_message
48 return fields
49
50 def delete_record(self, port):
51 pass
Omar Abdelkader760d0a72017-07-10 13:24:46 -070052
53 #def handle_service_monitoringagentinfo_watch_notification(self, monitoring_agent_info):
54 # if not monitoring_agent_info.service:
55 # logger.info("handle watch notifications for service monitoring agent info...ignoring because service attribute in monitoring agent info:%s is null" % (monitoring_agent_info))
56 # return
57
58 # if not monitoring_agent_info.target_uri:
59 # logger.info("handle watch notifications for service monitoring agent info...ignoring because target_uri attribute in monitoring agent info:%s is null" % (monitoring_agent_info))
60 # return
61
62 # objs = VHSSTenant.objects.all()
63 # for obj in objs:
64 # if obj.provider_service.id != monitoring_agent_info.service.id:
65 # logger.info("handle watch notifications for service monitoring agent info...ignoring because service attribute in monitoring agent info:%s is not matching" % (monitoring_agent_info))
66 # return
67
68 # instance = self.get_instance(obj)
69 # if not instance:
70 # logger.warn("handle watch notifications for service monitoring agent info...: No valid instance found for object %s" % (str(obj)))
71 # return
72
73 # logger.info("handling watch notification for monitoring agent info:%s for ExampleTenant object:%s" % (monitoring_agent_info, obj))
74
75 # #Run ansible playbook to update the routing table entries in the instance
76 # fields = self.get_ansible_fields(instance)
77 # fields["ansible_tag"] = obj.__class__.__name__ + "_" + str(obj.id) + "_monitoring"
78 # fields["target_uri"] = monitoring_agent_info.target_uri
79
80 # template_name = "monitoring_agent.yaml"
81 # super(SyncVHSSTenant, self).run_playbook(obj, fields, template_name)
82 # pass