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 b90a4ba commit b5a0ad7
Show file tree
Hide file tree
Showing 4 changed files with 23 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 @@ -85,8 +85,9 @@ const (
// Network
fTag = "tag"
// PortGroup
fDVSwitch = "config.distributedVirtualSwitch"
fKey = "key"
fDVSwitch = "config.distributedVirtualSwitch"
fDVSwitchVlan = "config.defaultPortConfig"
fKey = "key"
// DV Switch
fDVSwitchHost = "config.host"
// Datastore
Expand Down Expand Up @@ -676,6 +677,7 @@ func (r *Collector) propertySpec() []types.PropertySpec {
PathSet: []string{
fName,
fDVSwitch,
fDVSwitchVlan,
fTag,
fKey,
},
Expand Down
15 changes: 15 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 @@ -394,6 +396,19 @@ func (v *NetworkAdapter) Apply(u types.ObjectUpdate) {
}
case fDVSwitch:
v.model.DVSwitch = v.Ref(p.Val)
case fDVSwitchVlan:
if portSettings, cast := p.Val.(types.VMwareDVSPortSetting); cast {
if vlanIdSpec, cast := portSettings.Vlan.(*types.VmwareDistributedVirtualSwitchVlanIdSpec); cast && int(vlanIdSpec.VlanId) > 0 {
v.model.VlanId = strconv.Itoa(int(vlanIdSpec.VlanId))
}
if vlanIdSpec, cast := portSettings.Vlan.(*types.VmwareDistributedVirtualSwitchTrunkVlanSpec); cast {
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 @@ -199,6 +199,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 @@ -214,6 +215,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.NetDvSwitch:
r.Host = m.Host
}
Expand Down

0 comments on commit b5a0ad7

Please sign in to comment.