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