blob: 18e5d48688cc5bdcda702e63f4ddad04249f54c9 [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
12from synchronizers.base.syncstep import SyncStep
13from synchronizers.base.ansible import run_template_ssh
14from synchronizers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
15from core.models import Service, Slice, ControllerSlice, ControllerUser
Srikanth Vavilapallid84b7b72016-06-28 00:19:07 +000016from services.monitoring.models import SFlowService, SFlowTenant
Scott Baker31acc652016-06-23 15:47:56 -070017from xos.logger import Logger, logging
18
19# hpclibrary will be in steps/..
20parentdir = os.path.join(os.path.dirname(__file__),"..")
21sys.path.insert(0,parentdir)
22
23logger = Logger(level=logging.INFO)
24
25class SyncSFlowTenant(SyncInstanceUsingAnsible):
26 provides=[SFlowTenant]
27 observes=SFlowTenant
28 requested_interval=0
29 template_name = "sync_sflowtenant.yaml"
Srikanth Vavilapallid84b7b72016-06-28 00:19:07 +000030 service_key_name = "/opt/xos/synchronizers/monitoring/monitoring_channel_private_key"
Scott Baker31acc652016-06-23 15:47:56 -070031
32 def __init__(self, *args, **kwargs):
33 super(SyncSFlowTenant, self).__init__(*args, **kwargs)
34
35 def fetch_pending(self, deleted):
36 if (not deleted):
37 objs = SFlowTenant.get_tenant_objects().filter(Q(enacted__lt=F('updated')) | Q(enacted=None),Q(lazy_blocked=False))
38 else:
39 objs = SFlowTenant.get_deleted_tenant_objects()
40
41 return objs
42
43 def get_sflow_service(self, o):
44 sflows = SFlowService.get_service_objects().filter(id=o.provider_service.id)
45 if not sflows:
46 raise "No associated SFlow service"
47
48 return sflows[0]
49
50 def get_instance(self, o):
51 # We assume the SFlow service owns a slice, so pick one of the instances
52 # inside that slice to sync to.
53
54 serv = self.get_sflow_service(o)
55
56 if serv.slices.exists():
57 slice = serv.slices.all()[0]
58 if slice.instances.exists():
59 return slice.instances.all()[0]
60
61 return None
62
63 def get_extra_attributes(self, o):
64 instance = self.get_instance(o)
65
66 fields={}
67 fields["sflow_api_base_url"] = self.get_sflow_service(o).sflow_api_url
68 fields["sflow_api_port"] = self.get_sflow_service(o).sflow_api_port
69 fields["listening_endpoint"] = o.listening_endpoint
70 fields["sflow_container"] = "sflowpubsub"
71
72 return fields
73
74 def sync_fields(self, o, fields):
75 # the super causes the playbook to be run
76 super(SyncSFlowTenant, self).sync_fields(o, fields)
77
78 def run_playbook(self, o, fields):
79 super(SyncSFlowTenant, self).run_playbook(o, fields)
80
81 def delete_record(self, m):
82 pass