mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Merge pull request #3652 from foehn/master
Vsphere_virtual_machine: Network interfaces
This commit is contained in:
commit
b95e3fd1a2
@ -1000,7 +1000,6 @@ func (vm *virtualMachine) deployVirtualMachine(c *govmomi.Client) error {
|
|||||||
NumCPUs: vm.vcpu,
|
NumCPUs: vm.vcpu,
|
||||||
NumCoresPerSocket: 1,
|
NumCoresPerSocket: 1,
|
||||||
MemoryMB: vm.memoryMb,
|
MemoryMB: vm.memoryMb,
|
||||||
DeviceChange: networkDevices,
|
|
||||||
}
|
}
|
||||||
log.Printf("[DEBUG] virtual machine config spec: %v", configSpec)
|
log.Printf("[DEBUG] virtual machine config spec: %v", configSpec)
|
||||||
|
|
||||||
@ -1024,11 +1023,10 @@ func (vm *virtualMachine) deployVirtualMachine(c *govmomi.Client) error {
|
|||||||
|
|
||||||
// make vm clone spec
|
// make vm clone spec
|
||||||
cloneSpec := types.VirtualMachineCloneSpec{
|
cloneSpec := types.VirtualMachineCloneSpec{
|
||||||
Location: relocateSpec,
|
Location: relocateSpec,
|
||||||
Template: false,
|
Template: false,
|
||||||
Config: &configSpec,
|
Config: &configSpec,
|
||||||
Customization: &customSpec,
|
PowerOn: false,
|
||||||
PowerOn: true,
|
|
||||||
}
|
}
|
||||||
log.Printf("[DEBUG] clone spec: %v", cloneSpec)
|
log.Printf("[DEBUG] clone spec: %v", cloneSpec)
|
||||||
|
|
||||||
@ -1048,6 +1046,43 @@ func (vm *virtualMachine) deployVirtualMachine(c *govmomi.Client) error {
|
|||||||
}
|
}
|
||||||
log.Printf("[DEBUG] new vm: %v", newVM)
|
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())
|
ip, err := newVM.WaitForIP(context.TODO())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
Reference in New Issue
Block a user