blob: 26b5eab461c8c8df828e8c24b879a8a882d07f46 [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 socket
21import sys
22import base64
23import time
24import re
25import json
26from django.db.models import F, Q
27from xos.config import Config
Murat Parlakisik638c65f2017-05-31 11:10:24 +030028from synchronizers.new_base.syncstep import SyncStep
29from synchronizers.new_base.ansible_helper import run_template_ssh
30from synchronizers.new_base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
31from modelaccessor import *
32#from core.models import Service, Slice, ControllerSlice, ControllerUser
33#from services.monitoring.models import SFlowService, SFlowTenant
Scott Baker31acc652016-06-23 15:47:56 -070034from xos.logger import Logger, logging
35
36# hpclibrary will be in steps/..
37parentdir = os.path.join(os.path.dirname(__file__),"..")
38sys.path.insert(0,parentdir)
39
40logger = Logger(level=logging.INFO)
41
42class SyncSFlowTenant(SyncInstanceUsingAnsible):
43 provides=[SFlowTenant]
44 observes=SFlowTenant
45 requested_interval=0
46 template_name = "sync_sflowtenant.yaml"
Srikanth Vavilapallid84b7b72016-06-28 00:19:07 +000047 service_key_name = "/opt/xos/synchronizers/monitoring/monitoring_channel_private_key"
Scott Baker31acc652016-06-23 15:47:56 -070048
49 def __init__(self, *args, **kwargs):
50 super(SyncSFlowTenant, self).__init__(*args, **kwargs)
51
52 def fetch_pending(self, deleted):
53 if (not deleted):
54 objs = SFlowTenant.get_tenant_objects().filter(Q(enacted__lt=F('updated')) | Q(enacted=None),Q(lazy_blocked=False))
55 else:
56 objs = SFlowTenant.get_deleted_tenant_objects()
57
58 return objs
59
60 def get_sflow_service(self, o):
61 sflows = SFlowService.get_service_objects().filter(id=o.provider_service.id)
62 if not sflows:
63 raise "No associated SFlow service"
64
65 return sflows[0]
66
67 def get_instance(self, o):
68 # We assume the SFlow service owns a slice, so pick one of the instances
69 # inside that slice to sync to.
70
71 serv = self.get_sflow_service(o)
72
73 if serv.slices.exists():
74 slice = serv.slices.all()[0]
75 if slice.instances.exists():
76 return slice.instances.all()[0]
77
78 return None
79
80 def get_extra_attributes(self, o):
81 instance = self.get_instance(o)
82
83 fields={}
84 fields["sflow_api_base_url"] = self.get_sflow_service(o).sflow_api_url
85 fields["sflow_api_port"] = self.get_sflow_service(o).sflow_api_port
86 fields["listening_endpoint"] = o.listening_endpoint
87 fields["sflow_container"] = "sflowpubsub"
88
89 return fields
90
91 def sync_fields(self, o, fields):
92 # the super causes the playbook to be run
93 super(SyncSFlowTenant, self).sync_fields(o, fields)
94
95 def run_playbook(self, o, fields):
96 super(SyncSFlowTenant, self).run_playbook(o, fields)
97
98 def delete_record(self, m):
99 pass