Skip to content

Commit

Permalink
MTV-1695 | Add missing NIC for opaque network
Browse files Browse the repository at this point in the history
Issue: When user has NSXT managed network it is represented as opaque
network and the VM has opaque nic.

Fix: Add opaque nic model mapping to inventory

Ref: https://issues.redhat.com/browse/MTV-1695

Signed-off-by: Martin Necas <[email protected]>
  • Loading branch information
mnecas committed Nov 28, 2024
1 parent 1fed336 commit da99f3c
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pkg/controller/plan/adapter/vsphere/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ func (r *Builder) mapNetworks(vm *model.VM, object *cnv.VirtualMachineSpec) (err
needed := []vsphere.NIC{}
for _, nic := range vm.NICs {
switch network.Variant {
case vsphere.NetDvPortGroup:
case vsphere.NetDvPortGroup, vsphere.OpaqueNetwork:
if nic.Network.ID == network.Key {
needed = append(needed, nic)
}
Expand Down
22 changes: 21 additions & 1 deletion pkg/controller/provider/container/vsphere/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const (
ComputeResource = "ComputeResource"
Host = "HostSystem"
Network = "Network"
OpaqueNetwork = "OpaqueNetwork"
DVPortGroup = "DistributedVirtualPortgroup"
DVSwitch = "VmwareDistributedVirtualSwitch"
Datastore = "Datastore"
Expand Down Expand Up @@ -83,7 +84,8 @@ const (
fThumbprint = "summary.config.sslThumbprint"
fMgtServerIp = "summary.managementServerIp"
// Network
fTag = "tag"
fTag = "tag"
fSummary = "summary"
// PortGroup
fDVSwitch = "config.distributedVirtualSwitch"
fKey = "key"
Expand Down Expand Up @@ -671,6 +673,15 @@ func (r *Collector) propertySpec() []types.PropertySpec {
fTag,
},
},
{
Type: OpaqueNetwork,
PathSet: []string{
fName,
fParent,
fTag,
fSummary,
},
},
{
Type: DVPortGroup,
PathSet: []string{
Expand Down Expand Up @@ -823,6 +834,15 @@ func (r *Collector) selectAdapter(u types.ObjectUpdate) (Adapter, bool) {
},
},
}
case OpaqueNetwork:
adapter = &NetworkAdapter{
model: model.Network{
Base: model.Base{
Variant: model.OpaqueNetwork,
ID: u.Obj.Value,
},
},
}
case DVPortGroup:
adapter = &NetworkAdapter{
model: model.Network{
Expand Down
6 changes: 6 additions & 0 deletions pkg/controller/provider/container/vsphere/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,10 @@ func (v *NetworkAdapter) Apply(u types.ObjectUpdate) {
}
case fDVSwitch:
v.model.DVSwitch = v.Ref(p.Val)
case fSummary:
if s, cast := p.Val.(types.OpaqueNetworkSummary); cast {
v.model.Key = s.OpaqueNetworkId
}
}
}
}
Expand Down Expand Up @@ -704,6 +708,8 @@ func (v *VmAdapter) Apply(u types.ObjectUpdate) {
}
case *types.VirtualEthernetCardDistributedVirtualPortBackingInfo:
network = backing.Port.PortgroupKey
case *types.VirtualEthernetCardOpaqueNetworkBackingInfo:
network = backing.OpaqueNetworkId
}

devList = append(
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/provider/model/vsphere/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (
// Network.
NetStandard = "Standard"
NetDvPortGroup = "DvPortGroup"
OpaqueNetwork = "OpaqueNetwork"
NetDvSwitch = "DvSwitch"
// Cluster.
ComputeResource = "ComputeResource"
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 @@ -191,6 +191,8 @@ func (r *Network) With(m *model.Network) {
case model.NetDvPortGroup:
r.DVSwitch = &m.DVSwitch
r.Key = m.Key
case model.OpaqueNetwork:
r.Key = m.Key
case model.NetDvSwitch:
r.Host = m.Host
}
Expand Down

0 comments on commit da99f3c

Please sign in to comment.