Skip to content

Commit 88c38fb

Browse files
committed
Propagate placement host with VM fast deploy
If the VM must be created on a specific host - like for instance storage - that host must be provided to CreateVM for fast deploy like we do with DeployOVF for content library.
1 parent 4474c72 commit 88c38fb

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

pkg/providers/vsphere/vmlifecycle/create_fastdeploy.go

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,15 @@ func fastDeploy(
202202
})
203203
logger.Info("Got pool", "pool", pool.Reference())
204204

205+
var host *object.HostSystem
206+
if createArgs.HostMoID != "" {
207+
host = object.NewHostSystem(vimClient, vimtypes.ManagedObjectReference{
208+
Type: "HostSystem",
209+
Value: createArgs.HostMoID,
210+
})
211+
logger.Info("Got host", "host", host.Reference())
212+
}
213+
205214
// Determine the type of fast deploy operation.
206215
var fastDeployMode string
207216

@@ -222,6 +231,7 @@ func fastDeploy(
222231
vmCtx,
223232
folder,
224233
pool,
234+
host,
225235
createArgs.ConfigSpec,
226236
createArgs.Datastores[0].MoRef,
227237
disks,
@@ -234,6 +244,7 @@ func fastDeploy(
234244
datacenter,
235245
folder,
236246
pool,
247+
host,
237248
createArgs.ConfigSpec,
238249
diskSpecs,
239250
dstDiskFormat,
@@ -245,6 +256,7 @@ func fastDeployLinked(
245256
ctx context.Context,
246257
folder *object.Folder,
247258
pool *object.ResourcePool,
259+
host *object.HostSystem,
248260
configSpec vimtypes.VirtualMachineConfigSpec,
249261
datastoreRef vimtypes.ManagedObjectReference,
250262
disks []*vimtypes.VirtualDisk,
@@ -290,14 +302,15 @@ func fastDeployLinked(
290302
}
291303
}
292304

293-
return fastDeployCreateVM(ctx, logger, folder, pool, configSpec)
305+
return fastDeployCreateVM(ctx, logger, folder, pool, host, configSpec)
294306
}
295307

296308
func fastDeployDirect(
297309
ctx context.Context,
298310
datacenter *object.Datacenter,
299311
folder *object.Folder,
300312
pool *object.ResourcePool,
313+
host *object.HostSystem,
301314
configSpec vimtypes.VirtualMachineConfigSpec,
302315
diskSpecs []*vimtypes.VirtualDeviceConfigSpec,
303316
diskFormat vimtypes.DatastoreSectorFormat,
@@ -341,14 +354,15 @@ func fastDeployDirect(
341354
}
342355
}
343356

344-
return fastDeployCreateVM(ctx, logger, folder, pool, configSpec)
357+
return fastDeployCreateVM(ctx, logger, folder, pool, host, configSpec)
345358
}
346359

347360
func fastDeployCreateVM(
348361
ctx context.Context,
349362
logger logr.Logger,
350363
folder *object.Folder,
351364
pool *object.ResourcePool,
365+
host *object.HostSystem,
352366
configSpec vimtypes.VirtualMachineConfigSpec) (*vimtypes.ManagedObjectReference, error) {
353367

354368
logger.Info("Creating VM", "configSpec", vimtypes.ToString(configSpec))
@@ -357,7 +371,7 @@ func fastDeployCreateVM(
357371
ctx,
358372
configSpec,
359373
pool,
360-
nil)
374+
host)
361375
if err != nil {
362376
return nil, fmt.Errorf("failed to call create task: %w", err)
363377
}

0 commit comments

Comments
 (0)