<s> from networking_onos . common import utils as onos_utils <EOL> ADD_INTF_BY_PORT = <NUM_LIT:1> <EOL> ADD_INTF_BY_SUBNET = <NUM_LIT:2> <EOL> class ONOSRouter ( object ) : <EOL> """<STR_LIT>""" <EOL> def send_router_msg ( self , msg_type , entity_path , entity ) : <EOL> onos_utils . send_msg ( self . onos_path , self . onos_auth , <EOL> msg_type , entity_path , entity ) <EOL> def handle_create_router ( self , router_dict ) : <EOL> self . send_router_msg ( '<STR_LIT>' , '<STR_LIT>' , <EOL> { '<STR_LIT>' : router_dict } ) <EOL> def handle_update_router ( self , router_dict , id ) : <EOL> url_path = '<STR_LIT>' + '<STR_LIT:/>' + id <EOL> resource = router_dict . copy ( ) <EOL> onos_utils . safe_delete_from_dict ( resource , <EOL> [ '<STR_LIT:id>' , '<STR_LIT>' , '<STR_LIT:status>' ] ) <EOL> self . send_router_msg ( '<STR_LIT>' , url_path , { '<STR_LIT>' : resource } ) <EOL> def handle_delete_router ( self , id ) : <EOL> url_path = '<STR_LIT>' + '<STR_LIT:/>' + id <EOL> self . send_router_msg ( '<STR_LIT>' , url_path , None ) <EOL> def handle_add_router_interface ( self , new_router , router_id , <EOL> interface_info , intf_add_type ) : <EOL> url_path = '<STR_LIT>' + '<STR_LIT:/>' + router_id + '<STR_LIT>' <EOL> router_dict = self . _prepare_router_dict ( router_id , interface_info , <EOL> new_router , intf_add_type ) <EOL> self . send_router_msg ( '<STR_LIT>' , url_path , router_dict ) <EOL> def handle_remove_router_interface ( self , new_router , router_id , <EOL> interface_info , intf_add_type ) : <EOL> url_path = '<STR_LIT>' + '<STR_LIT:/>' + router_id + '<STR_LIT>' <EOL> router_dict = self . _prepare_router_dict ( router_id , interface_info , <EOL> new_router , intf_add_type ) <EOL> self . send_router_msg ( '<STR_LIT>' , url_path , router_dict ) <EOL> def _prepare_router_dict ( self , router_id , interface_info , <EOL> new_router , add_type ) : <EOL> if add_type == ADD_INTF_BY_SUBNET : <EOL> _port_id = new_router [ '<STR_LIT>' ] <EOL> _subnet_id = interface_info [ '<STR_LIT>' ] <EOL> else : <EOL> _port_id = interface_info [ '<STR_LIT>' ] <EOL> _subnet_id = new_router [ '<STR_LIT>' ] <EOL> router_dict = { '<STR_LIT>' : _subnet_id , <EOL> '<STR_LIT>' : _port_id , <EOL> '<STR_LIT:id>' : router_id , <EOL> '<STR_LIT>' : new_router [ '<STR_LIT>' ] } <EOL> return router_dict </s>
