ovs

package
v0.0.0-...-9649b88 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2020 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ASCII0      = 48
	ASCIIA      = 65
	ASCIIa      = 97
	NumRange    = 10
	LetterRange = 26
)
View Source
const MaxTimesRetryCreateVeth int = 10
View Source
const MaxTimesRetryFindVeth int = 10

Variables

View Source
var DeleteVethPair = func(vethPair VethPair) error {
	link, err := GetLinkByName(vethPair.VethNameOfPod)
	if err == nil {
		err := netlink.LinkDel(link)
		if err != nil {
			klog.Errorf("Delete veth [%v] error: %v", link, err)
			return err
		}
		return nil
	}
	klog.Errorf("Cannot find veth [%v] error: %v", vethPair.VethNameOfPod, err)
	link, err = GetLinkByName(vethPair.VethNameOfBridge)
	if err == nil {
		err := netlink.LinkDel(link)
		if err != nil {
			klog.Errorf("Delete veth [%v] error: %v", link, err)
			return err
		}
		return nil
	}
	klog.Errorf("Cannot find veth [%v] error: %v", vethPair.VethNameOfBridge, err)
	return errors.New("cannot find veth pair error")
}

To delete a veth pair

View Source
var GetNwMechDriver = func(phyNw, PortType, confPath string) (string, error) {
	cfg, err := InitConfig(confPath)
	if err != nil {
		klog.Errorf("Init config from [%v] error! %v", confPath, err)
		return "", err
	}
	driver, err := GetDriverbyPortType(cfg, phyNw, PortType)
	if err != nil {
		klog.Errorf("GetDriverbyPortType VnicType:%v, PhyNw:%v, return err:%v", PortType, phyNw, err)
		return "", err
	}
	if strings.Contains(driver, "sriov_nic") {
		driver = strings.TrimRight(driver, "_nic")
	}
	return driver, nil
}

To get driver name by physical network

View Source
var GetOvsBrg = func(phyNw string, confPath string) (string, error) {
	phyNwStr, err := GetPhyNwOvsMapStr(confPath)
	if err != nil {
		klog.Errorf("GetOvsBrg: GetBrgMaps() error! %v", err)
		return "", err
	}
	phyNwOvsPair, err := GetPhyNwOvsPair(phyNwStr)
	if err != nil {
		klog.Errorf("GetOvsBrg: GetPhyNwOvsPair(phyNwStr) error %v, ", err)
		return "", err
	}
	if len(*phyNwOvsPair) == 1 && phyNw == "" {
		klog.Info("phyNw is nil and ovs has configure one bridge!")
		for _, ovsBrg := range *phyNwOvsPair {
			return ovsBrg, nil
		}
	}
	ovsBrg, err1 := (*phyNwOvsPair)[phyNw]
	if err1 == false {
		klog.Errorf("Never configured [%v] in config file!", phyNw)
		return "", errors.New("phyNet does not exist error")
	}
	return ovsBrg, nil
}

To get ovs bridge by phyNet

View Source
var TimeSleepFunc = func(d time.Duration) {
	time.Sleep(d)
}

Functions

func CreateVeth

func CreateVeth(vethPair *VethPair) error

func GetCommonDriver

func GetCommonDriver(cfg *ini.File, phyNw, PortType string) (string, error)

func GetDriverFromSection

func GetDriverFromSection(section *ini.Section, phyNw string) (string, error)

func GetDriverbyPortType

func GetDriverbyPortType(cfg *ini.File, phyNw, PortType string) (string, error)

func GetLinkByName

func GetLinkByName(name string) (netlink.Link, error)

func GetMappingKey

func GetMappingKey(section *ini.Section) string

func GetNormalDriver

func GetNormalDriver(cfg *ini.File, phyNw string) (string, error)

func GetPhyNwOvsMapStr

func GetPhyNwOvsMapStr(confPath string) (string, error)

To get phyNet-ovs map string

func GetPhyNwOvsPair

func GetPhyNwOvsPair(phyNwStr string) (*map[string]string, error)

To get phyNet-ovs pair

func GetSectionName

func GetSectionName(PortType string) string

func GetSriovDriver

func GetSriovDriver(cfg *ini.File, phyNw string) (string, error)

func GetVethMac

func GetVethMac(vethName string) (string, error)

To get veth mac by veth name

func GetVethPairMacs

func GetVethPairMacs(vethPair *VethPair) error

func GetrandSuffix

func GetrandSuffix() string

func InitConfig

func InitConfig(confPath string) (*ini.File, error)

To init a config by config file

func WaitOvsUsable

func WaitOvsUsable() error

Types

type VethPair

type VethPair struct {
	VethNameOfPod    string `json:"vetha"`
	VethNameOfBridge string `json:"vethb"`
	VethMacOfPod     string `json:"vetha_mac"`
	VethMacOfBridge  string `json:"vethb_mac"`
}

func CreateVethPair

func CreateVethPair(args ...string) (VethPair, error)

To create a veth pair for pod & ovs

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL