本文整理汇总了Golang中github.com/vmware/govmomi/vim25/types.VirtualMachineCloneSpec.Customization方法的典型用法代码示例。如果您正苦于以下问题:Golang VirtualMachineCloneSpec.Customization方法的具体用法?Golang VirtualMachineCloneSpec.Customization怎么用?Golang VirtualMachineCloneSpec.Customization使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/vmware/govmomi/vim25/types.VirtualMachineCloneSpec
的用法示例。
在下文中一共展示了VirtualMachineCloneSpec.Customization方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: resourceVirtualMachineCreate
//.........这里部分代码省略.........
confSpec.MemoryMB = int64(d.Get("memory").(int))
}
params := d.Get("configuration_parameters").(map[string]interface{})
var ov []types.BaseOptionValue
if len(params) > 0 {
for k, v := range params {
key := k
value := v
o := types.OptionValue{
Key: key,
Value: &value,
}
ov = append(ov, &o)
}
confSpec.ExtraConfig = ov
}
cloneSpec := types.VirtualMachineCloneSpec{
Location: relocateSpec,
Config: &confSpec,
PowerOn: d.Get("power_on").(bool),
}
if d.Get("linked_clone").(bool) {
if image_mo.Snapshot == nil {
return fmt.Errorf("`linked_clone=true`, but image VM has no snapshots")
}
cloneSpec.Snapshot = image_mo.Snapshot.CurrentSnapshot
}
domain := d.Get("domain").(string)
ip_address := d.Get("ip_address").(string)
if domain != "" {
if image_mo.Guest.ToolsVersionStatus2 == "guestToolsNotInstalled" {
return fmt.Errorf("VMware tools are not installed in base VM")
}
if !strings.Contains(image_mo.Config.GuestFullName, "Linux") && !strings.Contains(image_mo.Config.GuestFullName, "CentOS") {
return fmt.Errorf("Guest customization is supported only for Linux. Base image OS is: %s", image_mo.Config.GuestFullName)
}
customizationSpec := types.CustomizationSpec{
GlobalIPSettings: types.CustomizationGlobalIPSettings{},
Identity: &types.CustomizationLinuxPrep{
HostName: &types.CustomizationVirtualMachineName{},
Domain: domain,
},
NicSettingMap: []types.CustomizationAdapterMapping{
{
Adapter: types.CustomizationIPSettings{},
},
},
}
if ip_address != "" {
mask := d.Get("subnet_mask").(string)
if mask == "" {
return fmt.Errorf("'subnet_mask' must be set, if static 'ip_address' is specified")
}
customizationSpec.NicSettingMap[0].Adapter.Ip = &types.CustomizationFixedIp{
IpAddress: ip_address,
}
customizationSpec.NicSettingMap[0].Adapter.SubnetMask = d.Get("subnet_mask").(string)
gateway := d.Get("gateway").(string)
if gateway != "" {
customizationSpec.NicSettingMap[0].Adapter.Gateway = []string{gateway}
}
} else {
customizationSpec.NicSettingMap[0].Adapter.Ip = &types.CustomizationDhcpIpGenerator{}
}
cloneSpec.Customization = &customizationSpec
} else if ip_address != "" {
return fmt.Errorf("'domain' must be set, if static 'ip_address' is specified")
}
task, err := image.Clone(context.TODO(), folder, d.Get("name").(string), cloneSpec)
if err != nil {
return fmt.Errorf("Error clonning vm: %s", err)
}
info, err := task.WaitForResult(context.TODO(), nil)
if err != nil {
return fmt.Errorf("Error clonning vm: %s", err)
}
vm_mor := info.Result.(types.ManagedObjectReference)
d.SetId(vm_mor.Value)
vm := object.NewVirtualMachine(client, vm_mor)
// workaround for https://github.com/vmware/govmomi/issues/218
if ip_address == "" && d.Get("power_on").(bool) {
ip, err := vm.WaitForIP(context.TODO())
if err != nil {
log.Printf("[ERROR] Cannot read ip address: %s", err)
} else {
d.Set("ip_address", ip)
d.SetConnInfo(map[string]string{
"type": "ssh",
"host": ip,
})
}
}
return nil
}