本文整理汇总了Golang中github.com/hooklift/terraform-provider-vix/provider/vix.VM.VNetworkAdapters方法的典型用法代码示例。如果您正苦于以下问题:Golang VM.VNetworkAdapters方法的具体用法?Golang VM.VNetworkAdapters怎么用?Golang VM.VNetworkAdapters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/hooklift/terraform-provider-vix/provider/vix.VM
的用法示例。
在下文中一共展示了VM.VNetworkAdapters方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: net_tf_to_vix
func net_tf_to_vix(d *schema.ResourceData, vm *vix.VM) error {
tf_to_vix_virtual_device := func(attr string) (govix.VNetDevice, error) {
switch attr {
case "vlance":
return govix.NETWORK_DEVICE_VLANCE, nil
case "e1000":
return govix.NETWORK_DEVICE_E1000, nil
case "vmxnet3":
return govix.NETWORK_DEVICE_VMXNET3, nil
default:
return "", fmt.Errorf("[ERROR] Invalid virtual network device: %s", attr)
}
}
tf_to_vix_network_type := func(attr string) (govix.NetworkType, error) {
switch attr {
case "bridged":
return govix.NETWORK_BRIDGED, nil
case "nat":
return govix.NETWORK_NAT, nil
case "hostonly":
return govix.NETWORK_HOSTONLY, nil
case "custom":
return govix.NETWORK_CUSTOM, nil
default:
return "", fmt.Errorf("[ERROR] Invalid virtual network adapter type: %s", attr)
}
}
// tf_to_vix_vswitch := func(attr string) (vix.VSwitch, error) {
// return vix.VSwitch{}, nil
// }
var err error
var errs []error
adaptersCount := d.Get("network_adapter.#").(int)
vm.VNetworkAdapters = make([]*govix.NetworkAdapter, 0, adaptersCount)
for i := 0; i < adaptersCount; i++ {
prefix := fmt.Sprintf("network_adapter.%d.", i)
adapter := new(govix.NetworkAdapter)
if attr, ok := d.Get(prefix + "driver").(string); ok && attr != "" {
adapter.Vdevice, err = tf_to_vix_virtual_device(attr)
}
if attr, ok := d.Get(prefix + "mac_address").(string); ok && attr != "" {
// Only set a MAC address if it is declared as static
// otherwise leave Govix to assign or continue using the generated
// one.
if addrtype, ok := d.Get(prefix + "mac_address_type").(string); ok && addrtype == "static" {
adapter.MacAddress, err = net.ParseMAC(attr)
}
}
if attr, ok := d.Get(prefix + "type").(string); ok && attr != "" {
adapter.ConnType, err = tf_to_vix_network_type(attr)
}
// if attr, ok := adapter["vswitch"].(string); ok && attr != "" {
// vnic.VSwitch, err = tf_to_vix_vswitch(attr)
// }
if err != nil {
errs = append(errs, err)
}
log.Printf("[DEBUG] Network adapter: %+v\n", adapter)
vm.VNetworkAdapters = append(vm.VNetworkAdapters, adapter)
}
if len(errs) > 0 {
return &multierror.Error{Errors: errs}
}
return nil
}