Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: disk_size #411

Merged
merged 1 commit into from
May 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .web-docs/components/builder/vsphere-clone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ necessary for this build to succeed and can be found further down the page.

- `disk_size` (int64) - Specifies the size of the primary disk in MiB.
Cannot be used with `linked_clone`.
-> **Note:** Only the primary disk size can be specified. Additional disks are not supported.

- `linked_clone` (bool) - Specifies that the virtual machine is created as a linked clone from the latest snapshot. Defaults to `false`.
Cannot be used with `disk_size`.`
Expand Down
1 change: 1 addition & 0 deletions builder/vsphere/clone/step_clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type CloneConfig struct {
Template string `mapstructure:"template"`
// Specifies the size of the primary disk in MiB.
// Cannot be used with `linked_clone`.
// -> **Note:** Only the primary disk size can be specified. Additional disks are not supported.
DiskSize int64 `mapstructure:"disk_size"`
// Specifies that the virtual machine is created as a linked clone from the latest snapshot. Defaults to `false`.
// Cannot be used with `disk_size`.`
Expand Down
14 changes: 9 additions & 5 deletions builder/vsphere/driver/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ type Disk struct {
}

type StorageConfig struct {
DiskControllerType []string // example: "scsi", "pvscsi", "nvme", "lsilogic"
DiskControllerType []string // Example: "scsi", "pvscsi", "nvme", "lsilogic"
Storage []Disk
}

func (c *StorageConfig) AddStorageDevices(existingDevices object.VirtualDeviceList) ([]types.BaseVirtualDeviceConfigSpec, error) {
newDevices := object.VirtualDeviceList{}

// Create new controller based on existing devices list and add it to the new devices list
// to confirm creation
// Create new controller based on existing devices list and add it to the new devices list.
var controllers []types.BaseVirtualController
for _, controllerType := range c.DiskControllerType {
var device types.BaseVirtualDevice
Expand Down Expand Up @@ -69,6 +68,8 @@ func (c *StorageConfig) AddStorageDevices(existingDevices object.VirtualDeviceLi
return newDevices.ConfigSpec(types.VirtualDeviceConfigSpecOperationAdd)
}

// Returns the first virtual disk found in the devices list.
// TODO: Add support for multiple disks.
func findDisk(devices object.VirtualDeviceList) (*types.VirtualDisk, error) {
var disks []*types.VirtualDisk
for _, device := range devices {
Expand All @@ -80,9 +81,12 @@ func findDisk(devices object.VirtualDeviceList) (*types.VirtualDisk, error) {

switch len(disks) {
case 0:
return nil, errors.New("VM has no disks")
// No disks found.
return nil, errors.New("error finding virtual disk")
case 1:
// Single disk found.
return disks[0], nil
}
return nil, errors.New("VM has multiple disks")
// More than one disk found.
return nil, errors.New("more than one virtual disk found, only a single disk is allowed")
}
1 change: 1 addition & 0 deletions builder/vsphere/driver/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ func (vm *VirtualMachineDriver) Customize(spec types.CustomizationSpec) error {
return task.Wait(vm.driver.ctx)
}

// TODO: Add support to resize multiple disks.
func (vm *VirtualMachineDriver) ResizeDisk(diskSize int64) ([]types.BaseVirtualDeviceConfigSpec, error) {
devices, err := vm.vm.Device(vm.driver.ctx)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- `disk_size` (int64) - Specifies the size of the primary disk in MiB.
Cannot be used with `linked_clone`.
-> **Note:** Only the primary disk size can be specified. Additional disks are not supported.

- `linked_clone` (bool) - Specifies that the virtual machine is created as a linked clone from the latest snapshot. Defaults to `false`.
Cannot be used with `disk_size`.`
Expand Down