Resize disk
This commit is contained in:
parent
24805991a6
commit
98b2f99436
|
@ -64,6 +64,7 @@ Hardware customization:
|
||||||
* `RAM` - Amount of RAM in megabytes. Inherited from source VM by default.
|
* `RAM` - Amount of RAM in megabytes. Inherited from source VM by default.
|
||||||
* `RAM_reservation` - Amount of reserved RAM in MB. Inherited from source VM by default.
|
* `RAM_reservation` - Amount of reserved RAM in MB. Inherited from source VM by default.
|
||||||
* `RAM_reserve_all` - Reserve all available RAM (bool). `false` by default. Cannot be used together with `RAM_reservation`.
|
* `RAM_reserve_all` - Reserve all available RAM (bool). `false` by default. Cannot be used together with `RAM_reservation`.
|
||||||
|
* `disk_size` - Change the disk size (in GB). VM should have a single disk. Cannot be used together with `linked_clone`.
|
||||||
|
|
||||||
Provisioning:
|
Provisioning:
|
||||||
* `ssh_username` - [**mandatory**] username in guest OS.
|
* `ssh_username` - [**mandatory**] username in guest OS.
|
||||||
|
|
40
driver/vm.go
40
driver/vm.go
|
@ -30,6 +30,7 @@ type HardwareConfig struct {
|
||||||
RAM int64
|
RAM int64
|
||||||
RAMReservation int64
|
RAMReservation int64
|
||||||
RAMReserveAll bool
|
RAMReserveAll bool
|
||||||
|
DiskSize int64
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) NewVM(ref *types.ManagedObjectReference) *VirtualMachine {
|
func (d *Driver) NewVM(ref *types.ManagedObjectReference) *VirtualMachine {
|
||||||
|
@ -165,6 +166,27 @@ func (vm *VirtualMachine) Configure(config *HardwareConfig) error {
|
||||||
|
|
||||||
confSpec.MemoryReservationLockedToMax = &config.RAMReserveAll
|
confSpec.MemoryReservationLockedToMax = &config.RAMReserveAll
|
||||||
|
|
||||||
|
if config.DiskSize > 0 {
|
||||||
|
devices, err := vm.vm.Device(vm.driver.ctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
disk, err := findDisk(devices)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
disk.CapacityInKB = config.DiskSize * 1024 * 1024 // Gb
|
||||||
|
|
||||||
|
confSpec.DeviceChange = []types.BaseVirtualDeviceConfigSpec{
|
||||||
|
&types.VirtualDeviceConfigSpec{
|
||||||
|
Device: disk,
|
||||||
|
Operation: types.VirtualDeviceConfigSpecOperationEdit,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
task, err := vm.vm.Reconfigure(vm.driver.ctx, confSpec)
|
task, err := vm.vm.Reconfigure(vm.driver.ctx, confSpec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -173,6 +195,24 @@ func (vm *VirtualMachine) Configure(config *HardwareConfig) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func findDisk(devices object.VirtualDeviceList) (*types.VirtualDisk, error) {
|
||||||
|
var disks []*types.VirtualDisk
|
||||||
|
for _, device := range devices {
|
||||||
|
switch d := device.(type) {
|
||||||
|
case *types.VirtualDisk:
|
||||||
|
disks = append(disks, d)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch len(disks) {
|
||||||
|
case 0:
|
||||||
|
return nil, errors.New("VM has no disks")
|
||||||
|
case 1:
|
||||||
|
return disks[0], nil
|
||||||
|
}
|
||||||
|
return nil, errors.New("VM has multiple disks")
|
||||||
|
}
|
||||||
|
|
||||||
func (vm *VirtualMachine) PowerOn() error {
|
func (vm *VirtualMachine) PowerOn() error {
|
||||||
task, err := vm.vm.PowerOn(vm.driver.ctx)
|
task, err := vm.vm.PowerOn(vm.driver.ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -14,6 +14,7 @@ type HardwareConfig struct {
|
||||||
RAM int64 `mapstructure:"RAM"`
|
RAM int64 `mapstructure:"RAM"`
|
||||||
RAMReservation int64 `mapstructure:"RAM_reservation"`
|
RAMReservation int64 `mapstructure:"RAM_reservation"`
|
||||||
RAMReserveAll bool `mapstructure:"RAM_reserve_all"`
|
RAMReserveAll bool `mapstructure:"RAM_reserve_all"`
|
||||||
|
DiskSize int64 `mapstructure:"disk_size"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *HardwareConfig) Prepare() []error {
|
func (c *HardwareConfig) Prepare() []error {
|
||||||
|
@ -44,6 +45,7 @@ func (s *StepConfigureHardware) Run(state multistep.StateBag) multistep.StepActi
|
||||||
RAM: s.config.RAM,
|
RAM: s.config.RAM,
|
||||||
RAMReservation: s.config.RAMReservation,
|
RAMReservation: s.config.RAMReservation,
|
||||||
RAMReserveAll: s.config.RAMReserveAll,
|
RAMReserveAll: s.config.RAMReserveAll,
|
||||||
|
DiskSize: s.config.DiskSize,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
|
|
Loading…
Reference in New Issue