blob: 88a3efb00c1d4208eff33e9151485c9ab826d420 [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 *
5from xos.logger import Logger, logging
6
7parentdir = os.path.join(os.path.dirname(__file__), "..")
8sys.path.insert(0, parentdir)
9
10logger = Logger(level=logging.INFO)
11
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
40 # Gets the attributes that are used by the Ansible template but are not
41 # part of the set of default attributes.
42 #def get_extra_attributes(self, o):
43 # fields = {}
44 # fields['tenant_message'] = o.tenant_message
45 # vhss = self.get_vhss(o)
46 # fields['service_message'] = vhss.service_message
47 # return fields
48
49 #def delete_record(self, port):
50 # # Nothing needs to be done to delete an exampleservice; it goes away
51 # # when the instance holding the exampleservice is deleted.
52 # pass
53
54 #def handle_service_monitoringagentinfo_watch_notification(self, monitoring_agent_info):
55 # if not monitoring_agent_info.service:
56 # logger.info("handle watch notifications for service monitoring agent info...ignoring because service attribute in monitoring agent info:%s is null" % (monitoring_agent_info))
57 # return
58
59 # if not monitoring_agent_info.target_uri:
60 # 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))
61 # return
62
63 # objs = VHSSTenant.objects.all()
64 # for obj in objs:
65 # if obj.provider_service.id != monitoring_agent_info.service.id:
66 # 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))
67 # return
68
69 # instance = self.get_instance(obj)
70 # if not instance:
71 # logger.warn("handle watch notifications for service monitoring agent info...: No valid instance found for object %s" % (str(obj)))
72 # return
73
74 # logger.info("handling watch notification for monitoring agent info:%s for ExampleTenant object:%s" % (monitoring_agent_info, obj))
75
76 # #Run ansible playbook to update the routing table entries in the instance
77 # fields = self.get_ansible_fields(instance)
78 # fields["ansible_tag"] = obj.__class__.__name__ + "_" + str(obj.id) + "_monitoring"
79 # fields["target_uri"] = monitoring_agent_info.target_uri
80
81 # template_name = "monitoring_agent.yaml"
82 # super(SyncVHSSTenant, self).run_playbook(obj, fields, template_name)
83 # pass