本文整理匯總了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
}