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

[Issue 74] Create var for Cloud-Init Disk Type #256

Merged
merged 6 commits into from
May 29, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .web-docs/components/builder/clone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ boot time.
- `cloud_init_storage_pool` (string) - Name of the Proxmox storage pool
to store the Cloud-Init CDROM on. If not given, the storage pool of the boot device will be used.

- `cloud_init_disk_type` (string) - The type of Cloud-Init disk. Can be `scsi`, `sata`, or `ide`
Defaults to `ide`.

- `additional_iso_files` ([]additionalISOsConfig) - Additional ISO files attached to the virtual machine.
See [Additional ISO Files](#additional-iso-files).

Expand Down
3 changes: 3 additions & 0 deletions .web-docs/components/builder/iso/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,9 @@ in the image's Cloud-Init settings for provisioning.
- `cloud_init_storage_pool` (string) - Name of the Proxmox storage pool
to store the Cloud-Init CDROM on. If not given, the storage pool of the boot device will be used.

- `cloud_init_disk_type` (string) - The type of Cloud-Init disk. Can be `scsi`, `sata`, or `ide`
Defaults to `ide`.

- `additional_iso_files` ([]additionalISOsConfig) - Additional ISO files attached to the virtual machine.
See [Additional ISO Files](#additional-iso-files).

Expand Down
2 changes: 2 additions & 0 deletions builder/proxmox/clone/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions builder/proxmox/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ type Config struct {
// Name of the Proxmox storage pool
// to store the Cloud-Init CDROM on. If not given, the storage pool of the boot device will be used.
CloudInitStoragePool string `mapstructure:"cloud_init_storage_pool"`
// The type of Cloud-Init disk. Can be `scsi`, `sata`, or `ide`
// Defaults to `ide`.
CloudInitDiskType string `mapstructure:"cloud_init_disk_type"`

// Additional ISO files attached to the virtual machine.
// See [Additional ISO Files](#additional-iso-files).
Expand Down Expand Up @@ -649,6 +652,16 @@ func (c *Config) Prepare(upper interface{}, raws ...interface{}) ([]string, []st
log.Printf("SCSI controller not set, using default 'lsi'")
c.SCSIController = "lsi"
}
if c.CloudInit {
switch c.CloudInitDiskType {
case "ide", "scsi", "sata":
case "":
log.Printf("Cloud-Init disk type not set, using default 'ide'")
c.CloudInitDiskType = "ide"
default:
errs = packersdk.MultiErrorAppend(errs, fmt.Errorf("invalid value for `cloud_init_disk_type` %q: only one of 'ide', 'scsi', 'sata' is valid", c.CloudInitDiskType))
}
}

errs = packersdk.MultiErrorAppend(errs, c.Comm.Prepare(&c.Ctx)...)
errs = packersdk.MultiErrorAppend(errs, c.BootConfig.Prepare(&c.Ctx)...)
Expand Down
2 changes: 2 additions & 0 deletions builder/proxmox/common/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 24 additions & 4 deletions builder/proxmox/common/step_finalize_template_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,30 @@ func (s *stepFinalizeTemplateConfig) Run(ctx context.Context, state multistep.St
}
}
if cloudInitStoragePool != "" {
ideControllers := []string{"ide0", "ide1", "ide2", "ide3"}
var diskControllers []string
switch c.CloudInitDiskType {
// Proxmox supports up to 6 SATA controllers (0 - 5)
case "sata":
for i := 0; i < 6; i++ {
sataController := fmt.Sprintf("sata%d", i)
diskControllers = append(diskControllers, sataController)
}
// and up to 31 SCSI controllers (0 - 30)
case "scsi":
for i := 0; i < 31; i++ {
scsiController := fmt.Sprintf("scsi%d", i)
diskControllers = append(diskControllers, scsiController)
}
// Unspecified disk type defaults to "ide"
case "ide":
diskControllers = []string{"ide0", "ide1", "ide2", "ide3"}
default:
state.Put("error", fmt.Errorf("unsupported disk type %q", c.CloudInitDiskType))
return multistep.ActionHalt
}
cloudInitAttached := false
// find a free ide controller
for _, controller := range ideControllers {
// find a free disk controller
for _, controller := range diskControllers {
if vmParams[controller] == nil {
ui.Say("Adding a cloud-init cdrom in storage pool " + cloudInitStoragePool)
changes[controller] = cloudInitStoragePool + ":cloudinit"
Expand All @@ -72,7 +92,7 @@ func (s *stepFinalizeTemplateConfig) Run(ctx context.Context, state multistep.St
}
}
if cloudInitAttached == false {
err := fmt.Errorf("Found no free ide controller for a cloud-init cdrom")
err := fmt.Errorf("Found no free controller of type %s for a cloud-init cdrom", c.CloudInitDiskType)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func TestTemplateFinalize(t *testing.T) {
TemplateName: "my-template",
TemplateDescription: "some-description",
CloudInit: true,
CloudInitDiskType: "ide",
},
initialVMConfig: map[string]interface{}{
"name": "dummy",
Expand All @@ -130,6 +131,7 @@ func TestTemplateFinalize(t *testing.T) {
TemplateName: "my-template",
TemplateDescription: "some-description",
CloudInit: true,
CloudInitDiskType: "ide",
},
initialVMConfig: map[string]interface{}{
"name": "dummy",
Expand All @@ -150,6 +152,7 @@ func TestTemplateFinalize(t *testing.T) {
TemplateName: "my-template",
TemplateDescription: "some-description",
CloudInit: true,
CloudInitDiskType: "ide",
},
getConfigErr: fmt.Errorf("some error"),
expectCallSetConfig: false,
Expand Down
2 changes: 2 additions & 0 deletions builder/proxmox/iso/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@
- `cloud_init_storage_pool` (string) - Name of the Proxmox storage pool
to store the Cloud-Init CDROM on. If not given, the storage pool of the boot device will be used.

- `cloud_init_disk_type` (string) - The type of Cloud-Init disk. Can be `scsi`, `sata`, or `ide`
Defaults to `ide`.

- `additional_iso_files` ([]additionalISOsConfig) - Additional ISO files attached to the virtual machine.
See [Additional ISO Files](#additional-iso-files).

Expand Down