mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-09-01 15:07:17 +08:00
Hotfix/qj tap service mirrorfixes2 (#14476)
* fix: no details for net_tap_flows * fix: tap support bugfixes Co-authored-by: Qiu Jian <qiujian@yunionyun.com>
This commit is contained in:
@@ -21,6 +21,7 @@ type SMirrorConfig struct {
|
||||
Direction string `json:"direction"`
|
||||
}
|
||||
|
||||
/*
|
||||
type SHostBridgeMirrorConfig struct {
|
||||
TapHostIp string `json:"tap_host_ip"`
|
||||
|
||||
@@ -36,6 +37,7 @@ type SHostBridgeMirrorConfig struct {
|
||||
|
||||
Port []string `json:"port"`
|
||||
}
|
||||
*/
|
||||
|
||||
type STapServiceConfig struct {
|
||||
TapHostIp string `json:"tap_host_ip"`
|
||||
@@ -44,11 +46,11 @@ type STapServiceConfig struct {
|
||||
|
||||
Ifname string `json:"ifname"`
|
||||
|
||||
Mirrors []SHostBridgeMirrorConfig
|
||||
Mirrors []SMirrorConfig
|
||||
}
|
||||
|
||||
type SHostTapConfig struct {
|
||||
Taps []STapServiceConfig `json:"taps"`
|
||||
|
||||
Mirrors []SHostBridgeMirrorConfig `json:"mirrors"`
|
||||
Mirrors []SMirrorConfig `json:"mirrors"`
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ type NetTapFlowCreateInput struct {
|
||||
|
||||
WireId string `json:"wire_id" help:"id or name of wire to tap with"`
|
||||
|
||||
VlanId int `json:"vlan_id" help:"vlan id of vswitch to tap with"`
|
||||
VlanId *int `json:"vlan_id" help:"vlan id of vswitch to tap with"`
|
||||
|
||||
GuestId string `json:"guest_id" help:"id or name of vm to tap with"`
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sort"
|
||||
|
||||
"yunion.io/x/jsonutils"
|
||||
"yunion.io/x/pkg/errors"
|
||||
@@ -37,7 +38,8 @@ func (h *SHost) GetDetailsTapConfig(ctx context.Context, userCred mcclient.Token
|
||||
}
|
||||
mirrors = append(mirrors, mirror)
|
||||
}
|
||||
conf.Mirrors = groupMirrorConfig(mirrors)
|
||||
sort.Sort(sMirrorConfigs(mirrors))
|
||||
conf.Mirrors = mirrors // groupMirrorConfig(mirrors)
|
||||
|
||||
return conf, nil
|
||||
}
|
||||
|
||||
@@ -191,6 +191,7 @@ func (manager *SNetTapFlowManager) FetchCustomizeColumns(
|
||||
}
|
||||
flow := objs[i].(*SNetTapFlow)
|
||||
tapIds[i] = flow.TapId
|
||||
rows[i] = flow.getMoreDetails(ctx, rows[i])
|
||||
}
|
||||
tapIdMap, err := db.FetchIdNameMap2(NetTapServiceManager, tapIds)
|
||||
if err != nil {
|
||||
@@ -286,8 +287,8 @@ func (manager *SNetTapFlowManager) ValidateCreateData(
|
||||
input.SourceId = host.Id
|
||||
input.MacAddr = ""
|
||||
input.NetId = wire.Id
|
||||
if input.VlanId <= 0 || input.VlanId > 4095 {
|
||||
return input, errors.Wrapf(httperrors.ErrInputParameter, "invalid vlan id %d", input.VlanId)
|
||||
if input.VlanId != nil && (*input.VlanId <= 0 || *input.VlanId > 4095) {
|
||||
return input, errors.Wrapf(httperrors.ErrInputParameter, "invalid vlan id %d", *input.VlanId)
|
||||
}
|
||||
case api.TapFlowGuestNic:
|
||||
guestObj, err := GuestManager.FetchByIdOrName(userCred, input.GuestId)
|
||||
@@ -327,7 +328,7 @@ func (manager *SNetTapFlowManager) ValidateCreateData(
|
||||
input.SourceId = guest.Id
|
||||
input.MacAddr = gn.MacAddr
|
||||
input.NetId = gn.NetworkId
|
||||
input.VlanId = 0
|
||||
input.VlanId = nil
|
||||
default:
|
||||
return input, errors.Wrapf(httperrors.ErrInputParameter, "invalid flow type %s", input.Type)
|
||||
}
|
||||
@@ -337,6 +338,10 @@ func (manager *SNetTapFlowManager) ValidateCreateData(
|
||||
if !utils.IsInStringArray(input.Direction, api.TapFlowDirections) {
|
||||
return input, errors.Wrapf(httperrors.ErrNotSupported, "unsupported direction %s", input.Direction)
|
||||
}
|
||||
if input.Enabled == nil {
|
||||
trueVal := true
|
||||
input.Enabled = &trueVal
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -392,7 +392,8 @@ func (srv *SNetTapService) getConfig() (api.STapServiceConfig, error) {
|
||||
mirrors = append(mirrors, mc)
|
||||
}
|
||||
}
|
||||
conf.Mirrors = groupMirrorConfig(mirrors)
|
||||
sort.Sort(sMirrorConfigs(mirrors))
|
||||
conf.Mirrors = mirrors // groupMirrorConfig(mirrors)
|
||||
|
||||
conf.TapHostIp = srv.getTapHostIp()
|
||||
conf.MacAddr = srv.MacAddr
|
||||
@@ -428,6 +429,7 @@ func (a sMirrorConfigs) Less(i, j int) bool {
|
||||
return a[i].FlowId < a[j].FlowId
|
||||
}
|
||||
|
||||
/*
|
||||
func groupMirrorConfig(mirrors []api.SMirrorConfig) []api.SHostBridgeMirrorConfig {
|
||||
sort.Sort(sMirrorConfigs(mirrors))
|
||||
ret := make([]api.SHostBridgeMirrorConfig, 0)
|
||||
@@ -458,6 +460,7 @@ func groupMirrorConfig(mirrors []api.SMirrorConfig) []api.SHostBridgeMirrorConfi
|
||||
}
|
||||
return ret
|
||||
}
|
||||
*/
|
||||
|
||||
func (manager *SNetTapServiceManager) getEnabledTapServiceByGuestId(guestId string) *SNetTapService {
|
||||
srvs, err := manager.getTapServicesByGuestId(guestId, true)
|
||||
|
||||
@@ -169,13 +169,15 @@ func (s *SKVMGuestInstance) GetDiskAddr(idx int) int {
|
||||
func (s *SKVMGuestInstance) getNicUpScriptPath(nic jsonutils.JSONObject) string {
|
||||
ifname, _ := nic.GetString("ifname")
|
||||
bridge, _ := nic.GetString("bridge")
|
||||
return path.Join(s.HomeDir(), fmt.Sprintf("if-up-%s-%s.sh", bridge, ifname))
|
||||
dev := guestManager.GetHost().GetBridgeDev(bridge)
|
||||
return path.Join(s.HomeDir(), fmt.Sprintf("if-up-%s-%s.sh", dev.Bridge(), ifname))
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) getNicDownScriptPath(nic jsonutils.JSONObject) string {
|
||||
ifname, _ := nic.GetString("ifname")
|
||||
bridge, _ := nic.GetString("bridge")
|
||||
return path.Join(s.HomeDir(), fmt.Sprintf("if-down-%s-%s.sh", bridge, ifname))
|
||||
dev := guestManager.GetHost().GetBridgeDev(bridge)
|
||||
return path.Join(s.HomeDir(), fmt.Sprintf("if-down-%s-%s.sh", dev.Bridge(), ifname))
|
||||
}
|
||||
|
||||
func (s *SKVMGuestInstance) generateNicScripts(nic jsonutils.JSONObject) error {
|
||||
|
||||
@@ -59,6 +59,8 @@ type IBridgeDriver interface {
|
||||
|
||||
getUpScripts(nic jsonutils.JSONObject, isSlave bool) (string, error)
|
||||
getDownScripts(nic jsonutils.JSONObject, isSlave bool) (string, error)
|
||||
|
||||
Bridge() string
|
||||
}
|
||||
|
||||
type SBaseBridgeDriver struct {
|
||||
@@ -97,6 +99,10 @@ func (d *SBaseBridgeDriver) GetMac() string {
|
||||
return d.bridge.Mac
|
||||
}
|
||||
|
||||
func (d *SBaseBridgeDriver) Bridge() string {
|
||||
return d.bridge.String()
|
||||
}
|
||||
|
||||
func (d *SBaseBridgeDriver) PersistentConfig() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -128,7 +128,7 @@ func (o *SOVSBridgeDriver) GenerateIfupScripts(scriptPath string, nic jsonutils.
|
||||
|
||||
func (o *SOVSBridgeDriver) getUpScripts(nic jsonutils.JSONObject, isSlave bool) (string, error) {
|
||||
var (
|
||||
bridge, _ = nic.GetString("bridge")
|
||||
bridge = o.bridge.String()
|
||||
ifname, _ = nic.GetString("ifname")
|
||||
ip, _ = nic.GetString("ip")
|
||||
mac, _ = nic.GetString("mac")
|
||||
@@ -198,7 +198,7 @@ func (o *SOVSBridgeDriver) getUpScripts(nic jsonutils.JSONObject, isSlave bool)
|
||||
|
||||
func (o *SOVSBridgeDriver) getDownScripts(nic jsonutils.JSONObject, isSlave bool) (string, error) {
|
||||
var (
|
||||
bridge, _ = nic.GetString("bridge")
|
||||
bridge = o.bridge.String()
|
||||
ifname, _ = nic.GetString("ifname")
|
||||
ip, _ = nic.GetString("ip")
|
||||
mac, _ = nic.GetString("mac")
|
||||
|
||||
@@ -142,7 +142,7 @@ type SHostOptions struct {
|
||||
SdnEnableEipMan bool `help:"enable eip network manager in sdnagent" default:"$SDN_ENABLE_EIP_MAN|false"`
|
||||
SdnEnableTcMan bool `help:"enable TC manager in sdnagent" default:"$SDN_ENABLE_TC_MAN|true"`
|
||||
|
||||
SdnEnableTapMan bool `help:"enable tap service"`
|
||||
SdnEnableTapMan bool `help:"enable tap service" default:"$SDN_ENABLE_TAP_MAN|true"`
|
||||
TapBridgeName string `help:"bridge name for tap service" default:"brtap"`
|
||||
|
||||
SdnAllowConntrackInvalid bool `help:"allow packets marked by conntrack as INVALID to pass" default:"$SDN_ALLOW_CONNTRACK_INVALID|false"`
|
||||
|
||||
Reference in New Issue
Block a user