<s> from oslo_log import log as logging <EOL> from neutron . _i18n import _LE , _LI <EOL> from neutron . agent . l2 . extensions import qos <EOL> from neutron . plugins . ml2 . drivers . mech_sriov . agent . common import ( <EOL> exceptions as exc ) <EOL> from neutron . plugins . ml2 . drivers . mech_sriov . agent import eswitch_manager as esm <EOL> from neutron . plugins . ml2 . drivers . mech_sriov . mech_driver import ( <EOL> mech_driver ) <EOL> LOG = logging . getLogger ( __name__ ) <EOL> class QosSRIOVAgentDriver ( qos . QosAgentDriver ) : <EOL> SUPPORTED_RULES = ( <EOL> mech_driver . SriovNicSwitchMechanismDriver . supported_qos_rule_types ) <EOL> def __init__ ( self ) : <EOL> super ( QosSRIOVAgentDriver , self ) . __init__ ( ) <EOL> self . eswitch_mgr = None <EOL> def initialize ( self ) : <EOL> self . eswitch_mgr = esm . ESwitchManager ( ) <EOL> def create_bandwidth_limit ( self , port , rule ) : <EOL> self . update_bandwidth_limit ( port , rule ) <EOL> def update_bandwidth_limit ( self , port , rule ) : <EOL> pci_slot = port [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) <EOL> device = port [ '<STR_LIT>' ] <EOL> self . _set_vf_max_rate ( device , pci_slot , rule . max_kbps ) <EOL> def delete_bandwidth_limit ( self , port ) : <EOL> pci_slot = port [ '<STR_LIT>' ] . get ( '<STR_LIT>' ) <EOL> if port . get ( '<STR_LIT>' ) is None : <EOL> self . eswitch_mgr . clear_max_rate ( pci_slot ) <EOL> else : <EOL> device = port [ '<STR_LIT>' ] <EOL> self . _set_vf_max_rate ( device , pci_slot ) <EOL> def _set_vf_max_rate ( self , device , pci_slot , max_kbps = <NUM_LIT:0> ) : <EOL> if self . eswitch_mgr . device_exists ( device , pci_slot ) : <EOL> try : <EOL> self . eswitch_mgr . set_device_max_rate ( <EOL> device , pci_slot , max_kbps ) <EOL> except exc . SriovNicError : <EOL> LOG . exception ( <EOL> _LE ( "<STR_LIT>" ) , device ) <EOL> else : <EOL> LOG . info ( _LI ( "<STR_LIT>" ) , device ) </s>
