<s> """<STR_LIT>""" <EOL> import os <EOL> import sys <EOL> import netaddr <EOL> import simplejson as json <EOL> from novalib import execute , execute_get_output <EOL> OVS_OFCTL = '<STR_LIT>' <EOL> class OvsFlow ( object ) : <EOL> def __init__ ( self , bridge , params ) : <EOL> self . bridge = bridge <EOL> self . params = params <EOL> def add ( self , rule ) : <EOL> execute ( OVS_OFCTL , '<STR_LIT>' , self . bridge , rule % self . params ) <EOL> def clear_flows ( self , ofport ) : <EOL> execute ( OVS_OFCTL , '<STR_LIT>' , self . bridge , "<STR_LIT>" % ofport ) <EOL> def main ( command , vif_raw , net_type ) : <EOL> if command not in ( '<STR_LIT>' , '<STR_LIT>' ) : <EOL> return <EOL> vif_name , dom_id , vif_index = vif_raw . split ( '<STR_LIT:->' ) <EOL> vif = "<STR_LIT>" % ( vif_name , dom_id , vif_index ) <EOL> bridge = "<STR_LIT>" % vif_index <EOL> xsls = execute_get_output ( '<STR_LIT>' , <EOL> '<STR_LIT>' % dom_id ) <EOL> macs = [ line . split ( "<STR_LIT:=>" ) [ <NUM_LIT:0> ] . strip ( ) for line in xsls . splitlines ( ) ] <EOL> for mac in macs : <EOL> xsread = execute_get_output ( '<STR_LIT>' , <EOL> '<STR_LIT>' % <EOL> ( dom_id , mac ) ) <EOL> data = json . loads ( xsread ) <EOL> if data [ "<STR_LIT:label>" ] == "<STR_LIT>" : <EOL> this_vif = "<STR_LIT>" % dom_id <EOL> else : <EOL> this_vif = "<STR_LIT>" % dom_id <EOL> if vif == this_vif : <EOL> vif_ofport = execute_get_output ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , vif , '<STR_LIT>' ) <EOL> params = dict ( VIF_NAME = vif , <EOL> MAC = data [ '<STR_LIT>' ] , <EOL> OF_PORT = vif_ofport ) <EOL> ovs = OvsFlow ( bridge , params ) <EOL> if command == '<STR_LIT>' : <EOL> ovs . clear_flows ( vif_ofport ) <EOL> if command == '<STR_LIT>' : <EOL> if net_type in ( '<STR_LIT>' , '<STR_LIT:all>' ) and '<STR_LIT>' in data : <EOL> for ip4 in data [ '<STR_LIT>' ] : <EOL> ovs . params . update ( { '<STR_LIT>' : ip4 [ '<STR_LIT>' ] } ) <EOL> apply_ovs_ipv4_flows ( ovs , bridge , params ) <EOL> if net_type in ( '<STR_LIT>' , '<STR_LIT:all>' ) and '<STR_LIT>' in data : <EOL> for ip6 in data [ '<STR_LIT>' ] : <EOL> link_local = str ( netaddr . EUI ( data [ '<STR_LIT>' ] ) . eui64 ( ) . ipv6_link_local ( ) ) <EOL> ovs . params . update ( { '<STR_LIT>' : link_local } ) <EOL> ovs . params . update ( { '<STR_LIT>' : ip6 [ '<STR_LIT>' ] } ) <EOL> apply_ovs_ipv6_flows ( ovs , bridge , params ) <EOL> def apply_ovs_ipv4_flows ( ovs , bridge , params ) : <EOL> ovs . add ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> def apply_ovs_ipv6_flows ( ovs , bridge , params ) : <EOL> ovs . add ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> ovs . add ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> if len ( sys . argv ) != <NUM_LIT:4> : <EOL> print "<STR_LIT>" % os . path . basename ( sys . argv [ <NUM_LIT:0> ] ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> else : <EOL> command , vif_raw , net_type = sys . argv [ <NUM_LIT:1> : <NUM_LIT:4> ] <EOL> main ( command , vif_raw , net_type ) </s>
