Skip to content

Commit

Permalink
Fetch Vlan IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
machacekondra committed Nov 28, 2024
1 parent 4d6a3f1 commit dabe1d1
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
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,
})
}
}
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

0 comments on commit dabe1d1

Please sign in to comment.