raghunath dudyala | a927d56 | 2016-09-28 14:04:13 +0530 | [diff] [blame] | 1 | import hashlib |
| 2 | import os |
| 3 | import socket |
| 4 | import sys |
| 5 | import base64 |
| 6 | import time |
| 7 | #import threading |
| 8 | import subprocess |
| 9 | import random |
| 10 | import tempfile |
| 11 | #from sshtunnel import SSHTunnelForwarder |
| 12 | from django.db.models import F, Q |
| 13 | from xos.config import Config |
| 14 | from synchronizers.base.syncstep import SyncStep |
Sapan Bhatia | 7e9f4d3 | 2017-01-24 19:32:59 +0100 | [diff] [blame^] | 15 | from synchronizers.base.ansible_helper import run_template_ssh |
raghunath dudyala | a927d56 | 2016-09-28 14:04:13 +0530 | [diff] [blame] | 16 | from synchronizers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible |
| 17 | from core.models import Service, Slice |
| 18 | from services.monitoring.models import CeilometerService, MonitoringChannel |
| 19 | from xos.logger import Logger, logging |
| 20 | |
| 21 | parentdir = os.path.join(os.path.dirname(__file__),"..") |
| 22 | sys.path.insert(0,parentdir) |
| 23 | |
| 24 | logger = Logger(level=logging.INFO) |
| 25 | |
| 26 | class SyncCeilometerService(SyncInstanceUsingAnsible): |
| 27 | provides=[CeilometerService] |
| 28 | observes=CeilometerService |
| 29 | requested_interval=0 |
| 30 | template_name = "sync_ceilometerservice.yaml" |
| 31 | service_key_name = "/opt/xos/synchronizers/monitoring/monitoring_channel_private_key" |
| 32 | |
| 33 | def __init__(self, *args, **kwargs): |
| 34 | super(SyncCeilometerService, self).__init__(*args, **kwargs) |
| 35 | |
| 36 | def fetch_pending(self, deleted): |
| 37 | if (not deleted): |
| 38 | objs = CeilometerService.get_service_objects().filter(Q(enacted__lt=F('updated')) | Q(enacted=None),Q(lazy_blocked=False)) |
| 39 | else: |
| 40 | objs = CeilometerService.get_deleted_service_objects() |
| 41 | |
| 42 | return objs |
| 43 | |
| 44 | def get_instance(self, o): |
| 45 | return o.get_instance() |
| 46 | |
| 47 | def get_extra_attributes(self, o): |
| 48 | fields={} |
| 49 | fields["instance_hostname"] = o.get_instance().instance_name.replace("_","-") |
| 50 | #fields = {"instance_hostname": o.get_instance().instance_name.replace("_","-"), |
| 51 | # "instance_ip": o.get_instance().private_ip()} |
| 52 | |
| 53 | |
| 54 | return fields |
| 55 | |
| 56 | def sync_fields(self, o, fields): |
| 57 | # the super causes the playbook to be run |
| 58 | super(SyncCeilometerService, self).sync_fields(o, fields) |
| 59 | |
| 60 | def run_playbook(self, o, fields): |
| 61 | instance = self.get_instance(o) |
| 62 | #if (instance.isolation=="container"): |
| 63 | # If the instance is already a container, then we don't need to |
| 64 | # install ONOS. |
| 65 | # return |
| 66 | super(SyncCeilometerService,self).run_playbook(o, fields) |
| 67 | |
| 68 | def delete_record(self, m): |
| 69 | pass |