blob: 21451b651651442e9ed1756d7c118d9beb6179ed [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
Scott Baker31acc652016-06-23 15:47:56 -070017import hashlib
18import os
19import socket
20import sys
21import base64
22import time
23from django.db.models import F, Q
24from xos.config import Config
Murat Parlakisik638c65f2017-05-31 11:10:24 +030025from synchronizers.new_base.syncstep import SyncStep
26from synchronizers.new_base.ansible_helper import run_template_ssh
27from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
28from modelaccessor import *
29#from core.models import Service, Slice
30#from services.monitoring.models import SFlowService
Scott Baker31acc652016-06-23 15:47:56 -070031from xos.logger import Logger, logging
32
33# hpclibrary will be in steps/..
34parentdir = os.path.join(os.path.dirname(__file__),"..")
35sys.path.insert(0,parentdir)
36
37logger = Logger(level=logging.INFO)
38
39class SyncSFlowService(SyncInstanceUsingAnsible):
40 provides=[SFlowService]
41 observes=SFlowService
42 requested_interval=0
43 template_name = "sync_sflowservice.yaml"
Srikanth Vavilapallid84b7b72016-06-28 00:19:07 +000044 service_key_name = "/opt/xos/synchronizers/monitoring/monitoring_channel_private_key"
Scott Baker31acc652016-06-23 15:47:56 -070045
46 def __init__(self, *args, **kwargs):
47 super(SyncSFlowService, self).__init__(*args, **kwargs)
48
49 def fetch_pending(self, deleted):
50 if (not deleted):
51 objs = SFlowService.get_service_objects().filter(Q(enacted__lt=F('updated')) | Q(enacted=None),Q(lazy_blocked=False))
52 else:
53 objs = SFlowService.get_deleted_service_objects()
54
55 return objs
56
57 def get_instance(self, o):
58 # We assume the ONOS service owns a slice, so pick one of the instances
59 # inside that slice to sync to.
60
61 serv = o
62
63 if serv.slices.exists():
64 slice = serv.slices.all()[0]
65 if slice.instances.exists():
66 return slice.instances.all()[0]
67
68 return None
69
70 def get_extra_attributes(self, o):
71 fields={}
72 fields["instance_hostname"] = self.get_instance(o).instance_name.replace("_","-")
73 fields["sflow_port"] = o.sflow_port
74 fields["sflow_api_port"] = o.sflow_api_port
75 fields["sflow_container"] = "sflowpubsub"
76 return fields
77
78 def sync_fields(self, o, fields):
79 # the super causes the playbook to be run
80 super(SyncSFlowService, self).sync_fields(o, fields)
81
82 def run_playbook(self, o, fields):
83 instance = self.get_instance(o)
84 if (instance.isolation=="container"):
85 # If the instance is already a container, then we don't need to
86 # install ONOS.
87 return
88 super(SyncSFlowService, self).run_playbook(o, fields)
89
90 def delete_record(self, m):
91 pass