<s> '''<STR_LIT>''' <EOL> from pprint import pprint <EOL> from expedient . common . rpc4django import rpcmethod <EOL> from decorator import decorator <EOL> from openflow . optin_manager . dummyfv . models import DummyFVSlice , DummyFVDevice , DummyFVLink , DummyFVRule , DummyFV <EOL> from django . contrib . auth . models import User <EOL> @ decorator <EOL> def get_fv ( func , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> fv_id = kwargs [ '<STR_LIT>' ] <EOL> fv = DummyFV . objects . get ( id = fv_id ) <EOL> kwargs [ '<STR_LIT>' ] = fv <EOL> return func ( * args , ** kwargs ) <EOL> @ decorator <EOL> def checkUser ( 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> if not kwargs [ '<STR_LIT>' ] . user . is_authenticated ( ) : <EOL> raise Exception ( "<STR_LIT>" % func . func_name ) <EOL> else : <EOL> kwargs [ '<STR_LIT:user>' ] = kwargs [ '<STR_LIT>' ] . user <EOL> return func ( * args , ** kwargs ) <EOL> @ checkUser <EOL> @ get_fv <EOL> @ rpcmethod ( name = "<STR_LIT>" , url_name = "<STR_LIT>" , <EOL> signature = [ '<STR_LIT>' , '<STR_LIT:string>' , '<STR_LIT:string>' , '<STR_LIT:string>' , '<STR_LIT:string>' ] ) <EOL> def createSlice ( sliceName , passwd , controller_url , slice_email , ** kwargs ) : <EOL> slice = DummyFVSlice . objects . create ( fv = kwargs [ '<STR_LIT>' ] , <EOL> name = sliceName , password = passwd , <EOL> controller_url = controller_url , <EOL> email = slice_email ) <EOL> print "<STR_LIT>" % ( <EOL> slice . name , slice . password , slice . controller_url , slice . email , <EOL> ) <EOL> return True <EOL> @ checkUser <EOL> @ get_fv <EOL> @ rpcmethod ( name = "<STR_LIT>" , url_name = "<STR_LIT>" , <EOL> signature = [ '<STR_LIT>' ] ) <EOL> def listDevices ( ** kwargs ) : <EOL> return list ( DummyFVDevice . objects . filter ( <EOL> fv = kwargs [ '<STR_LIT>' ] ) . values_list ( '<STR_LIT>' , flat = True ) ) <EOL> @ checkUser <EOL> @ get_fv <EOL> @ rpcmethod ( name = "<STR_LIT>" , url_name = "<STR_LIT>" , <EOL> signature = [ '<STR_LIT>' , '<STR_LIT:string>' ] ) <EOL> def getDeviceInfo ( dpidStr , ** kwargs ) : <EOL> return { } <EOL> @ checkUser <EOL> @ get_fv <EOL> @ rpcmethod ( name = "<STR_LIT>" , url_name = "<STR_LIT>" , <EOL> signature = [ '<STR_LIT>' ] ) <EOL> def getLinks ( ** kwargs ) : <EOL> return [ { "<STR_LIT>" : link . dst_dev . dpid , <EOL> "<STR_LIT>" : link . dst_port , <EOL> "<STR_LIT>" : link . src_dev . dpid , <EOL> "<STR_LIT>" : link . src_port } for link in DummyFVLink . objects . filter ( fv = kwargs [ '<STR_LIT>' ] ) ] <EOL> @ checkUser <EOL> @ get_fv <EOL> @ rpcmethod ( name = "<STR_LIT>" , url_name = "<STR_LIT>" , <EOL> signature = [ '<STR_LIT>' , '<STR_LIT:string>' ] ) <EOL> def deleteSlice ( sliceName , ** kwargs ) : <EOL> DummyFVSlice . objects . filter ( <EOL> fv = kwargs [ '<STR_LIT>' ] ) . get ( name = sliceName ) . delete ( ) <EOL> return True <EOL> @ checkUser <EOL> @ get_fv <EOL> @ rpcmethod ( name = "<STR_LIT>" , url_name = "<STR_LIT>" , <EOL> signature = [ '<STR_LIT:string>' , '<STR_LIT:string>' ] ) <EOL> def ping ( data , ** kwargs ) : <EOL> return "<STR_LIT>" % ( data ) <EOL> @ checkUser <EOL> @ get_fv <EOL> @ rpcmethod ( name = "<STR_LIT>" , url_name = "<STR_LIT>" , <EOL> signature = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> def changeFlowSpace ( changes , ** kwargs ) : <EOL> funcs = { "<STR_LIT>" : add_flowspace , <EOL> "<STR_LIT>" : remove_flowspace , <EOL> "<STR_LIT>" : change_flowspace } <EOL> ret = [ ] <EOL> for change in changes : <EOL> operation = change . pop ( "<STR_LIT>" ) <EOL> result = funcs [ operation ] ( kwargs [ '<STR_LIT>' ] , change ) <EOL> ret . append ( result ) <EOL> return ret <EOL> def add_flowspace ( fv , change ) : <EOL> import re <EOL> slice_re = re . compile ( r"<STR_LIT>" ) <EOL> axn_matches = slice_re . findall ( change [ '<STR_LIT>' ] ) <EOL> for axn in axn_matches : <EOL> try : <EOL> slice = DummyFVSlice . objects . filter ( <EOL> fv = fv ) . get ( name = axn . group ( "<STR_LIT:name>" ) ) <EOL> except DummyFVSlice . DoesNotExist : <EOL> raise Exception ( "<STR_LIT>" + "<STR_LIT>" % axn . group ( "<STR_LIT:name>" ) ) <EOL> rule = DummyFVRule ( <EOL> fv = fv , <EOL> match = change [ '<STR_LIT>' ] , <EOL> priority = int ( change [ '<STR_LIT>' ] ) , <EOL> dpid = change [ '<STR_LIT>' ] , <EOL> actions = change [ '<STR_LIT>' ] , <EOL> ) <EOL> rule . save ( ) <EOL> return rule . id <EOL> def remove_flowspace ( fv , change ) : <EOL> id = change [ '<STR_LIT:id>' ] <EOL> rule = DummyFVRule . objects . filter ( fv = fv ) . get ( id = int ( id ) ) <EOL> rule . delete ( ) <EOL> return id <EOL> def change_flowspace ( fv , change ) : <EOL> import re <EOL> slice_re = re . compile ( r"<STR_LIT>" ) <EOL> axn_matches = slice_re . findall ( change [ '<STR_LIT>' ] ) <EOL> for axn in axn_matches : <EOL> try : <EOL> slice = DummyFVSlice . objects . filter ( <EOL> fv = fv ) . get ( name = axn . group ( "<STR_LIT:name>" ) ) <EOL> except DummyFVSlice . DoesNotExist : <EOL> raise Exception ( <EOL> "<STR_LIT>" % axn . group ( "<STR_LIT:name>" ) <EOL> ) <EOL> try : <EOL> rule = DummyFVRule . objects . filter ( fv = fv ) . get ( id = change [ '<STR_LIT:id>' ] ) <EOL> except DummyFVRule . DoesNotExist : <EOL> raise Exception ( "<STR_LIT>" + "<STR_LIT>" % change [ '<STR_LIT:id>' ] ) <EOL> rule . match = change [ '<STR_LIT>' ] <EOL> rule . dpid = change [ '<STR_LIT>' ] <EOL> rule . actions = change [ '<STR_LIT>' ] <EOL> rule . priority = int ( change [ '<STR_LIT>' ] ) <EOL> rule . save ( ) <EOL> return rule . id </s>
