diff --git a/pkg/apis/compute/host_tap.go b/pkg/apis/compute/host_tap.go index 403d0ecb0f..2cec4e921d 100644 --- a/pkg/apis/compute/host_tap.go +++ b/pkg/apis/compute/host_tap.go @@ -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"` } diff --git a/pkg/apis/compute/net_tap_flows.go b/pkg/apis/compute/net_tap_flows.go index fbe68f6856..e8babe61e5 100644 --- a/pkg/apis/compute/net_tap_flows.go +++ b/pkg/apis/compute/net_tap_flows.go @@ -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"` diff --git a/pkg/compute/models/host_taps.go b/pkg/compute/models/host_taps.go index ae1566c0bd..4123a722cf 100644 --- a/pkg/compute/models/host_taps.go +++ b/pkg/compute/models/host_taps.go @@ -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 } diff --git a/pkg/compute/models/net_tap_flows.go b/pkg/compute/models/net_tap_flows.go index fed3c19482..1a880758c4 100644 --- a/pkg/compute/models/net_tap_flows.go +++ b/pkg/compute/models/net_tap_flows.go @@ -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 } diff --git a/pkg/compute/models/net_tap_services.go b/pkg/compute/models/net_tap_services.go index 8fc8061a78..dfa8170735 100644 --- a/pkg/compute/models/net_tap_services.go +++ b/pkg/compute/models/net_tap_services.go @@ -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) diff --git a/pkg/hostman/guestman/qemu-kvmhelper.go b/pkg/hostman/guestman/qemu-kvmhelper.go index 7bac496a80..78c5ca1a20 100644 --- a/pkg/hostman/guestman/qemu-kvmhelper.go +++ b/pkg/hostman/guestman/qemu-kvmhelper.go @@ -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 { diff --git a/pkg/hostman/hostinfo/hostbridge/hostbridge.go b/pkg/hostman/hostinfo/hostbridge/hostbridge.go index a053435a76..8e81139473 100644 --- a/pkg/hostman/hostinfo/hostbridge/hostbridge.go +++ b/pkg/hostman/hostinfo/hostbridge/hostbridge.go @@ -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 } diff --git a/pkg/hostman/hostinfo/hostbridge/ovs.go b/pkg/hostman/hostinfo/hostbridge/ovs.go index 5199b1d4fe..5896e65090 100644 --- a/pkg/hostman/hostinfo/hostbridge/ovs.go +++ b/pkg/hostman/hostinfo/hostbridge/ovs.go @@ -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") diff --git a/pkg/hostman/options/options.go b/pkg/hostman/options/options.go index 4ee1df34cb..6bccb0eb05 100644 --- a/pkg/hostman/options/options.go +++ b/pkg/hostman/options/options.go @@ -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"`