Matteo Scandolo | eb0d11c | 2017-08-08 13:05:26 -0700 | [diff] [blame^] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
| 15 | |
| 16 | |
raghunath dudyala | a927d56 | 2016-09-28 14:04:13 +0530 | [diff] [blame] | 17 | import hashlib |
| 18 | import os |
| 19 | import socket |
| 20 | import sys |
| 21 | import base64 |
| 22 | import time |
| 23 | #import threading |
| 24 | import subprocess |
| 25 | import random |
| 26 | import tempfile |
| 27 | #from sshtunnel import SSHTunnelForwarder |
| 28 | from django.db.models import F, Q |
| 29 | from xos.config import Config |
Murat Parlakisik | 638c65f | 2017-05-31 11:10:24 +0300 | [diff] [blame] | 30 | from synchronizers.new_base.syncstep import SyncStep |
| 31 | from synchronizers.new_base.ansible_helper import run_template_ssh |
| 32 | from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible |
| 33 | #from services.monitoring.models import CeilometerService, MonitoringChannel |
| 34 | #from core.models import Service, Slice |
| 35 | from modelaccessor import * |
raghunath dudyala | a927d56 | 2016-09-28 14:04:13 +0530 | [diff] [blame] | 36 | from xos.logger import Logger, logging |
| 37 | |
| 38 | parentdir = os.path.join(os.path.dirname(__file__),"..") |
| 39 | sys.path.insert(0,parentdir) |
| 40 | |
| 41 | logger = Logger(level=logging.INFO) |
| 42 | |
| 43 | class SyncCeilometerService(SyncInstanceUsingAnsible): |
| 44 | provides=[CeilometerService] |
| 45 | observes=CeilometerService |
| 46 | requested_interval=0 |
| 47 | template_name = "sync_ceilometerservice.yaml" |
| 48 | service_key_name = "/opt/xos/synchronizers/monitoring/monitoring_channel_private_key" |
| 49 | |
| 50 | def __init__(self, *args, **kwargs): |
| 51 | super(SyncCeilometerService, self).__init__(*args, **kwargs) |
| 52 | |
| 53 | def fetch_pending(self, deleted): |
| 54 | if (not deleted): |
| 55 | objs = CeilometerService.get_service_objects().filter(Q(enacted__lt=F('updated')) | Q(enacted=None),Q(lazy_blocked=False)) |
| 56 | else: |
| 57 | objs = CeilometerService.get_deleted_service_objects() |
| 58 | |
| 59 | return objs |
| 60 | |
| 61 | def get_instance(self, o): |
| 62 | return o.get_instance() |
| 63 | |
| 64 | def get_extra_attributes(self, o): |
| 65 | fields={} |
| 66 | fields["instance_hostname"] = o.get_instance().instance_name.replace("_","-") |
| 67 | #fields = {"instance_hostname": o.get_instance().instance_name.replace("_","-"), |
| 68 | # "instance_ip": o.get_instance().private_ip()} |
| 69 | |
| 70 | |
| 71 | return fields |
| 72 | |
| 73 | def sync_fields(self, o, fields): |
| 74 | # the super causes the playbook to be run |
| 75 | super(SyncCeilometerService, self).sync_fields(o, fields) |
| 76 | |
| 77 | def run_playbook(self, o, fields): |
| 78 | instance = self.get_instance(o) |
| 79 | #if (instance.isolation=="container"): |
| 80 | # If the instance is already a container, then we don't need to |
| 81 | # install ONOS. |
| 82 | # return |
| 83 | super(SyncCeilometerService,self).run_playbook(o, fields) |
| 84 | |
| 85 | def delete_record(self, m): |
| 86 | pass |