Skip to content

Commit

Permalink
govc: Support thick/eager disk opts on vm.create
Browse files Browse the repository at this point in the history
Closes: #3526
Signed-off-by: Bernd Zeimetz <bernd@bzed.de>
  • Loading branch information
bzed committed Aug 21, 2024
1 parent c737066 commit 1892eec
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
2 changes: 2 additions & 0 deletions govc/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -6418,6 +6418,8 @@ Options:
-disk= Disk path (to use existing) OR size (to create new, e.g. 20GB)
-disk-datastore= Datastore for disk file
-disk.controller=scsi Disk controller type
-disk.eager=false Eagerly scrub new disk
-disk.thick=false Thick provision new disk
-ds= Datastore [GOVC_DATASTORE]
-firmware=bios Firmware type [bios|efi]
-folder= Inventory folder [GOVC_FOLDER]
Expand Down
18 changes: 13 additions & 5 deletions govc/vm/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ type create struct {
on bool
force bool
controller string
eager bool
thick bool
annotation string
firmware string
version string
Expand Down Expand Up @@ -126,6 +128,8 @@ func (cmd *create) Register(ctx context.Context, f *flag.FlagSet) {
f.BoolVar(&cmd.on, "on", true, "Power on VM")
f.BoolVar(&cmd.force, "force", false, "Create VM if vmx already exists")
f.StringVar(&cmd.controller, "disk.controller", "scsi", "Disk controller type")
f.BoolVar(&cmd.eager, "disk.eager", false, "Eagerly scrub new disk")
f.BoolVar(&cmd.thick, "disk.thick", false, "Thick provision new disk")
f.StringVar(&cmd.annotation, "annotation", "", "VM description")
f.StringVar(&cmd.firmware, "firmware", FirmwareTypes[0], FirmwareUsage)
f.StringVar(&cmd.profile, "profile", "", "Storage profile name or ID")
Expand Down Expand Up @@ -558,13 +562,17 @@ func (cmd *create) addStorage(devices object.VirtualDeviceList) (object.VirtualD
return nil, err
}

backing := &types.VirtualDiskFlatVer2BackingInfo{
DiskMode: string(types.VirtualDiskModePersistent),
ThinProvisioned: types.NewBool(!cmd.thick),
}
if cmd.thick {
backing.EagerlyScrub = &cmd.eager
}
disk := &types.VirtualDisk{
VirtualDevice: types.VirtualDevice{
Key: devices.NewKey(),
Backing: &types.VirtualDiskFlatVer2BackingInfo{
DiskMode: string(types.VirtualDiskModePersistent),
ThinProvisioned: types.NewBool(true),
},
Key: devices.NewKey(),
Backing: backing,
},
CapacityInKB: cmd.diskByteSize / 1024,
}
Expand Down

0 comments on commit 1892eec

Please sign in to comment.