blob: bf3390ba2f4faf80e22b58ea3a8d403e1da1c25b [file] [log] [blame]
Scott Baker31acc652016-06-23 15:47:56 -07001import hashlib
2import os
3import socket
4import sys
5import base64
6import time
7from django.db.models import F, Q
8from xos.config import Config
9from synchronizers.base.syncstep import SyncStep
10from synchronizers.base.ansible import run_template_ssh
11from synchronizers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
12from core.models import Service, Slice
Srikanth Vavilapallid84b7b72016-06-28 00:19:07 +000013from services.monitoring.models import CeilometerService, MonitoringChannel
Scott Baker31acc652016-06-23 15:47:56 -070014from xos.logger import Logger, logging
15
16parentdir = os.path.join(os.path.dirname(__file__),"..")
17sys.path.insert(0,parentdir)
18
19logger = Logger(level=logging.INFO)
20
21class SyncMonitoringChannel(SyncInstanceUsingAnsible):
22 provides=[MonitoringChannel]
23 observes=MonitoringChannel
24 requested_interval=0
25 template_name = "sync_monitoringchannel.yaml"
Srikanth Vavilapallid84b7b72016-06-28 00:19:07 +000026 service_key_name = "/opt/xos/synchronizers/monitoring/monitoring_channel_private_key"
Scott Baker31acc652016-06-23 15:47:56 -070027
28 def __init__(self, *args, **kwargs):
29 super(SyncMonitoringChannel, self).__init__(*args, **kwargs)
30
31 def fetch_pending(self, deleted):
32 if (not deleted):
33 objs = MonitoringChannel.get_tenant_objects().filter(Q(enacted__lt=F('updated')) | Q(enacted=None),Q(lazy_blocked=False))
34 else:
35 objs = MonitoringChannel.get_deleted_tenant_objects()
36
37 return objs
38
39 def get_extra_attributes(self, o):
40 # This is a place to include extra attributes. In the case of Monitoring Channel, we need to know
41 # 1) Allowed tenant ids
42 # 2) Ceilometer API service endpoint URL if running externally
43 # 3) Credentials to access Ceilometer API service
44
45 ceilometer_services = CeilometerService.get_service_objects().filter(id=o.provider_service.id)
46 if not ceilometer_services:
47 raise "No associated Ceilometer service"
48 ceilometer_service = ceilometer_services[0]
49 ceilometer_pub_sub_url = ceilometer_service.ceilometer_pub_sub_url
50 if not ceilometer_pub_sub_url:
51 ceilometer_pub_sub_url = ''
52 instance = self.get_instance(o)
53
54 try:
55 full_setup = Config().observer_full_setup
56 except:
57 full_setup = True
58
59 fields = {"unique_id": o.id,
60 "allowed_tenant_ids": o.tenant_list,
61 "auth_url":instance.controller.auth_url,
62 "admin_user":instance.controller.admin_user,
63 "admin_password":instance.controller.admin_password,
64 "admin_tenant":instance.controller.admin_tenant,
65 "ceilometer_pub_sub_url": ceilometer_pub_sub_url,
66 "full_setup": full_setup}
67
68 return fields
69
70 def run_playbook(self, o, fields):
71 #ansible_hash = hashlib.md5(repr(sorted(fields.items()))).hexdigest()
72 #quick_update = (o.last_ansible_hash == ansible_hash)
73
74 #if quick_update:
75 # logger.info("quick_update triggered; skipping ansible recipe")
76 #else:
77 super(SyncMonitoringChannel, self).run_playbook(o, fields)
78
79 #o.last_ansible_hash = ansible_hash
80
81 def map_delete_inputs(self, o):
82 fields = {"unique_id": o.id,
83 "delete": True}
84 return fields