<s> '''<STR_LIT>''' <EOL> import os <EOL> import sys <EOL> import random <EOL> from foam . ethzlegacyoptinstuff . legacyoptin . optsmodels import Experiment , ExperimentFLowSpace <EOL> from foam . ethzlegacyoptinstuff . legacyoptin . flowspaceutils import dotted_ip_to_int , mac_to_int , int_to_dotted_ip , int_to_mac , parseFVexception <EOL> import logging <EOL> import zlib <EOL> import base64 <EOL> import xmlrpclib <EOL> from xml . parsers . expat import ExpatError <EOL> import jsonrpc <EOL> from flaskext . xmlrpc import XMLRPCHandler , Fault <EOL> from flask import request <EOL> import foam . task <EOL> import foam . lib <EOL> import foam . api . xmlrpc <EOL> import foam . version <EOL> from foam . creds import CredVerifier , Certificate <EOL> from foam . config import AUTO_SLIVER_PRIORITY , GAPI_REPORTFOAMVERSION <EOL> from foam . core . configdb import ConfigDB <EOL> from foam . core . log import KeyAdapter <EOL> from foam . geni . db import GeniDB , UnknownSlice , UnknownNode <EOL> import foam . geni . approval <EOL> import foam . geni . ofeliaapproval <EOL> import foam . geni . lib <EOL> import sfa <EOL> from foam . flowvisor import Connection as FV <EOL> from pprint import pprint <EOL> import json <EOL> import httplib , urllib , base64 <EOL> THIS_SITE_TAG = ConfigDB . getConfigItemByKey ( "<STR_LIT>" ) . getValue ( ) <EOL> def _same ( val ) : <EOL> return "<STR_LIT:%s>" % val <EOL> class om_ch_translate ( object ) : <EOL> attr_funcs = { <EOL> "<STR_LIT>" : ( int_to_mac , mac_to_int , <NUM_LIT> , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( int_to_mac , mac_to_int , <NUM_LIT> , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( _same , int , <NUM_LIT:16> , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( _same , int , <NUM_LIT:12> , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( int_to_dotted_ip , dotted_ip_to_int , <NUM_LIT:32> , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( int_to_dotted_ip , dotted_ip_to_int , <NUM_LIT:32> , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( _same , int , <NUM_LIT:8> , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( _same , int , <NUM_LIT:16> , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( _same , int , <NUM_LIT:16> , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : ( _same , int , <NUM_LIT:16> , "<STR_LIT>" , "<STR_LIT>" ) , <EOL> } <EOL> import threading <EOL> import time <EOL> class RepeatTimer ( threading . Thread ) : <EOL> def __init__ ( self , interval , callable_fun , * args , ** kwargs ) : <EOL> threading . Thread . __init__ ( self ) <EOL> self . interval = interval <EOL> self . callable_fun = callable_fun <EOL> self . args = args <EOL> self . kwargs = kwargs <EOL> self . event = threading . Event ( ) <EOL> def run ( self ) : <EOL> while not self . event . is_set ( ) : <EOL> self . callable_fun ( self . args , self . kwargs ) <EOL> self . event . wait ( self . interval ) <EOL> def cancel ( self ) : <EOL> self . event . set ( ) <EOL> from foam . ethzlegacyoptinstuff . api_exp_to_rspecv3 . expdatatogeniv3rspec import create_ofv3_rspec <EOL> class AMLegExpAPI ( foam . api . xmlrpc . Dispatcher ) : <EOL> def __init__ ( self , log ) : <EOL> super ( AMLegExpAPI , self ) . __init__ ( "<STR_LIT>" , log ) <EOL> self . _actionLog = KeyAdapter ( "<STR_LIT>" , logging . getLogger ( '<STR_LIT>' ) ) <EOL> filedir = '<STR_LIT>' <EOL> filename = os . path . join ( filedir , '<STR_LIT>' ) <EOL> if os . path . isfile ( filename ) : <EOL> f = open ( filename , '<STR_LIT:r>' ) <EOL> self . slice_info_dict = json . load ( f ) <EOL> f . close ( ) <EOL> else : <EOL> self . slice_info_dict = { } <EOL> self . switch_dpid_list = None <EOL> self . link_list = None <EOL> self . callback_http_attr_list = [ ] <EOL> self . callback_cred_attr_list = [ ] <EOL> def recordAction ( self , action , credentials = [ ] , urn = None ) : <EOL> cred_ids = [ ] <EOL> self . _actionLog . info ( "<STR_LIT>" % ( urn , action ) ) <EOL> for cred in credentials : <EOL> self . _actionLog . info ( "<STR_LIT>" % ( cred ) ) <EOL> def priv_CreateSliver ( self , slice_urn , credentials , rspec , users , force_approval = False , options = None ) : <EOL> user_info = users <EOL> try : <EOL> if True : <EOL> self . recordAction ( "<STR_LIT>" , credentials , slice_urn ) <EOL> try : <EOL> self . _log . debug ( "<STR_LIT>" % users ) <EOL> except Exception , e : <EOL> self . _log . exception ( "<STR_LIT>" ) <EOL> user_info [ "<STR_LIT>" ] = None <EOL> user_info [ "<STR_LIT:email>" ] = None <EOL> from foam . app import admin_apih <EOL> if not admin_apih . vlan_automation_on : <EOL> sliver = foam . geni . lib . createSliver ( slice_urn , credentials , rspec , user_info ) <EOL> style = ConfigDB . getConfigItemByKey ( "<STR_LIT>" ) . getValue ( ) <EOL> if style == foam . geni . approval . NEVER : <EOL> approve = False <EOL> elif style == foam . geni . approval . ALWAYS : <EOL> approve = True <EOL> else : <EOL> approve = foam . geni . ofeliaapproval . of_analyzeForApproval ( sliver ) <EOL> if approve or force_approval : <EOL> pid = foam . task . approveSliver ( sliver . getURN ( ) , AUTO_SLIVER_PRIORITY ) <EOL> self . _log . debug ( "<STR_LIT>" % pid ) <EOL> else : <EOL> free_vlan_list = self . pub_get_offered_vlans ( <NUM_LIT:1> ) <EOL> free_vlan = free_vlan_list [ <NUM_LIT:0> ] <EOL> slice_id = slice_urn . split ( "<STR_LIT>" ) [ <NUM_LIT:1> ] . split ( "<STR_LIT::>" ) [ <NUM_LIT:0> ] . split ( "<STR_LIT>" ) [ <NUM_LIT:1> ] . split ( "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> if ( slice_id == "<STR_LIT>" ) or ( slice_id not in self . slice_info_dict ) : <EOL> self . _log . exception ( "<STR_LIT>" ) <EOL> raise Exception <EOL> updated_slice_info_dict = self . slice_info_dict . copy ( ) <EOL> for sliv_pos , sliver in enumerate ( self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] ) : <EOL> for sfs_pos , sfs in enumerate ( sliver [ '<STR_LIT>' ] ) : <EOL> updated_slice_info_dict [ slice_id ] [ '<STR_LIT>' ] [ sliv_pos ] [ '<STR_LIT>' ] [ sfs_pos ] [ '<STR_LIT>' ] = free_vlan <EOL> updated_slice_info_dict [ slice_id ] [ '<STR_LIT>' ] [ sliv_pos ] [ '<STR_LIT>' ] [ sfs_pos ] [ '<STR_LIT>' ] = free_vlan <EOL> all_efs = self . create_slice_fs ( updated_slice_info_dict [ slice_id ] [ '<STR_LIT>' ] ) <EOL> new_slice_of_rspec = create_ofv3_rspec ( slice_id , updated_slice_info_dict [ slice_id ] [ '<STR_LIT>' ] , updated_slice_info_dict [ slice_id ] [ '<STR_LIT>' ] , updated_slice_info_dict [ slice_id ] [ '<STR_LIT>' ] , updated_slice_info_dict [ slice_id ] [ '<STR_LIT>' ] , updated_slice_info_dict [ slice_id ] [ '<STR_LIT>' ] , updated_slice_info_dict [ slice_id ] [ '<STR_LIT>' ] , updated_slice_info_dict [ slice_id ] [ '<STR_LIT>' ] , updated_slice_info_dict [ slice_id ] [ '<STR_LIT>' ] , all_efs ) <EOL> self . slice_info_dict = updated_slice_info_dict . copy ( ) <EOL> sliver = foam . geni . lib . createSliver ( slice_urn , credentials , new_slice_of_rspec , user_info ) <EOL> pid = foam . task . approveSliver ( sliver . getURN ( ) , AUTO_SLIVER_PRIORITY ) <EOL> self . _log . debug ( "<STR_LIT>" % pid ) <EOL> data = GeniDB . getSliverData ( sliver . getURN ( ) , True ) <EOL> foam . task . emailCreateSliver ( data ) <EOL> return self . successResult ( GeniDB . getManifest ( sliver . getURN ( ) ) ) <EOL> return <EOL> except foam . geni . lib . RspecParseError , e : <EOL> self . _log . info ( str ( e ) ) <EOL> e . _foam_logged = True <EOL> raise e <EOL> except foam . geni . lib . RspecValidationError , e : <EOL> self . _log . info ( str ( e ) ) <EOL> e . _foam_logged = True <EOL> raise e <EOL> except foam . geni . lib . DuplicateSliver , ds : <EOL> self . _log . info ( "<STR_LIT>" % ( ds . slice_urn ) ) <EOL> ds . _foam_logged = True <EOL> raise ds <EOL> except foam . geni . lib . UnknownComponentManagerID , ucm : <EOL> raise Fault ( "<STR_LIT>" , "<STR_LIT>" % ( ucm . cid ) ) <EOL> except ( foam . geni . lib . UnmanagedComponent , UnknownNode ) , uc : <EOL> self . _log . info ( "<STR_LIT>" % ( uc . cid ) ) <EOL> f = Fault ( "<STR_LIT>" , "<STR_LIT>" % ( uc . cid ) ) <EOL> f . _foam_logged = True <EOL> raise f <EOL> except Exception , e : <EOL> self . _log . exception ( "<STR_LIT>" ) <EOL> raise e <EOL> def priv_DeleteSliver ( self , slice_urn , credentials , options = None ) : <EOL> try : <EOL> if True : <EOL> self . recordAction ( "<STR_LIT>" , credentials , slice_urn ) <EOL> if GeniDB . getSliverURN ( slice_urn ) is None : <EOL> raise Fault ( "<STR_LIT>" , "<STR_LIT>" % ( slice_urn ) ) <EOL> return self . errorResult ( <NUM_LIT:12> , "<STR_LIT>" ) <EOL> sliver_urn = GeniDB . getSliverURN ( slice_urn ) <EOL> data = GeniDB . getSliverData ( sliver_urn , True ) <EOL> foam . geni . lib . deleteSliver ( sliver_urn = sliver_urn ) <EOL> foam . task . emailGAPIDeleteSliver ( data ) <EOL> return self . successResult ( True ) <EOL> return self . successResult ( False ) <EOL> except UnknownSlice , x : <EOL> self . _log . info ( "<STR_LIT>" % ( slice_urn ) ) <EOL> x . _foam_logged = True <EOL> raise x <EOL> except Exception , e : <EOL> self . _log . exception ( "<STR_LIT>" ) <EOL> raise e <EOL> def pub_check_fv_set ( self , func , * arg , ** kwargs ) : <EOL> if ( FV . xmlconn is None ) : <EOL> self . _log . exception ( "<STR_LIT>" ) <EOL> raise Exception ( "<STR_LIT>" ) <EOL> return func ( * arg , ** kwargs ) <EOL> def pub_check_user ( self , func , * args , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> if "<STR_LIT>" not in kwargs : <EOL> raise Exception ( "<STR_LIT>" % func . func_name ) <EOL> if not hasattr ( kwargs [ "<STR_LIT>" ] , "<STR_LIT:user>" ) : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> kwargs [ '<STR_LIT:user>' ] = kwargs [ '<STR_LIT>' ] . user <EOL> return func ( * args , ** kwargs ) <EOL> def pub_checkFlowVisor ( self , * arg , ** kwargs ) : <EOL> if ( FV . xmlconn is None ) : <EOL> self . _log . exception ( "<STR_LIT>" ) <EOL> raise Exception ( "<STR_LIT>" ) <EOL> return "<STR_LIT>" <EOL> def pub_convert_star ( self , fs ) : <EOL> temp = fs . copy ( ) <EOL> for ch_name , ( to_str , from_str , width , om_name , of_name ) in om_ch_translate . attr_funcs . items ( ) : <EOL> ch_start = "<STR_LIT>" % ch_name <EOL> ch_end = "<STR_LIT>" % ch_name <EOL> if ch_start not in fs or fs [ ch_start ] == "<STR_LIT:*>" : <EOL> temp [ ch_start ] = to_str ( <NUM_LIT:0> ) <EOL> if ch_end not in fs or fs [ ch_end ] == "<STR_LIT:*>" : <EOL> temp [ ch_end ] = to_str ( <NUM_LIT:2> ** width - <NUM_LIT:1> ) <EOL> return temp <EOL> def pub_convert_star_int ( self , fs ) : <EOL> temp = fs . copy ( ) <EOL> for ch_name , ( to_str , from_str , width , om_name , of_name ) in om_ch_translate . attr_funcs . items ( ) : <EOL> ch_start = "<STR_LIT>" % ch_name <EOL> ch_end = "<STR_LIT>" % ch_name <EOL> if ch_start not in fs or fs [ ch_start ] == "<STR_LIT:*>" : <EOL> temp [ ch_start ] = <NUM_LIT:0> <EOL> else : <EOL> temp [ ch_start ] = from_str ( fs [ ch_start ] ) <EOL> if ch_end not in fs or fs [ ch_end ] == "<STR_LIT:*>" : <EOL> temp [ ch_end ] = <NUM_LIT:2> ** width - <NUM_LIT:1> <EOL> else : <EOL> temp [ ch_end ] = from_str ( fs [ ch_end ] ) <EOL> return temp <EOL> def pub_get_direction ( self , direction ) : <EOL> if ( direction == '<STR_LIT>' ) : <EOL> return <NUM_LIT:0> <EOL> if ( direction == '<STR_LIT>' ) : <EOL> return <NUM_LIT:1> <EOL> if ( direction == '<STR_LIT>' ) : <EOL> return <NUM_LIT:2> <EOL> return <NUM_LIT:2> <EOL> def create_slice_fs ( self , switch_slivers ) : <EOL> all_efs = [ ] <EOL> for sliver in switch_slivers : <EOL> if "<STR_LIT>" in sliver : <EOL> dpid = sliver [ '<STR_LIT>' ] <EOL> else : <EOL> dpid = "<STR_LIT>" * <NUM_LIT:8> <EOL> dpid = dpid [ : - <NUM_LIT:1> ] <EOL> if len ( sliver [ '<STR_LIT>' ] ) == <NUM_LIT:0> : <EOL> efs = ExperimentFLowSpace ( ) <EOL> efs . dpid = dpid <EOL> efs . direction = <NUM_LIT:2> <EOL> all_efs . append ( efs ) <EOL> else : <EOL> for sfs in sliver [ '<STR_LIT>' ] : <EOL> efs = ExperimentFLowSpace ( ) <EOL> efs . dpid = dpid <EOL> if "<STR_LIT>" in sfs : <EOL> efs . direction = self . get_direction ( sfs [ '<STR_LIT>' ] ) <EOL> else : <EOL> efs . direction = <NUM_LIT:2> <EOL> fs = self . pub_convert_star ( sfs ) <EOL> for attr_name , ( to_str , from_str , width , om_name , of_name ) in om_ch_translate . attr_funcs . items ( ) : <EOL> ch_start = "<STR_LIT>" % ( attr_name ) <EOL> ch_end = "<STR_LIT>" % ( attr_name ) <EOL> om_start = "<STR_LIT>" % ( om_name ) <EOL> om_end = "<STR_LIT>" % ( om_name ) <EOL> setattr ( efs , om_start , from_str ( fs [ ch_start ] ) ) <EOL> setattr ( efs , om_end , from_str ( fs [ ch_end ] ) ) <EOL> all_efs . append ( efs ) <EOL> return all_efs <EOL> def purge_switch_slivers_from_null_fs ( self , switch_slivers ) : <EOL> purged_switch_slivers = switch_slivers <EOL> slivers_to_remove = [ ] <EOL> for sliver in purged_switch_slivers : <EOL> if len ( sliver [ '<STR_LIT>' ] ) == <NUM_LIT:0> : <EOL> slivers_to_remove . append ( sliver ) <EOL> for sliver in slivers_to_remove : <EOL> purged_switch_slivers . remove ( sliver ) <EOL> del slivers_to_remove <EOL> return purged_switch_slivers <EOL> def pub_create_slice ( self , slice_id , project_name , project_description , <EOL> slice_name , slice_description , controller_url , <EOL> owner_email , owner_password , <EOL> switch_slivers , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> slice_id = slice_id . replace ( "<STR_LIT::>" , "<STR_LIT:_>" ) <EOL> slice_id = slice_id . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> slice_name = slice_name . replace ( "<STR_LIT::>" , "<STR_LIT:_>" ) <EOL> '''<STR_LIT>''' <EOL> purged_switch_slivers = self . purge_switch_slivers_from_null_fs ( switch_slivers ) <EOL> self . slice_info_dict [ slice_id ] = { } <EOL> self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] = project_name <EOL> self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] = project_description <EOL> self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] = slice_name <EOL> self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] = slice_description <EOL> self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] = controller_url <EOL> self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] = owner_email <EOL> self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] = owner_password <EOL> self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] = purged_switch_slivers <EOL> all_efs = self . create_slice_fs ( purged_switch_slivers ) <EOL> slice_of_rspec = create_ofv3_rspec ( slice_id , project_name , project_description , slice_name , slice_description , controller_url , owner_email , owner_password , purged_switch_slivers , all_efs ) <EOL> self . _log . info ( slice_of_rspec ) <EOL> slice_urn = "<STR_LIT>" + str ( THIS_SITE_TAG ) + "<STR_LIT>" + "<STR_LIT>" + str ( slice_id ) + "<STR_LIT>" + str ( slice_name ) <EOL> creds = [ ] <EOL> user_info = { } <EOL> user_info [ "<STR_LIT>" ] = "<STR_LIT>" + str ( THIS_SITE_TAG ) + "<STR_LIT>" + "<STR_LIT>" + str ( owner_email ) <EOL> user_info [ "<STR_LIT:email>" ] = str ( owner_email ) <EOL> update_exp = True <EOL> if not GeniDB . sliceExists ( slice_urn ) : <EOL> update_exp = False <EOL> if ( update_exp ) : <EOL> try : <EOL> old_exp_shutdown_success = self . priv_DeleteSliver ( slice_urn , creds , [ ] ) <EOL> except Exception , e : <EOL> import traceback <EOL> traceback . print_exc ( ) <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if old_exp_shutdown_success == False : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> creation_result = self . priv_CreateSliver ( slice_urn , creds , slice_of_rspec , user_info ) <EOL> filedir = '<STR_LIT>' <EOL> filename = os . path . join ( filedir , '<STR_LIT>' ) <EOL> tempfilename = os . path . join ( filedir , '<STR_LIT>' + str ( time . time ( ) ) + str ( random . randint ( <NUM_LIT:1> , <NUM_LIT> ) ) ) <EOL> f = open ( tempfilename , '<STR_LIT:w>' ) <EOL> json . dump ( self . slice_info_dict , f ) <EOL> f . close ( ) <EOL> os . rename ( tempfilename , filename ) <EOL> return { <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : [ ] , <EOL> } <EOL> def pub_delete_slice ( self , slice_id , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> slice_id = slice_id . replace ( "<STR_LIT::>" , "<STR_LIT:_>" ) <EOL> slice_id = slice_id . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> '''<STR_LIT>''' <EOL> slice_urn = "<STR_LIT>" + str ( THIS_SITE_TAG ) + "<STR_LIT>" + "<STR_LIT>" + str ( slice_id ) + "<STR_LIT>" + str ( self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] ) <EOL> creds = [ ] <EOL> deleted_slice_info = self . priv_DeleteSliver ( slice_urn , creds , [ ] ) <EOL> del self . slice_info_dict [ slice_id ] <EOL> filedir = '<STR_LIT>' <EOL> filename = os . path . join ( filedir , '<STR_LIT>' ) <EOL> tempfilename = os . path . join ( filedir , '<STR_LIT>' + str ( time . time ( ) ) + str ( random . randint ( <NUM_LIT:1> , <NUM_LIT> ) ) ) <EOL> f = open ( tempfilename , '<STR_LIT:w>' ) <EOL> json . dump ( self . slice_info_dict , f ) <EOL> f . close ( ) <EOL> os . rename ( tempfilename , filename ) <EOL> return "<STR_LIT>" <EOL> def pub_change_slice_controller ( self , slice_id , controller_url , ** kwargs ) : <EOL> slice_id = slice_id . replace ( "<STR_LIT::>" , "<STR_LIT:_>" ) <EOL> slice_id = slice_id . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> '''<STR_LIT>''' <EOL> if slice_id not in self . slice_info_dict : <EOL> self . _log . info ( "<STR_LIT>" ) <EOL> return "<STR_LIT>" <EOL> filedir = '<STR_LIT>' <EOL> filename = os . path . join ( filedir , '<STR_LIT>' ) <EOL> if os . path . isfile ( filename ) : <EOL> f = open ( filename , '<STR_LIT:r>' ) <EOL> self . slice_info_dict = json . load ( f ) <EOL> f . close ( ) <EOL> else : <EOL> self . _log . info ( "<STR_LIT>" ) <EOL> return "<STR_LIT>" <EOL> slice_of_rspec = create_ofv3_rspec ( slice_id , self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] , <EOL> self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] , <EOL> self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] , <EOL> self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] , controller_url , <EOL> self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] , <EOL> self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] , <EOL> self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] , <EOL> self . create_slice_fs ( self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] ) ) <EOL> self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] = controller_url <EOL> slice_urn = "<STR_LIT>" + str ( THIS_SITE_TAG ) + "<STR_LIT>" + "<STR_LIT>" + str ( slice_id ) + "<STR_LIT>" + str ( self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] ) <EOL> creds = [ ] <EOL> user_info = { } <EOL> user_info [ "<STR_LIT>" ] = "<STR_LIT>" + str ( THIS_SITE_TAG ) + "<STR_LIT>" + "<STR_LIT>" + str ( self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] ) <EOL> user_info [ "<STR_LIT:email>" ] = str ( self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] ) <EOL> if GeniDB . sliceExists ( slice_urn ) : <EOL> sliv_urn = GeniDB . getSliverURN ( slice_urn ) <EOL> else : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> sliver = GeniDB . getSliverObj ( sliv_urn ) <EOL> is_allocated_by_FV = GeniDB . getEnabled ( sliv_urn ) <EOL> was_allocated_by_FV = is_allocated_by_FV <EOL> try : <EOL> old_exp_shutdown_success = self . priv_DeleteSliver ( slice_urn , creds , [ ] ) <EOL> except Exception , e : <EOL> import traceback <EOL> traceback . print_exc ( ) <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if old_exp_shutdown_success == False : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> if was_allocated_by_FV == True : <EOL> creation_result = self . priv_CreateSliver ( slice_urn , creds , slice_of_rspec , user_info , True , None ) <EOL> else : <EOL> creation_result = self . priv_CreateSliver ( slice_urn , creds , slice_of_rspec , user_info , False , None ) <EOL> filedir = '<STR_LIT>' <EOL> filename = os . path . join ( filedir , '<STR_LIT>' ) <EOL> tempfilename = os . path . join ( filedir , '<STR_LIT>' + str ( time . time ( ) ) + str ( random . randint ( <NUM_LIT:1> , <NUM_LIT> ) ) ) <EOL> f = open ( tempfilename , '<STR_LIT:w>' ) <EOL> json . dump ( self . slice_info_dict , f ) <EOL> f . close ( ) <EOL> os . rename ( tempfilename , filename ) <EOL> return "<STR_LIT>" <EOL> def pub_get_switches ( self , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> complete_list = [ ] <EOL> try : <EOL> dpids = FV . getDeviceList ( ) <EOL> for d in dpids : <EOL> FV . log . debug ( "<STR_LIT>" % ( d ) ) <EOL> infos = [ FV . xmlcall ( "<STR_LIT>" , d ) for d in dpids ] <EOL> switches = zip ( dpids , infos ) <EOL> except Exception , e : <EOL> import traceback <EOL> traceback . print_exc ( ) <EOL> raise e <EOL> complete_list . extend ( switches ) <EOL> return complete_list <EOL> def pub_get_links ( self , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> complete_list = [ ] <EOL> try : <EOL> links = [ ( l . pop ( "<STR_LIT>" ) , <EOL> l . pop ( "<STR_LIT>" ) , <EOL> l . pop ( "<STR_LIT>" ) , <EOL> l . pop ( "<STR_LIT>" ) , <EOL> l ) for l in FV . getLinkList ( ) ] <EOL> except Exception , e : <EOL> import traceback <EOL> traceback . print_exc ( ) <EOL> raise e <EOL> complete_list . extend ( links ) <EOL> return complete_list <EOL> def check_topo_change ( self ) : <EOL> if ( self . switch_dpid_list is None ) or ( self . link_list is None ) : <EOL> if self . pub_get_switches ( ) != [ ] : <EOL> switch_dpids_unzipped , infos = zip ( * self . pub_get_switches ( ) ) <EOL> self . switch_dpid_list = list ( switch_dpids_unzipped ) <EOL> else : <EOL> self . switch_dpid_list = [ ] <EOL> self . link_list = self . pub_get_links ( ) <EOL> try : <EOL> if self . pub_get_switches ( ) != [ ] : <EOL> updated_switch_dpids_unzipped , infos = zip ( * self . pub_get_switches ( ) ) <EOL> updated_switch_dpid_list = list ( updated_switch_dpids_unzipped ) <EOL> else : <EOL> updated_switch_dpid_list = [ ] <EOL> updated_link_list = self . pub_get_links ( ) <EOL> if ( set ( updated_switch_dpid_list ) != set ( self . switch_dpid_list ) ) : <EOL> self . _log . info ( "<STR_LIT>" ) <EOL> self . topology_changed_alert_expedient ( ) <EOL> if ( updated_link_list != self . link_list ) : <EOL> self . _log . info ( "<STR_LIT>" ) <EOL> self . topology_changed_alert_expedient ( ) <EOL> self . switch_dpid_list = updated_switch_dpid_list <EOL> self . link_list = updated_link_list <EOL> except Exception , e : <EOL> import traceback <EOL> traceback . print_exc ( ) <EOL> raise e <EOL> def topology_changed_alert_expedient ( self ) : <EOL> if len ( self . callback_cred_attr_list ) == <NUM_LIT:0> : <EOL> self . _log . info ( "<STR_LIT>" ) <EOL> return "<STR_LIT>" <EOL> for i , at in enumerate ( self . callback_cred_attr_list ) : <EOL> callback_cred_attrs = self . callback_cred_attr_list [ i ] <EOL> callback_http_attrs = self . callback_http_attr_list [ i ] <EOL> username = callback_cred_attrs [ '<STR_LIT:username>' ] <EOL> password = callback_cred_attrs [ '<STR_LIT:password>' ] <EOL> body = "<STR_LIT>" + str ( callback_http_attrs [ '<STR_LIT>' ] ) + "<STR_LIT>" <EOL> base64string = base64 . encodestring ( '<STR_LIT>' % ( username , password ) ) [ : - <NUM_LIT:1> ] <EOL> authheader = "<STR_LIT>" % base64string <EOL> headers = { "<STR_LIT>" : authheader } <EOL> firstIndex = callback_http_attrs [ '<STR_LIT:url>' ] . find ( "<STR_LIT>" ) <EOL> lastIndex = callback_http_attrs [ '<STR_LIT:url>' ] . find ( "<STR_LIT:/>" , firstIndex + <NUM_LIT:3> , len ( callback_http_attrs [ '<STR_LIT:url>' ] ) ) <EOL> if lastIndex == - <NUM_LIT:1> : <EOL> lastIndex = len ( callback_http_attrs [ '<STR_LIT:url>' ] ) <EOL> clearingHouseURL1 = callback_http_attrs [ '<STR_LIT:url>' ] [ firstIndex + <NUM_LIT:2> : lastIndex ] <EOL> if lastIndex + <NUM_LIT:1> < len ( callback_http_attrs [ '<STR_LIT:url>' ] ) : <EOL> clearingHouseURL2 = "<STR_LIT:/>" + callback_http_attrs [ '<STR_LIT:url>' ] [ lastIndex + <NUM_LIT:1> : len ( callback_http_attrs [ '<STR_LIT:url>' ] ) ] <EOL> else : <EOL> clearingHouseURL2 = "<STR_LIT>" ; <EOL> connectionToClearingHouse = httplib . HTTPSConnection ( clearingHouseURL1 ) <EOL> connectionToClearingHouse . request ( "<STR_LIT:POST>" , clearingHouseURL2 , body , headers ) <EOL> response = connectionToClearingHouse . getresponse ( ) ; <EOL> self . _log . info ( "<STR_LIT>" ) <EOL> self . _log . info ( response . status ) <EOL> self . _log . info ( response . reason ) <EOL> self . _log . info ( response . read ( ) ) <EOL> self . _log . info ( "<STR_LIT>" ) <EOL> return "<STR_LIT>" <EOL> def pub_register_topology_callback ( self , url , cookie , ** kwargs ) : <EOL> callback_http_attrs = { '<STR_LIT:url>' : url , '<STR_LIT>' : cookie } <EOL> if ( '<STR_LIT:user>' not in kwargs ) or ( '<STR_LIT:password>' not in kwargs ) : <EOL> self . _log . info ( "<STR_LIT>" ) <EOL> return "<STR_LIT>" <EOL> callback_cred_attrs = { '<STR_LIT:username>' : kwargs [ '<STR_LIT:user>' ] . username , '<STR_LIT:password>' : kwargs [ '<STR_LIT:password>' ] . password } <EOL> self . callback_http_attr_list . append ( callback_http_attrs ) <EOL> self . callback_cred_attr_list . append ( callback_cred_attrs ) <EOL> return "<STR_LIT>" <EOL> def pub_change_password ( self , new_password , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> return "<STR_LIT>" <EOL> def pub_ping ( self , data , ** kwargs ) : <EOL> if ( FV . xmlconn is None ) : <EOL> self . _log . exception ( "<STR_LIT>" ) <EOL> raise Exception ( "<STR_LIT>" ) <EOL> self . check_topo_change ( ) <EOL> try : <EOL> FV . log . debug ( "<STR_LIT>" % ( str ( data ) ) ) <EOL> return FV . xmlcall ( "<STR_LIT>" , "<STR_LIT:U+0020>" + str ( data ) ) <EOL> except Exception , e : <EOL> import traceback <EOL> traceback . print_exc ( ) <EOL> raise e <EOL> def pub_get_granted_flowspace ( self , slice_id , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> slice_id = slice_id . replace ( "<STR_LIT::>" , "<STR_LIT:_>" ) <EOL> slice_id = slice_id . replace ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> def parse_granted_flowspaces ( gfs ) : <EOL> gfs_list = [ ] <EOL> for fs in gfs : <EOL> fs_dict = dict ( <EOL> flowspace = dict ( ) , <EOL> openflow = dict ( ) <EOL> ) <EOL> fs_dict [ '<STR_LIT>' ] = [ ] <EOL> fs_dict [ '<STR_LIT>' ] = dict ( <EOL> mac_src_s = int_to_mac ( fs . mac_src_s ) , <EOL> mac_src_e = int_to_mac ( fs . mac_src_e ) , <EOL> mac_dst_s = int_to_mac ( fs . mac_dst_s ) , <EOL> mac_dst_e = int_to_mac ( fs . mac_dst_e ) , <EOL> eth_type_s = fs . eth_type_s , <EOL> eth_type_e = fs . eth_type_e , <EOL> vlan_id_s = fs . vlan_id_s , <EOL> vlan_id_e = fs . vlan_id_e , <EOL> ip_src_s = int_to_dotted_ip ( fs . ip_src_s ) , <EOL> ip_dst_s = int_to_dotted_ip ( fs . ip_dst_s ) , <EOL> ip_src_e = int_to_dotted_ip ( fs . ip_src_e ) , <EOL> ip_dst_e = int_to_dotted_ip ( fs . ip_dst_e ) , <EOL> ip_proto_s = fs . ip_proto_s , <EOL> ip_proto_e = fs . ip_proto_e , <EOL> tp_src_s = fs . tp_src_s , <EOL> tp_dst_s = fs . tp_dst_s , <EOL> tp_src_e = fs . tp_src_e , <EOL> tp_dst_e = fs . tp_dst_e , <EOL> ) <EOL> openflow_dict = dict ( <EOL> dpid = fs . dpid , <EOL> direction = fs . direction , <EOL> port_number_s = fs . port_number_s , <EOL> port_number_e = fs . port_number_e , <EOL> ) <EOL> existing_fs = False <EOL> for prev_dict_list in gfs_list : <EOL> prev_dict = prev_dict_list [ <NUM_LIT:0> ] <EOL> if fs_dict [ '<STR_LIT>' ] == prev_dict [ '<STR_LIT>' ] : <EOL> if openflow_dict not in prev_dict [ '<STR_LIT>' ] : <EOL> prev_dict [ '<STR_LIT>' ] . append ( openflow_dict ) <EOL> existing_fs = True <EOL> break <EOL> if not existing_fs : <EOL> fs_dict [ '<STR_LIT>' ] . append ( openflow_dict ) <EOL> fs_list = [ fs_dict ] <EOL> gfs_list . append ( fs_list ) <EOL> return gfs_list <EOL> if slice_id in self . slice_info_dict : <EOL> slice_urn = "<STR_LIT>" + str ( THIS_SITE_TAG ) + "<STR_LIT>" + "<STR_LIT>" + str ( slice_id ) + "<STR_LIT>" + str ( self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] ) <EOL> else : <EOL> return [ ] <EOL> if GeniDB . sliceExists ( slice_urn ) : <EOL> sliv_urn = GeniDB . getSliverURN ( slice_urn ) <EOL> else : <EOL> return [ ] <EOL> sliver = GeniDB . getSliverObj ( sliv_urn ) <EOL> is_allocated_by_FV = GeniDB . getEnabled ( sliv_urn ) <EOL> if is_allocated_by_FV == True : <EOL> filedir = '<STR_LIT>' <EOL> filename = os . path . join ( filedir , '<STR_LIT>' ) <EOL> if os . path . isfile ( filename ) : <EOL> f = open ( filename , '<STR_LIT:r>' ) <EOL> self . slice_info_dict = json . load ( f ) <EOL> f . close ( ) <EOL> else : <EOL> self . _log . info ( "<STR_LIT>" ) <EOL> return [ ] <EOL> if slice_id not in self . slice_info_dict : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> all_efs = self . create_slice_fs ( self . slice_info_dict [ slice_id ] [ '<STR_LIT>' ] ) <EOL> gfs = [ ] <EOL> try : <EOL> gfs = parse_granted_flowspaces ( all_efs ) <EOL> except Exception , e : <EOL> import traceback <EOL> traceback . print_exc ( ) <EOL> self . _log . exception ( "<STR_LIT>" ) <EOL> raise Exception ( parseFVexception ( e ) ) <EOL> if gfs == [ ] : <EOL> self . _log . info ( "<STR_LIT>" ) <EOL> return gfs <EOL> else : <EOL> return [ ] <EOL> def pub_get_offered_vlans ( self , set = None ) : <EOL> from foam . app import admin_apih <EOL> return admin_apih . adminOfferVlanTags ( set , False ) <EOL> def pub_test_api_access ( self , sayHello ) : <EOL> if sayHello == <NUM_LIT:1> : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" <EOL> def successResult ( self , value ) : <EOL> code_dict = dict ( geni_code = <NUM_LIT:0> ) <EOL> return dict ( code = code_dict , <EOL> value = value , <EOL> output = "<STR_LIT>" ) <EOL> def errorResult ( self , code , output ) : <EOL> code_dict = dict ( geni_code = code ) <EOL> return dict ( code = code_dict , <EOL> value = "<STR_LIT>" , <EOL> output = output ) <EOL> def setup ( app ) : <EOL> legexpapi = XMLRPCHandler ( '<STR_LIT>' ) <EOL> legexpapi . connect ( app , '<STR_LIT>' ) <EOL> legexpapi . register_instance ( AMLegExpAPI ( app . logger ) ) <EOL> app . logger . info ( "<STR_LIT>" ) <EOL> return legexpapi </s>
