Vsphere_virtual_machine: Keep template as it is and apply the
customizations and add devices in the new server. When finished PowerOn
This commit is contained in:
parent
8dd4b155e0
commit
8c49403132
|
@ -890,22 +890,6 @@ func (vm *virtualMachine) deployVirtualMachine(c *govmomi.Client) error {
|
|||
}
|
||||
log.Printf("[DEBUG] template: %#v", template)
|
||||
|
||||
devices, err := template.Device(context.TODO())
|
||||
if err != nil {
|
||||
log.Printf("[DEBUG] Template devices can't be found")
|
||||
return err
|
||||
}
|
||||
|
||||
for _, dvc := range devices {
|
||||
// Issue 3559/3560: Delete all ethernet devices to add the correct ones later
|
||||
if devices.Type(dvc) == "ethernet" {
|
||||
err := template.RemoveDevice(context.TODO(), dvc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var resourcePool *object.ResourcePool
|
||||
if vm.resourcePool == "" {
|
||||
if vm.cluster == "" {
|
||||
|
@ -1013,7 +997,6 @@ func (vm *virtualMachine) deployVirtualMachine(c *govmomi.Client) error {
|
|||
NumCPUs: vm.vcpu,
|
||||
NumCoresPerSocket: 1,
|
||||
MemoryMB: vm.memoryMb,
|
||||
DeviceChange: networkDevices,
|
||||
}
|
||||
log.Printf("[DEBUG] virtual machine config spec: %v", configSpec)
|
||||
|
||||
|
@ -1040,8 +1023,7 @@ func (vm *virtualMachine) deployVirtualMachine(c *govmomi.Client) error {
|
|||
Location: relocateSpec,
|
||||
Template: false,
|
||||
Config: &configSpec,
|
||||
Customization: &customSpec,
|
||||
PowerOn: true,
|
||||
PowerOn: false,
|
||||
}
|
||||
log.Printf("[DEBUG] clone spec: %v", cloneSpec)
|
||||
|
||||
|
@ -1061,6 +1043,43 @@ func (vm *virtualMachine) deployVirtualMachine(c *govmomi.Client) error {
|
|||
}
|
||||
log.Printf("[DEBUG] new vm: %v", newVM)
|
||||
|
||||
devices, err := newVM.Device(context.TODO())
|
||||
if err != nil {
|
||||
log.Printf("[DEBUG] Template devices can't be found")
|
||||
return err
|
||||
}
|
||||
|
||||
for _, dvc := range devices {
|
||||
// Issue 3559/3560: Delete all ethernet devices to add the correct ones later
|
||||
if devices.Type(dvc) == "ethernet" {
|
||||
err := newVM.RemoveDevice(context.TODO(), dvc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
// Add Network devices
|
||||
for _, dvc := range networkDevices {
|
||||
err := newVM.AddDevice(
|
||||
context.TODO(), dvc.GetVirtualDeviceConfigSpec().Device)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
taskb, err := newVM.Customize(context.TODO(), customSpec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
_, err = taskb.WaitForResult(context.TODO(), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Printf("[DEBUG]VM customization finished")
|
||||
|
||||
newVM.PowerOn(context.TODO())
|
||||
|
||||
ip, err := newVM.WaitForIP(context.TODO())
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Reference in New Issue