<s> import hashlib <EOL> import os <EOL> import socket <EOL> import socket <EOL> import sys <EOL> import base64 <EOL> import time <EOL> import re <EOL> import json <EOL> from django . db . models import F , Q <EOL> from xos . config import Config <EOL> from synchronizers . base . syncstep import SyncStep <EOL> from synchronizers . base . ansible import run_template_ssh <EOL> from synchronizers . base . SyncInstanceUsingAnsible import SyncInstanceUsingAnsible <EOL> from core . models import Service , Slice , ControllerSlice , ControllerUser <EOL> from services . ceilometer . models import SFlowService , SFlowTenant <EOL> from xos . logger import Logger , logging <EOL> parentdir = os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT:..>" ) <EOL> sys . path . insert ( <NUM_LIT:0> , parentdir ) <EOL> logger = Logger ( level = logging . INFO ) <EOL> class SyncSFlowTenant ( SyncInstanceUsingAnsible ) : <EOL> provides = [ SFlowTenant ] <EOL> observes = SFlowTenant <EOL> requested_interval = <NUM_LIT:0> <EOL> template_name = "<STR_LIT>" <EOL> service_key_name = "<STR_LIT>" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( SyncSFlowTenant , self ) . __init__ ( * args , ** kwargs ) <EOL> def fetch_pending ( self , deleted ) : <EOL> if ( not deleted ) : <EOL> objs = SFlowTenant . get_tenant_objects ( ) . filter ( Q ( enacted__lt = F ( '<STR_LIT>' ) ) | Q ( enacted = None ) , Q ( lazy_blocked = False ) ) <EOL> else : <EOL> objs = SFlowTenant . get_deleted_tenant_objects ( ) <EOL> return objs <EOL> def get_sflow_service ( self , o ) : <EOL> sflows = SFlowService . get_service_objects ( ) . filter ( id = o . provider_service . id ) <EOL> if not sflows : <EOL> raise "<STR_LIT>" <EOL> return sflows [ <NUM_LIT:0> ] <EOL> def get_instance ( self , o ) : <EOL> serv = self . get_sflow_service ( o ) <EOL> if serv . slices . exists ( ) : <EOL> slice = serv . slices . all ( ) [ <NUM_LIT:0> ] <EOL> if slice . instances . exists ( ) : <EOL> return slice . instances . all ( ) [ <NUM_LIT:0> ] <EOL> return None <EOL> def get_extra_attributes ( self , o ) : <EOL> instance = self . get_instance ( o ) <EOL> fields = { } <EOL> fields [ "<STR_LIT>" ] = self . get_sflow_service ( o ) . sflow_api_url <EOL> fields [ "<STR_LIT>" ] = self . get_sflow_service ( o ) . sflow_api_port <EOL> fields [ "<STR_LIT>" ] = o . listening_endpoint <EOL> fields [ "<STR_LIT>" ] = "<STR_LIT>" <EOL> return fields <EOL> def sync_fields ( self , o , fields ) : <EOL> super ( SyncSFlowTenant , self ) . sync_fields ( o , fields ) <EOL> def run_playbook ( self , o , fields ) : <EOL> super ( SyncSFlowTenant , self ) . run_playbook ( o , fields ) <EOL> def delete_record ( self , m ) : <EOL> pass </s>
