Skip to content

Commit

Permalink
Merge pull request #3527 from bzed/disk_prov
Browse files Browse the repository at this point in the history
govc: Support thick/eager disk opts on vm.create
  • Loading branch information
dougm authored Sep 9, 2024
2 parents bc0c8a0 + 1892eec commit 139b19e
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 @@ -6472,6 +6472,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 @@ -61,6 +61,8 @@ type create struct {
on bool
force bool
controller string
eager bool
thick bool
annotation string
firmware string
version string
Expand Down Expand Up @@ -129,6 +131,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)
if cli.ShowUnreleased() {
Expand Down Expand Up @@ -550,13 +554,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 139b19e

Please sign in to comment.