<s> import os <EOL> from oslo_log import log as logging <EOL> from neutron . agent . linux import ip_lib <EOL> LOG = logging . getLogger ( __name__ ) <EOL> BRIDGE_FS = "<STR_LIT>" <EOL> BRIDGE_INTERFACE_FS = BRIDGE_FS + "<STR_LIT>" <EOL> BRIDGE_INTERFACES_FS = BRIDGE_FS + "<STR_LIT>" <EOL> BRIDGE_PORT_FS_FOR_DEVICE = BRIDGE_FS + "<STR_LIT>" <EOL> BRIDGE_PATH_FOR_DEVICE = BRIDGE_PORT_FS_FOR_DEVICE + '<STR_LIT>' <EOL> def is_bridged_interface ( interface ) : <EOL> if not interface : <EOL> return False <EOL> else : <EOL> return os . path . exists ( BRIDGE_PORT_FS_FOR_DEVICE % interface ) <EOL> def get_interface_bridged_time ( interface ) : <EOL> try : <EOL> return os . stat ( BRIDGE_PORT_FS_FOR_DEVICE % interface ) . st_mtime <EOL> except OSError : <EOL> pass <EOL> def get_bridge_names ( ) : <EOL> return os . listdir ( BRIDGE_FS ) <EOL> class BridgeDevice ( ip_lib . IPDevice ) : <EOL> def _brctl ( self , cmd ) : <EOL> cmd = [ '<STR_LIT>' ] + cmd <EOL> ip_wrapper = ip_lib . IPWrapper ( self . namespace ) <EOL> return ip_wrapper . netns . execute ( cmd , run_as_root = True ) <EOL> @ classmethod <EOL> def addbr ( cls , name , namespace = None ) : <EOL> bridge = cls ( name , namespace ) <EOL> bridge . _brctl ( [ '<STR_LIT>' , bridge . name ] ) <EOL> return bridge <EOL> @ classmethod <EOL> def get_interface_bridge ( cls , interface ) : <EOL> try : <EOL> path = os . readlink ( BRIDGE_PATH_FOR_DEVICE % interface ) <EOL> except OSError : <EOL> return None <EOL> else : <EOL> name = path . rpartition ( '<STR_LIT:/>' ) [ - <NUM_LIT:1> ] <EOL> return cls ( name ) <EOL> def delbr ( self ) : <EOL> return self . _brctl ( [ '<STR_LIT>' , self . name ] ) <EOL> def addif ( self , interface ) : <EOL> return self . _brctl ( [ '<STR_LIT>' , self . name , interface ] ) <EOL> def delif ( self , interface ) : <EOL> return self . _brctl ( [ '<STR_LIT>' , self . name , interface ] ) <EOL> def setfd ( self , fd ) : <EOL> return self . _brctl ( [ '<STR_LIT>' , self . name , str ( fd ) ] ) <EOL> def disable_stp ( self ) : <EOL> return self . _brctl ( [ '<STR_LIT>' , self . name , '<STR_LIT>' ] ) <EOL> def owns_interface ( self , interface ) : <EOL> return os . path . exists ( <EOL> BRIDGE_INTERFACE_FS % { '<STR_LIT>' : self . name , <EOL> '<STR_LIT>' : interface } ) <EOL> def get_interfaces ( self ) : <EOL> try : <EOL> return os . listdir ( BRIDGE_INTERFACES_FS % self . name ) <EOL> except OSError : <EOL> return [ ] </s>
