func cmdDel(args *skel.CmdArgs) error {
	conf, err := util.ParseConfig(args.StdinData)
	if err != nil {
		return err
	}

	netns, err := ns.GetNS(args.Netns)
	if err != nil {
		return fmt.Errorf("failed to open netns %s: %w", args.Netns, err)
	}
	defer netns.Close()

	var portPrefix string
	var contIfVeth *netlink.Veth
	contIfName := args.IfName
	err = ns.WithNetNSPath(netns.Path(), func(_ ns.NetNS) error {
		l, err := netlink.LinkByName(contIfName)
		if err != nil {
			if _, ok := err.(netlink.LinkNotFoundError); ok {
				return fmt.Errorf("%s not exists in ns", contIfName)
			}
			return fmt.Errorf("failed to link by name %s: %v", contIfName, err)
		}
		contIfVeth = l.(*netlink.Veth)
		return nil
	})
	if err != nil {
		return fmt.Errorf("failed to exec in ns: %v", err)
	}
	hostIfLink, err := netlink.LinkByIndex(contIfVeth.ParentIndex)
	if err != nil {
		if _, ok := err.(netlink.LinkNotFoundError); ok {
			return nil
		}
		return fmt.Errorf("faild to link by index: %v", err)
	}
	hostIfVeth := hostIfLink.(*netlink.Veth)
	hostIfName := hostIfVeth.Name
	if strings.HasPrefix(hostIfName, "tap") {
		portPrefix = hostIfName[3:]
	} else {
		return fmt.Errorf("host veth name err: %s", hostIfName)
	}

	// delete qvo, qvb
	qvoName := fmt.Sprintf("qvo%s", portPrefix)

	// output, err := ovs.Exec(ovs.IfExists, "--with-iface", "del-port", "br-int", nicName)
	ovsArgs := []string{"--if-exists", "--with-iface", "del-port", "br-int", qvoName}
	output, err := exec.Command(OvsVsCtl, ovsArgs...).CombinedOutput()
	if err != nil {
		return fmt.Errorf("ovs del port failed %q: %v", output, err)
	}

	// delete qvo
	err = delLinkByName(qvoName)
	if err != nil {
		return err
	}

	// delete qbr
	qbrName := fmt.Sprintf("qbr%s", portPrefix)
	err = delLinkByName(qbrName)
	if err != nil {
		return err
	}

	// delete hostIface
	err = delLinkByName(hostIfName)
	if err != nil {
		return err
	}

	return types.PrintResult(&current.Result{
		CNIVersion: conf.CNIVersion,
	}, conf.CNIVersion)
}
// cmdDel is called for DELETE requests
cmdDel is called for DELETE requests
// cmdDel is called for DELETE requests
func cmdDel(args *skel.CmdArgs) error {
	conf, err := util.ParseConfig(args.StdinData)
	if err != nil {
		return err
	}
	netns, err := ns.GetNS(args.Netns)
	if err != nil {
		return fmt.Errorf("failed to open netns %s: %w", args.Netns, err)
	}
	defer netns.Close()
	var portPrefix string
	var contIfVeth *netlink.Veth
	contIfName := args.IfName
	err = ns.WithNetNSPath(netns.Path(), func(_ ns.NetNS) error {
		l, err := netlink.LinkByName(contIfName)
		if err != nil {
			if _, ok := err.(netlink.LinkNotFoundError); ok {
				return fmt.Errorf("%s not exists in ns", contIfName)
			}
			return fmt.Errorf("failed to link by name %s: %v", contIfName, err)
		}
		contIfVeth = l.(*netlink.Veth)
		return nil
	})
	if err != nil {
		return fmt.Errorf("failed to exec in ns: %v", err)
	}
	hostIfLink, err := netlink.LinkByIndex(contIfVeth.ParentIndex)
	if err != nil {
		if _, ok := err.(netlink.LinkNotFoundError); ok {
			return nil
		}
		return fmt.Errorf("faild to link by index: %v", err)
	}
	hostIfVeth := hostIfLink.(*netlink.Veth)
	hostIfName := hostIfVeth.Name
	if strings.HasPrefix(hostIfName, "tap") {
		portPrefix = hostIfName[3:]
	} else {
		return fmt.Errorf("host veth name err: %s", hostIfName)
	}
	qvoName := fmt.Sprintf("qvo%s", portPrefix)
	ovsArgs := []string{"--if-exists", "--with-iface", "del-port", "br-int", qvoName}
	output, err := exec.Command(OvsVsCtl, ovsArgs...).CombinedOutput()
	if err != nil {
		return fmt.Errorf("ovs del port failed %q: %v", output, err)
	}
	err = delLinkByName(qvoName)
	if err != nil {
		return err
	}
	qbrName := fmt.Sprintf("qbr%s", portPrefix)
	err = delLinkByName(qbrName)
	if err != nil {
		return err
	}
	err = delLinkByName(hostIfName)
	if err != nil {
		return err
	}
	return types.PrintResult(&current.Result{
		CNIVersion: conf.CNIVersion,
	}, conf.CNIVersion)
}
func cmdDel ( args * skel . CmdArgs ) error { conf , err := util . ParseConfig ( args . StdinData ) if err != nil { return err } netns , err := ns . GetNS ( args . Netns ) if err != nil { return fmt . Errorf ( " " , args . Netns , err ) } defer netns . Close ( ) var portPrefix string var contIfVeth * netlink . Veth contIfName := args . IfName err = ns . WithNetNSPath ( netns . Path ( ) , func ( _ ns . NetNS ) error { l , err := netlink . LinkByName ( contIfName ) if err != nil { if _ , ok := err . ( netlink . LinkNotFoundError ) ; ok { return fmt . Errorf ( " " , contIfName ) } return fmt . Errorf ( " " , contIfName , err ) } contIfVeth = l . ( * netlink . Veth ) return nil } ) if err != nil { return fmt . Errorf ( " " , err ) } hostIfLink , err := netlink . LinkByIndex ( contIfVeth . ParentIndex ) if err != nil { if _ , ok := err . ( netlink . LinkNotFoundError ) ; ok { return nil } return fmt . Errorf ( " " , err ) } hostIfVeth := hostIfLink . ( * netlink . Veth ) hostIfName := hostIfVeth . Name if strings . HasPrefix ( hostIfName , " " ) { portPrefix = hostIfName [ 3 : ] } else { return fmt . Errorf ( " " , hostIfName ) } qvoName := fmt . Sprintf ( " " , portPrefix ) ovsArgs := [ ] string { " " , " " , " " , " " , qvoName } output , err := exec . Command ( OvsVsCtl , ovsArgs ... ) . CombinedOutput ( ) if err != nil { return fmt . Errorf ( " " , output , err ) } err = delLinkByName ( qvoName ) if err != nil { return err } qbrName := fmt . Sprintf ( " " , portPrefix ) err = delLinkByName ( qbrName ) if err != nil { return err } err = delLinkByName ( hostIfName ) if err != nil { return err } return types . PrintResult ( & current . Result { CNIVersion : conf . CNIVersion , } , conf . CNIVersion ) }
cmdDel is called for DELETE requests
cmdDel is called for DELETE requests
// delete qvo, qvb // output, err := ovs.Exec(ovs.IfExists, "--with-iface", "del-port", "br-int", nicName) // delete qvo // delete qbr // delete hostIface