blob: 0e9aa44d869bd884764d749e6a8a55a235c7709d [file] [log] [blame]
Matteo Scandoloeb0d11c2017-08-08 13:05:26 -07001
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 dudyalaa927d562016-09-28 14:04:13 +053017import hashlib
18import os
19import socket
20import sys
21import base64
22import time
23#import threading
24import subprocess
25import random
26import tempfile
27#from sshtunnel import SSHTunnelForwarder
28from django.db.models import F, Q
29from xos.config import Config
Murat Parlakisik638c65f2017-05-31 11:10:24 +030030from synchronizers.new_base.syncstep import SyncStep
31from synchronizers.new_base.ansible_helper import run_template_ssh
32from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
33#from services.monitoring.models import CeilometerService, MonitoringChannel
34#from core.models import Service, Slice
35from modelaccessor import *
raghunath dudyalaa927d562016-09-28 14:04:13 +053036from xos.logger import Logger, logging
37
38parentdir = os.path.join(os.path.dirname(__file__),"..")
39sys.path.insert(0,parentdir)
40
41logger = Logger(level=logging.INFO)
42
43class 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