Example #1
0
func (s *VirtualMachineConfigSpec) FindNICs(ctx context.Context, network object.NetworkReference) ([]types.BaseVirtualDeviceConfigSpec, error) {
	if network == nil {
		return nil, fmt.Errorf("no network provided")
	}

	backing, err := network.EthernetCardBackingInfo(ctx)
	if err != nil {
		return nil, err
	}

	var dcs []types.BaseVirtualDeviceConfigSpec
	for _, d := range s.DeviceChange {
		dev := d.GetVirtualDeviceConfigSpec().Device
		if _, ok := dev.(types.BaseVirtualEthernetCard); ok {
			var dl object.VirtualDeviceList
			dl = append(dl, dev)
			dl = dl.SelectByBackingInfo(backing)
			if len(dl) > 0 {
				dcs = append(dcs, d)
			}
		}
	}

	return dcs, nil
}