add ability to define multiple disk controllers (#9519)
This commit is contained in:
parent
9c1409dbba
commit
ae5156a70d
@ -63,7 +63,7 @@ type NIC struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type CreateConfig struct {
|
type CreateConfig struct {
|
||||||
DiskControllerType string // example: "scsi", "pvscsi"
|
DiskControllerType []string // example: "scsi", "pvscsi", "lsilogic"
|
||||||
|
|
||||||
Annotation string
|
Annotation string
|
||||||
Name string
|
Name string
|
||||||
@ -84,6 +84,7 @@ type Disk struct {
|
|||||||
DiskSize int64
|
DiskSize int64
|
||||||
DiskEagerlyScrub bool
|
DiskEagerlyScrub bool
|
||||||
DiskThinProvisioned bool
|
DiskThinProvisioned bool
|
||||||
|
ControllerIndex int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *Driver) NewVM(ref *types.ManagedObjectReference) *VirtualMachine {
|
func (d *Driver) NewVM(ref *types.ManagedObjectReference) *VirtualMachine {
|
||||||
@ -741,14 +742,22 @@ func addDisk(_ *Driver, devices object.VirtualDeviceList, config *CreateConfig)
|
|||||||
return nil, errors.New("no storage devices have been defined")
|
return nil, errors.New("no storage devices have been defined")
|
||||||
}
|
}
|
||||||
|
|
||||||
device, err := devices.CreateSCSIController(config.DiskControllerType)
|
if len(config.DiskControllerType) == 0 {
|
||||||
if err != nil {
|
return nil, errors.New("no controllers have been defined")
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
devices = append(devices, device)
|
|
||||||
controller, err := devices.FindDiskController(devices.Name(device))
|
var controllers []types.BaseVirtualController
|
||||||
if err != nil {
|
for _, controllerType := range config.DiskControllerType {
|
||||||
return nil, err
|
device, err := devices.CreateSCSIController(controllerType)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
devices = append(devices, device)
|
||||||
|
controller, err := devices.FindDiskController(devices.Name(device))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
controllers = append(controllers, controller)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, dc := range config.Storage {
|
for _, dc := range config.Storage {
|
||||||
@ -764,7 +773,7 @@ func addDisk(_ *Driver, devices object.VirtualDeviceList, config *CreateConfig)
|
|||||||
CapacityInKB: dc.DiskSize * 1024,
|
CapacityInKB: dc.DiskSize * 1024,
|
||||||
}
|
}
|
||||||
|
|
||||||
devices.AssignController(disk, controller)
|
devices.AssignController(disk, controllers[dc.ControllerIndex])
|
||||||
devices = append(devices, disk)
|
devices = append(devices, disk)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ type FlatConfig struct {
|
|||||||
Version *uint `mapstructure:"vm_version" cty:"vm_version" hcl:"vm_version"`
|
Version *uint `mapstructure:"vm_version" cty:"vm_version" hcl:"vm_version"`
|
||||||
GuestOSType *string `mapstructure:"guest_os_type" cty:"guest_os_type" hcl:"guest_os_type"`
|
GuestOSType *string `mapstructure:"guest_os_type" cty:"guest_os_type" hcl:"guest_os_type"`
|
||||||
Firmware *string `mapstructure:"firmware" cty:"firmware" hcl:"firmware"`
|
Firmware *string `mapstructure:"firmware" cty:"firmware" hcl:"firmware"`
|
||||||
DiskControllerType *string `mapstructure:"disk_controller_type" cty:"disk_controller_type" hcl:"disk_controller_type"`
|
DiskControllerType []string `mapstructure:"disk_controller_type" cty:"disk_controller_type" hcl:"disk_controller_type"`
|
||||||
Storage []FlatDiskConfig `mapstructure:"storage" cty:"storage" hcl:"storage"`
|
Storage []FlatDiskConfig `mapstructure:"storage" cty:"storage" hcl:"storage"`
|
||||||
NICs []FlatNIC `mapstructure:"network_adapters" cty:"network_adapters" hcl:"network_adapters"`
|
NICs []FlatNIC `mapstructure:"network_adapters" cty:"network_adapters" hcl:"network_adapters"`
|
||||||
USBController *bool `mapstructure:"usb_controller" cty:"usb_controller" hcl:"usb_controller"`
|
USBController *bool `mapstructure:"usb_controller" cty:"usb_controller" hcl:"usb_controller"`
|
||||||
@ -160,7 +160,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec {
|
|||||||
"vm_version": &hcldec.AttrSpec{Name: "vm_version", Type: cty.Number, Required: false},
|
"vm_version": &hcldec.AttrSpec{Name: "vm_version", Type: cty.Number, Required: false},
|
||||||
"guest_os_type": &hcldec.AttrSpec{Name: "guest_os_type", Type: cty.String, Required: false},
|
"guest_os_type": &hcldec.AttrSpec{Name: "guest_os_type", Type: cty.String, Required: false},
|
||||||
"firmware": &hcldec.AttrSpec{Name: "firmware", Type: cty.String, Required: false},
|
"firmware": &hcldec.AttrSpec{Name: "firmware", Type: cty.String, Required: false},
|
||||||
"disk_controller_type": &hcldec.AttrSpec{Name: "disk_controller_type", Type: cty.String, Required: false},
|
"disk_controller_type": &hcldec.AttrSpec{Name: "disk_controller_type", Type: cty.List(cty.String), Required: false},
|
||||||
"storage": &hcldec.BlockListSpec{TypeName: "storage", Nested: hcldec.ObjectSpec((*FlatDiskConfig)(nil).HCL2Spec())},
|
"storage": &hcldec.BlockListSpec{TypeName: "storage", Nested: hcldec.ObjectSpec((*FlatDiskConfig)(nil).HCL2Spec())},
|
||||||
"network_adapters": &hcldec.BlockListSpec{TypeName: "network_adapters", Nested: hcldec.ObjectSpec((*FlatNIC)(nil).HCL2Spec())},
|
"network_adapters": &hcldec.BlockListSpec{TypeName: "network_adapters", Nested: hcldec.ObjectSpec((*FlatNIC)(nil).HCL2Spec())},
|
||||||
"usb_controller": &hcldec.AttrSpec{Name: "usb_controller", Type: cty.Bool, Required: false},
|
"usb_controller": &hcldec.AttrSpec{Name: "usb_controller", Type: cty.Bool, Required: false},
|
||||||
|
@ -49,7 +49,7 @@ type NIC struct {
|
|||||||
// ```json
|
// ```json
|
||||||
// "storage": [
|
// "storage": [
|
||||||
// {
|
// {
|
||||||
// "disk_size": 15000,
|
// "disk_size": 15000
|
||||||
// },
|
// },
|
||||||
// {
|
// {
|
||||||
// "disk_size": 20000,
|
// "disk_size": 20000,
|
||||||
@ -57,6 +57,29 @@ type NIC struct {
|
|||||||
// }
|
// }
|
||||||
// ],
|
// ],
|
||||||
// ```
|
// ```
|
||||||
|
//
|
||||||
|
// Example that creates 2 pvscsi controllers and adds 2 disks to each one:
|
||||||
|
// ```json
|
||||||
|
// "disk_controller_type": ["pvscsi", "pvscsi"],
|
||||||
|
// "storage": [
|
||||||
|
// {
|
||||||
|
// "disk_size": 15000,
|
||||||
|
// "disk_controller_index": 0
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// "disk_size": 15000,
|
||||||
|
// "disk_controller_index": 0
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// "disk_size": 15000,
|
||||||
|
// "disk_controller_index": 1
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// "disk_size": 15000,
|
||||||
|
// "disk_controller_index": 1
|
||||||
|
// }
|
||||||
|
// ],
|
||||||
|
// ```
|
||||||
type DiskConfig struct {
|
type DiskConfig struct {
|
||||||
// The size of the disk in MB.
|
// The size of the disk in MB.
|
||||||
DiskSize int64 `mapstructure:"disk_size" required:"true"`
|
DiskSize int64 `mapstructure:"disk_size" required:"true"`
|
||||||
@ -64,6 +87,8 @@ type DiskConfig struct {
|
|||||||
DiskThinProvisioned bool `mapstructure:"disk_thin_provisioned"`
|
DiskThinProvisioned bool `mapstructure:"disk_thin_provisioned"`
|
||||||
// Enable VMDK eager scrubbing for VM. Defaults to `false`.
|
// Enable VMDK eager scrubbing for VM. Defaults to `false`.
|
||||||
DiskEagerlyScrub bool `mapstructure:"disk_eagerly_scrub"`
|
DiskEagerlyScrub bool `mapstructure:"disk_eagerly_scrub"`
|
||||||
|
// The assigned disk controller. Defaults to the first one (0)
|
||||||
|
DiskControllerIndex int `mapstructure:"disk_controller_index"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CreateConfig struct {
|
type CreateConfig struct {
|
||||||
@ -78,8 +103,8 @@ type CreateConfig struct {
|
|||||||
GuestOSType string `mapstructure:"guest_os_type"`
|
GuestOSType string `mapstructure:"guest_os_type"`
|
||||||
// Set the Firmware at machine creation. Supported values: `bios`, `efi` or `efi-secure`. Defaults to `bios`.
|
// Set the Firmware at machine creation. Supported values: `bios`, `efi` or `efi-secure`. Defaults to `bios`.
|
||||||
Firmware string `mapstructure:"firmware"`
|
Firmware string `mapstructure:"firmware"`
|
||||||
// Set VM disk controller type. Example `pvscsi`.
|
// Set VM disk controller type. Example `lsilogic`, pvscsi`, or `scsi`. Use a list to define additional controllers. Defaults to `lsilogic`
|
||||||
DiskControllerType string `mapstructure:"disk_controller_type"`
|
DiskControllerType []string `mapstructure:"disk_controller_type"`
|
||||||
// A collection of one or more disks to be provisioned along with the VM.
|
// A collection of one or more disks to be provisioned along with the VM.
|
||||||
Storage []DiskConfig `mapstructure:"storage"`
|
Storage []DiskConfig `mapstructure:"storage"`
|
||||||
// Network adapters
|
// Network adapters
|
||||||
@ -93,11 +118,19 @@ type CreateConfig struct {
|
|||||||
func (c *CreateConfig) Prepare() []error {
|
func (c *CreateConfig) Prepare() []error {
|
||||||
var errs []error
|
var errs []error
|
||||||
|
|
||||||
|
// there should be at least one
|
||||||
|
if len(c.DiskControllerType) == 0 {
|
||||||
|
c.DiskControllerType = append(c.DiskControllerType, "")
|
||||||
|
}
|
||||||
|
|
||||||
if len(c.Storage) > 0 {
|
if len(c.Storage) > 0 {
|
||||||
for i, storage := range c.Storage {
|
for i, storage := range c.Storage {
|
||||||
if storage.DiskSize == 0 {
|
if storage.DiskSize == 0 {
|
||||||
errs = append(errs, fmt.Errorf("storage[%d].'disk_size' is required", i))
|
errs = append(errs, fmt.Errorf("storage[%d].'disk_size' is required", i))
|
||||||
}
|
}
|
||||||
|
if storage.DiskControllerIndex >= len(c.DiskControllerType) {
|
||||||
|
errs = append(errs, fmt.Errorf("storage[%d].'disk_controller_index' references an unknown disk controller", i))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -149,6 +182,7 @@ func (s *StepCreateVM) Run(_ context.Context, state multistep.StateBag) multiste
|
|||||||
DiskSize: disk.DiskSize,
|
DiskSize: disk.DiskSize,
|
||||||
DiskEagerlyScrub: disk.DiskEagerlyScrub,
|
DiskEagerlyScrub: disk.DiskEagerlyScrub,
|
||||||
DiskThinProvisioned: disk.DiskThinProvisioned,
|
DiskThinProvisioned: disk.DiskThinProvisioned,
|
||||||
|
ControllerIndex: disk.DiskControllerIndex,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ type FlatCreateConfig struct {
|
|||||||
Version *uint `mapstructure:"vm_version" cty:"vm_version" hcl:"vm_version"`
|
Version *uint `mapstructure:"vm_version" cty:"vm_version" hcl:"vm_version"`
|
||||||
GuestOSType *string `mapstructure:"guest_os_type" cty:"guest_os_type" hcl:"guest_os_type"`
|
GuestOSType *string `mapstructure:"guest_os_type" cty:"guest_os_type" hcl:"guest_os_type"`
|
||||||
Firmware *string `mapstructure:"firmware" cty:"firmware" hcl:"firmware"`
|
Firmware *string `mapstructure:"firmware" cty:"firmware" hcl:"firmware"`
|
||||||
DiskControllerType *string `mapstructure:"disk_controller_type" cty:"disk_controller_type" hcl:"disk_controller_type"`
|
DiskControllerType []string `mapstructure:"disk_controller_type" cty:"disk_controller_type" hcl:"disk_controller_type"`
|
||||||
Storage []FlatDiskConfig `mapstructure:"storage" cty:"storage" hcl:"storage"`
|
Storage []FlatDiskConfig `mapstructure:"storage" cty:"storage" hcl:"storage"`
|
||||||
NICs []FlatNIC `mapstructure:"network_adapters" cty:"network_adapters" hcl:"network_adapters"`
|
NICs []FlatNIC `mapstructure:"network_adapters" cty:"network_adapters" hcl:"network_adapters"`
|
||||||
USBController *bool `mapstructure:"usb_controller" cty:"usb_controller" hcl:"usb_controller"`
|
USBController *bool `mapstructure:"usb_controller" cty:"usb_controller" hcl:"usb_controller"`
|
||||||
@ -34,7 +34,7 @@ func (*FlatCreateConfig) HCL2Spec() map[string]hcldec.Spec {
|
|||||||
"vm_version": &hcldec.AttrSpec{Name: "vm_version", Type: cty.Number, Required: false},
|
"vm_version": &hcldec.AttrSpec{Name: "vm_version", Type: cty.Number, Required: false},
|
||||||
"guest_os_type": &hcldec.AttrSpec{Name: "guest_os_type", Type: cty.String, Required: false},
|
"guest_os_type": &hcldec.AttrSpec{Name: "guest_os_type", Type: cty.String, Required: false},
|
||||||
"firmware": &hcldec.AttrSpec{Name: "firmware", Type: cty.String, Required: false},
|
"firmware": &hcldec.AttrSpec{Name: "firmware", Type: cty.String, Required: false},
|
||||||
"disk_controller_type": &hcldec.AttrSpec{Name: "disk_controller_type", Type: cty.String, Required: false},
|
"disk_controller_type": &hcldec.AttrSpec{Name: "disk_controller_type", Type: cty.List(cty.String), Required: false},
|
||||||
"storage": &hcldec.BlockListSpec{TypeName: "storage", Nested: hcldec.ObjectSpec((*FlatDiskConfig)(nil).HCL2Spec())},
|
"storage": &hcldec.BlockListSpec{TypeName: "storage", Nested: hcldec.ObjectSpec((*FlatDiskConfig)(nil).HCL2Spec())},
|
||||||
"network_adapters": &hcldec.BlockListSpec{TypeName: "network_adapters", Nested: hcldec.ObjectSpec((*FlatNIC)(nil).HCL2Spec())},
|
"network_adapters": &hcldec.BlockListSpec{TypeName: "network_adapters", Nested: hcldec.ObjectSpec((*FlatNIC)(nil).HCL2Spec())},
|
||||||
"usb_controller": &hcldec.AttrSpec{Name: "usb_controller", Type: cty.Bool, Required: false},
|
"usb_controller": &hcldec.AttrSpec{Name: "usb_controller", Type: cty.Bool, Required: false},
|
||||||
@ -49,6 +49,7 @@ type FlatDiskConfig struct {
|
|||||||
DiskSize *int64 `mapstructure:"disk_size" required:"true" cty:"disk_size" hcl:"disk_size"`
|
DiskSize *int64 `mapstructure:"disk_size" required:"true" cty:"disk_size" hcl:"disk_size"`
|
||||||
DiskThinProvisioned *bool `mapstructure:"disk_thin_provisioned" cty:"disk_thin_provisioned" hcl:"disk_thin_provisioned"`
|
DiskThinProvisioned *bool `mapstructure:"disk_thin_provisioned" cty:"disk_thin_provisioned" hcl:"disk_thin_provisioned"`
|
||||||
DiskEagerlyScrub *bool `mapstructure:"disk_eagerly_scrub" cty:"disk_eagerly_scrub" hcl:"disk_eagerly_scrub"`
|
DiskEagerlyScrub *bool `mapstructure:"disk_eagerly_scrub" cty:"disk_eagerly_scrub" hcl:"disk_eagerly_scrub"`
|
||||||
|
DiskControllerIndex *int `mapstructure:"disk_controller_index" cty:"disk_controller_index" hcl:"disk_controller_index"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// FlatMapstructure returns a new FlatDiskConfig.
|
// FlatMapstructure returns a new FlatDiskConfig.
|
||||||
@ -66,6 +67,7 @@ func (*FlatDiskConfig) HCL2Spec() map[string]hcldec.Spec {
|
|||||||
"disk_size": &hcldec.AttrSpec{Name: "disk_size", Type: cty.Number, Required: false},
|
"disk_size": &hcldec.AttrSpec{Name: "disk_size", Type: cty.Number, Required: false},
|
||||||
"disk_thin_provisioned": &hcldec.AttrSpec{Name: "disk_thin_provisioned", Type: cty.Bool, Required: false},
|
"disk_thin_provisioned": &hcldec.AttrSpec{Name: "disk_thin_provisioned", Type: cty.Bool, Required: false},
|
||||||
"disk_eagerly_scrub": &hcldec.AttrSpec{Name: "disk_eagerly_scrub", Type: cty.Bool, Required: false},
|
"disk_eagerly_scrub": &hcldec.AttrSpec{Name: "disk_eagerly_scrub", Type: cty.Bool, Required: false},
|
||||||
|
"disk_controller_index": &hcldec.AttrSpec{Name: "disk_controller_index", Type: cty.Number, Required: false},
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
- `firmware` (string) - Set the Firmware at machine creation. Supported values: `bios`, `efi` or `efi-secure`. Defaults to `bios`.
|
- `firmware` (string) - Set the Firmware at machine creation. Supported values: `bios`, `efi` or `efi-secure`. Defaults to `bios`.
|
||||||
|
|
||||||
- `disk_controller_type` (string) - Set VM disk controller type. Example `pvscsi`.
|
- `disk_controller_type` ([]string) - Set VM disk controller type. Example `lsilogic`, pvscsi`, or `scsi`. Use a list to define additional controllers. Defaults to `lsilogic`
|
||||||
|
|
||||||
- `storage` ([]DiskConfig) - A collection of one or more disks to be provisioned along with the VM.
|
- `storage` ([]DiskConfig) - A collection of one or more disks to be provisioned along with the VM.
|
||||||
|
|
||||||
|
@ -4,3 +4,5 @@
|
|||||||
|
|
||||||
- `disk_eagerly_scrub` (bool) - Enable VMDK eager scrubbing for VM. Defaults to `false`.
|
- `disk_eagerly_scrub` (bool) - Enable VMDK eager scrubbing for VM. Defaults to `false`.
|
||||||
|
|
||||||
|
- `disk_controller_index` (int) - The assigned disk controller. Defaults to the first one (0)
|
||||||
|
|
@ -6,7 +6,7 @@ Example that will create a 15GB and a 20GB disk on the VM. The second disk will
|
|||||||
```json
|
```json
|
||||||
"storage": [
|
"storage": [
|
||||||
{
|
{
|
||||||
"disk_size": 15000,
|
"disk_size": 15000
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"disk_size": 20000,
|
"disk_size": 20000,
|
||||||
@ -14,3 +14,26 @@ Example that will create a 15GB and a 20GB disk on the VM. The second disk will
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Example that creates 2 pvscsi controllers and adds 2 disks to each one:
|
||||||
|
```json
|
||||||
|
"disk_controller_type": ["pvscsi", "pvscsi"],
|
||||||
|
"storage": [
|
||||||
|
{
|
||||||
|
"disk_size": 15000,
|
||||||
|
"disk_controller_index": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"disk_size": 15000,
|
||||||
|
"disk_controller_index": 0
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"disk_size": 15000,
|
||||||
|
"disk_controller_index": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"disk_size": 15000,
|
||||||
|
"disk_controller_index": 1
|
||||||
|
}
|
||||||
|
],
|
||||||
|
```
|
||||||
|
Loading…
x
Reference in New Issue
Block a user