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