github.com/k8snetworkplumbingwg/sriov-network-operator@v1.2.1-0.20240408194816-2d2e5a45d453/pkg/host/internal/lib/ethtool/ethtool.go (about)

     1  package ethtool
     2  
     3  import (
     4  	"github.com/safchain/ethtool"
     5  )
     6  
     7  func New() EthtoolLib {
     8  	return &libWrapper{}
     9  }
    10  
    11  //go:generate ../../../../../bin/mockgen -destination mock/mock_ethtool.go -source ethtool.go
    12  type EthtoolLib interface {
    13  	// Features retrieves features of the given interface name.
    14  	Features(ifaceName string) (map[string]bool, error)
    15  	// FeatureNames shows supported features by their name.
    16  	FeatureNames(ifaceName string) (map[string]uint, error)
    17  	// Change requests a change in the given device's features.
    18  	Change(ifaceName string, config map[string]bool) error
    19  }
    20  
    21  type libWrapper struct{}
    22  
    23  // Features retrieves features of the given interface name.
    24  func (w *libWrapper) Features(ifaceName string) (map[string]bool, error) {
    25  	e, err := ethtool.NewEthtool()
    26  	if err != nil {
    27  		return nil, err
    28  	}
    29  	defer e.Close()
    30  	return e.Features(ifaceName)
    31  }
    32  
    33  // FeatureNames shows supported features by their name.
    34  func (w *libWrapper) FeatureNames(ifaceName string) (map[string]uint, error) {
    35  	e, err := ethtool.NewEthtool()
    36  	if err != nil {
    37  		return nil, err
    38  	}
    39  	defer e.Close()
    40  	return e.FeatureNames(ifaceName)
    41  }
    42  
    43  // Change requests a change in the given device's features.
    44  func (w *libWrapper) Change(ifaceName string, config map[string]bool) error {
    45  	e, err := ethtool.NewEthtool()
    46  	if err != nil {
    47  		return err
    48  	}
    49  	defer e.Close()
    50  	return e.Change(ifaceName, config)
    51  }