blob: d43cb3474e313d834f1dea654b7849b28bdf8ca4 [file] [log] [blame]
Scott Baker31acc652016-06-23 15:47:56 -07001import hashlib
2import os
3import socket
4import sys
5import base64
6import time
7from django.db.models import F, Q
8from xos.config import Config
9from synchronizers.base.syncstep import SyncStep
Sapan Bhatia7e9f4d32017-01-24 19:32:59 +010010from synchronizers.base.ansible_helper import run_template_ssh
Scott Baker31acc652016-06-23 15:47:56 -070011from synchronizers.base.SyncInstanceUsingAnsible import SyncInstanceUsingAnsible
12from core.models import Service, Slice
Srikanth Vavilapallid84b7b72016-06-28 00:19:07 +000013from services.monitoring.models import SFlowService
Scott Baker31acc652016-06-23 15:47:56 -070014from xos.logger import Logger, logging
15
16# hpclibrary will be in steps/..
17parentdir = os.path.join(os.path.dirname(__file__),"..")
18sys.path.insert(0,parentdir)
19
20logger = Logger(level=logging.INFO)
21
22class SyncSFlowService(SyncInstanceUsingAnsible):
23 provides=[SFlowService]
24 observes=SFlowService
25 requested_interval=0
26 template_name = "sync_sflowservice.yaml"
Srikanth Vavilapallid84b7b72016-06-28 00:19:07 +000027 service_key_name = "/opt/xos/synchronizers/monitoring/monitoring_channel_private_key"
Scott Baker31acc652016-06-23 15:47:56 -070028
29 def __init__(self, *args, **kwargs):
30 super(SyncSFlowService, self).__init__(*args, **kwargs)
31
32 def fetch_pending(self, deleted):
33 if (not deleted):
34 objs = SFlowService.get_service_objects().filter(Q(enacted__lt=F('updated')) | Q(enacted=None),Q(lazy_blocked=False))
35 else:
36 objs = SFlowService.get_deleted_service_objects()
37
38 return objs
39
40 def get_instance(self, o):
41 # We assume the ONOS service owns a slice, so pick one of the instances
42 # inside that slice to sync to.
43
44 serv = o
45
46 if serv.slices.exists():
47 slice = serv.slices.all()[0]
48 if slice.instances.exists():
49 return slice.instances.all()[0]
50
51 return None
52
53 def get_extra_attributes(self, o):
54 fields={}
55 fields["instance_hostname"] = self.get_instance(o).instance_name.replace("_","-")
56 fields["sflow_port"] = o.sflow_port
57 fields["sflow_api_port"] = o.sflow_api_port
58 fields["sflow_container"] = "sflowpubsub"
59 return fields
60
61 def sync_fields(self, o, fields):
62 # the super causes the playbook to be run
63 super(SyncSFlowService, self).sync_fields(o, fields)
64
65 def run_playbook(self, o, fields):
66 instance = self.get_instance(o)
67 if (instance.isolation=="container"):
68 # If the instance is already a container, then we don't need to
69 # install ONOS.
70 return
71 super(SyncSFlowService, self).run_playbook(o, fields)
72
73 def delete_record(self, m):
74 pass