<s> import logging <EOL> from ryu . controller import event <EOL> from ryu . lib . dpid import dpid_to_str <EOL> from ryu . base import app_manager <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class EventConfSwitchDelDPID ( event . EventBase ) : <EOL> def __init__ ( self , dpid ) : <EOL> super ( EventConfSwitchDelDPID , self ) . __init__ ( ) <EOL> self . dpid = dpid <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % dpid_to_str ( self . dpid ) <EOL> class EventConfSwitchSet ( event . EventBase ) : <EOL> def __init__ ( self , dpid , key , value ) : <EOL> super ( EventConfSwitchSet , self ) . __init__ ( ) <EOL> self . dpid = dpid <EOL> self . key = key <EOL> self . value = value <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % ( <EOL> dpid_to_str ( self . dpid ) , self . key , self . value ) <EOL> class EventConfSwitchDel ( event . EventBase ) : <EOL> def __init__ ( self , dpid , key ) : <EOL> super ( EventConfSwitchDel , self ) . __init__ ( ) <EOL> self . dpid = dpid <EOL> self . key = key <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % ( dpid_to_str ( self . dpid ) , <EOL> self . key ) <EOL> class ConfSwitchSet ( app_manager . RyuApp ) : <EOL> def __init__ ( self ) : <EOL> super ( ConfSwitchSet , self ) . __init__ ( ) <EOL> self . name = '<STR_LIT>' <EOL> self . confs = { } <EOL> def dpids ( self ) : <EOL> return list ( self . confs . keys ( ) ) <EOL> def del_dpid ( self , dpid ) : <EOL> del self . confs [ dpid ] <EOL> self . send_event_to_observers ( EventConfSwitchDelDPID ( dpid ) ) <EOL> def keys ( self , dpid ) : <EOL> return list ( self . confs [ dpid ] . keys ( ) ) <EOL> def set_key ( self , dpid , key , value ) : <EOL> conf = self . confs . setdefault ( dpid , { } ) <EOL> conf [ key ] = value <EOL> self . send_event_to_observers ( EventConfSwitchSet ( dpid , key , value ) ) <EOL> def get_key ( self , dpid , key ) : <EOL> return self . confs [ dpid ] [ key ] <EOL> def del_key ( self , dpid , key ) : <EOL> del self . confs [ dpid ] [ key ] <EOL> self . send_event_to_observers ( EventConfSwitchDel ( dpid , key ) ) <EOL> def __contains__ ( self , item ) : <EOL> """<STR_LIT>""" <EOL> ( dpid , key ) = item <EOL> return dpid in self . confs and key in self . confs [ dpid ] <EOL> def find_dpid ( self , key , value ) : <EOL> for dpid , conf in self . confs . items ( ) : <EOL> if key in conf : <EOL> if conf [ key ] == value : <EOL> return dpid <EOL> return None </s>
