Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch Vlan IDs #1225

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pkg/controller/provider/container/vsphere/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -688,6 +689,7 @@ func (r *Collector) propertySpec() []types.PropertySpec {
PathSet: []string{
fName,
fDVSwitch,
fDVSwitchVlan,
fTag,
fKey,
},
Expand Down
17 changes: 17 additions & 0 deletions pkg/controller/provider/container/vsphere/model.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vsphere

import (
"fmt"
"net/url"
"sort"
"strconv"
Expand Down Expand Up @@ -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,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

})
}
}
Expand Down Expand Up @@ -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, ",")
}
}
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/provider/model/vsphere/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -216,6 +217,7 @@ type Network struct {
DVSwitch Ref `sql:""`
Key string `sql:""`
Host []DVSHost `sql:""`
VlanId string `sql:""`
}

type DVSHost struct {
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/provider/web/vsphere/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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:
Expand Down
Loading