*CedZddlZddlZddlZddlmZddlmZddlm Z m Z m Z ddl Z dZ dZd ZGd d eZGd d eZGddeZGddej(Zy)z"netplan SR-IOV rebind command lineN)sleep)utils) PCIDevicebind_vfs_get_pci_slot_nameg?c eZdZy)MLX5VFLAGStateNotFoundN__name__ __module__ __qualname__;/usr/share/netplan/netplan_cli/cli/commands/sriov_rebind.pyr r #rr c eZdZy)MLX5VFLAGStateCannotBeReadNr rrrrr'rrrc eZdZy)MLX5VFLAGStateDisabledNr rrrrr+rrrcfeZdZfdZdZdZdedefdZdefdZ ded e fd Z d ed efd Z xZ S) NetplanSriovRebindc*t|dddy)NrebindzKRebind SR-IOV virtual functions of given physical functions to their driverT) command_id descriptionleaf)super__init__)self __class__s rr!zNetplanSriovRebind.__init__1s H%r"  $rc|jjddd|jjdtdgd|j|_t j d |_d |j_t jtj }|j|jrm|jjt j|jt j|j!t j"d nl|jjt j$|jt j$|j!t j"d |jj'||j)y)Nz --root-dir/zBSearch for configuration files in this root directory instead of /)defaulthelpnetdevs*z*Space separated list of PF interface names)typenargsr&r' sriov_rebindF)streamz%(levelname)s:%(message)sz %(message)s)parser add_argumentstrcommand_rebindfunclogging getLoggerlogger propagate StreamHandlersysstdout parse_argsdebugsetLevelDEBUG setFormatter FormatterINFO addHandler run_command)r" log_handlers rrunzNetplanSriovRebind.run6s7   s&j ! l   C&R ! T'' ''7 % ++3::>   :: KK  /   /  $ $W%6%67R%S T KK  .   .  $ $W%6%6}%E F {+ rc |jD]}t|}t|}|js+|jj dj |P|j||t|j|j}|jj dj |t|y)zeBind virtual functions of SR-IOV devices to their corresponding driver after eswitch mode was changedz1{} does not seem to be a SR-IOV physical functionz{}: bound {} VFsN) r(rris_pfr5r;format!_perform_hardware_specific_quirksrvfsdriverlen)r"ifacepci_addrpcidev bound_vfss rr1z!NetplanSriovRebind.command_rebindQs\\ QE)%0Hx(F<< !!"U"\"\]b"cd  2 25& A V]];I KK  077IO P QrrLpfc|jdvrJtj}|j|jtj }|j ||jjD]}|jr|j|k(s|j|k(s.|jjdx}sL|j}|j|s"|j j#|d|d|j j#|d |j%||j j#|dy y #t&$r"|j j#|dYt($r"|j j#|dY0t*$r"|j j#|d YYwxYw) z Perform any hardware-specific quirks for the given SR-IOV device to make sure it's ready before the bind. ) mlx5_corebondz - LAG mode z is not supported by VF LAGz+ - waiting for the LAG state to be 'active'z - VF LAG state is 'active'z - VF LAG state cannot be readz& - VF LAG state debugfs file not foundz1 - VF LAG state is still 'disabled' after waitingN)rJnetplanParserload_yaml_hierarchyroot_dirStateimport_parser_results ethernetsvalues _has_matchset_nameidlinksget _bond_mode_is_bond_mode_supportedr5r;"_wait_for_mlx5_pf_lag_state_activerr r)r"rLrPr.np_statenetdef bond_link bond_modes rrHz4NetplanSriovRebind._perform_hardware_specific_quirksbs 99 %^^%F  & &t}} 5}}H  * *6 2",,335 W%%&//U*BvyyTYGY$*LL$4$4V$<># $ $ $s ;A)rrrr!rDr1r0rrHrcboolrbrt __classcell__)r#s@rrr/s`$ 6Q")Ws)W )WV"%Y"%HDCDDD$s$s$rr)__doc__r3rpr8timerrsriovrrrrTrsrornrur rrNetplanCommandrrrrrsm$) ;;  Y    Y M$--M$r