本文整理汇总了Golang中github.com/vmware/govmomi/find.Finder.Network方法的典型用法代码示例。如果您正苦于以下问题:Golang Finder.Network方法的具体用法?Golang Finder.Network怎么用?Golang Finder.Network使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/vmware/govmomi/find.Finder
的用法示例。
在下文中一共展示了Finder.Network方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: buildNetworkDevice
// buildNetworkDevice builds VirtualDeviceConfigSpec for Network Device.
func buildNetworkDevice(f *find.Finder, label, adapterType string) (*types.VirtualDeviceConfigSpec, error) {
network, err := f.Network(context.TODO(), "*"+label)
if err != nil {
return nil, err
}
backing, err := network.EthernetCardBackingInfo(context.TODO())
if err != nil {
return nil, err
}
if adapterType == "vmxnet3" {
return &types.VirtualDeviceConfigSpec{
Operation: types.VirtualDeviceConfigSpecOperationAdd,
Device: &types.VirtualVmxnet3{
VirtualVmxnet: types.VirtualVmxnet{
VirtualEthernetCard: types.VirtualEthernetCard{
VirtualDevice: types.VirtualDevice{
Key: -1,
Backing: backing,
},
AddressType: string(types.VirtualEthernetCardMacTypeGenerated),
},
},
},
}, nil
} else if adapterType == "e1000" {
return &types.VirtualDeviceConfigSpec{
Operation: types.VirtualDeviceConfigSpecOperationAdd,
Device: &types.VirtualE1000{
VirtualEthernetCard: types.VirtualEthernetCard{
VirtualDevice: types.VirtualDevice{
Key: -1,
Backing: backing,
},
AddressType: string(types.VirtualEthernetCardMacTypeGenerated),
},
},
}, nil
} else {
return nil, fmt.Errorf("Invalid network adapter type.")
}
}
示例2: getNetwork
func (d *Driver) getNetwork(f *find.Finder, ctx context.Context) (net object.NetworkReference, err error) {
// Network
if d.Network != "" {
// Find specified Network
net, err = f.Network(ctx, d.Network)
if err != nil {
return net, err
}
} else {
// Find default Network
net, err = f.DefaultNetwork(ctx)
if err != nil {
return net, err
}
}
log.Debug("Network found: ", net)
return net, nil
}