From dabe1d170f418b7f696b483902b2d32746c7b115 Mon Sep 17 00:00:00 2001 From: Ondra Machacek Date: Wed, 27 Nov 2024 12:18:30 +0100 Subject: [PATCH] Fetch Vlan IDs Jira: https://issues.redhat.com/browse/ECOPROJECT-2359 Signed-off-by: Ondra Machacek --- .../provider/container/vsphere/collector.go | 6 ++++-- .../provider/container/vsphere/model.go | 17 +++++++++++++++++ pkg/controller/provider/model/vsphere/model.go | 2 ++ pkg/controller/provider/web/vsphere/network.go | 2 ++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/pkg/controller/provider/container/vsphere/collector.go b/pkg/controller/provider/container/vsphere/collector.go index 4835772ce..fdacbc83c 100644 --- a/pkg/controller/provider/container/vsphere/collector.go +++ b/pkg/controller/provider/container/vsphere/collector.go @@ -87,8 +87,9 @@ const ( fTag = "tag" fSummary = "summary" // PortGroup - fDVSwitch = "config.distributedVirtualSwitch" - fKey = "key" + fDVSwitch = "config.distributedVirtualSwitch" + fDVSwitchVlan = "config.defaultPortConfig" + fKey = "key" // DV Switch fDVSwitchHost = "config.host" // Datastore @@ -688,6 +689,7 @@ func (r *Collector) propertySpec() []types.PropertySpec { PathSet: []string{ fName, fDVSwitch, + fDVSwitchVlan, fTag, fKey, }, diff --git a/pkg/controller/provider/container/vsphere/model.go b/pkg/controller/provider/container/vsphere/model.go index e0b5f0e2a..11f9a70c1 100644 --- a/pkg/controller/provider/container/vsphere/model.go +++ b/pkg/controller/provider/container/vsphere/model.go @@ -1,6 +1,7 @@ package vsphere import ( + "fmt" "net/url" "sort" "strconv" @@ -306,6 +307,7 @@ func (v *HostAdapter) Apply(u types.ObjectUpdate) { Key: portGroup.Key, Name: portGroup.Spec.Name, Switch: portGroup.Vswitch, + VlanId: portGroup.Spec.VlanId, }) } } @@ -398,6 +400,21 @@ func (v *NetworkAdapter) Apply(u types.ObjectUpdate) { if s, cast := p.Val.(types.OpaqueNetworkSummary); cast { v.model.Key = s.OpaqueNetworkId } + case fDVSwitchVlan: + if portSettings, cast := p.Val.(types.VMwareDVSPortSetting); cast { + switch vlanIdSpec := portSettings.Vlan.(type) { + case *types.VmwareDistributedVirtualSwitchVlanIdSpec: + if int(vlanIdSpec.VlanId) > 0 { + v.model.VlanId = strconv.Itoa(int(vlanIdSpec.VlanId)) + } + case *types.VmwareDistributedVirtualSwitchTrunkVlanSpec: + refList := []string{} + for _, val := range vlanIdSpec.VlanId { + refList = append(refList, fmt.Sprintf("%d-%d", val.Start, val.End)) + } + v.model.VlanId = strings.Join(refList, ",") + } + } } } } diff --git a/pkg/controller/provider/model/vsphere/model.go b/pkg/controller/provider/model/vsphere/model.go index e17b0a8cd..9e6bf7ad6 100644 --- a/pkg/controller/provider/model/vsphere/model.go +++ b/pkg/controller/provider/model/vsphere/model.go @@ -201,6 +201,7 @@ type PortGroup struct { Key string `json:"key"` Name string `json:"name"` Switch string `json:"vSwitch"` + VlanId int32 `json:"vlanId"` } type Switch struct { @@ -216,6 +217,7 @@ type Network struct { DVSwitch Ref `sql:""` Key string `sql:""` Host []DVSHost `sql:""` + VlanId string `sql:""` } type DVSHost struct { diff --git a/pkg/controller/provider/web/vsphere/network.go b/pkg/controller/provider/web/vsphere/network.go index 65f12e23f..edc39ddbc 100644 --- a/pkg/controller/provider/web/vsphere/network.go +++ b/pkg/controller/provider/web/vsphere/network.go @@ -176,6 +176,7 @@ type Network struct { Resource Variant string `json:"variant"` DVSwitch *model.Ref `json:"dvSwitch,omitempty"` + VlanId string `json:"vlanId"` Host []model.DVSHost `json:"host"` Tag string `json:"tag,omitempty"` Key string `json:"key,omitempty"` @@ -191,6 +192,7 @@ func (r *Network) With(m *model.Network) { case model.NetDvPortGroup: r.DVSwitch = &m.DVSwitch r.Key = m.Key + r.VlanId = m.VlanId case model.OpaqueNetwork: r.Key = m.Key case model.NetDvSwitch: