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