Skip to content

Commit

Permalink
Merge pull request #2878 from bryanv/bryanv/vcsim-remove-nic-guest-net
Browse files Browse the repository at this point in the history
  • Loading branch information
embano1 committed Jun 17, 2022
2 parents 63aa05d + 361c90c commit 7556da8
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions simulator/virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1163,15 +1163,15 @@ func (vm *VirtualMachine) configureDevice(ctx *Context, devices object.VirtualDe
c.MacAddress = vm.generateMAC(*c.UnitNumber - 7) // Note 7 == PCI offset
}

if spec.Operation == types.VirtualDeviceConfigSpecOperationAdd {
vm.Guest.Net = append(vm.Guest.Net, types.GuestNicInfo{
Network: name,
IpAddress: nil,
MacAddress: c.MacAddress,
Connected: true,
DeviceConfigId: c.Key,
})
vm.Guest.Net = append(vm.Guest.Net, types.GuestNicInfo{
Network: name,
IpAddress: nil,
MacAddress: c.MacAddress,
Connected: true,
DeviceConfigId: c.Key,
})

if spec.Operation == types.VirtualDeviceConfigSpecOperationAdd {
if c.ResourceAllocation == nil {
c.ResourceAllocation = &types.VirtualEthernetCardResourceAllocation{
Reservation: types.NewInt64(0),
Expand Down Expand Up @@ -1352,6 +1352,13 @@ func (vm *VirtualMachine) removeDevice(ctx *Context, devices object.VirtualDevic
net.Value = b.Port.PortgroupKey
}

for j, nicInfo := range vm.Guest.Net {
if nicInfo.DeviceConfigId == key {
vm.Guest.Net = append(vm.Guest.Net[:j], vm.Guest.Net[j+1:]...)
break
}
}

networks := vm.Network
RemoveReference(&networks, net)
ctx.Map.Update(vm, []types.PropertyChange{
Expand Down

0 comments on commit 7556da8

Please sign in to comment.