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

Allows for the mounting of ISOs when a Proxmox VM s created. Same as … #9653

Merged
merged 7 commits into from
Aug 31, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
28 changes: 14 additions & 14 deletions builder/proxmox/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ type vgaConfig struct {
}
type storageConfig struct {
common.ISOConfig `mapstructure:",squash"`
DeviceType string `mapstructure:"device_type"`
Device string `mapstructure:"device"`
ISOFile string `mapstructure:"iso_file"`
ISOStoragePool string `mapstructure:"iso_storage_pool"`
Unmount bool `mapstructure:"unmount"`
Expand Down Expand Up @@ -209,14 +209,14 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
warnings = append(warnings, isoWarnings...)
c.AdditionalISOFiles[idx].shouldUploadISO = true
}
if c.AdditionalISOFiles[idx].DeviceType == "" {
log.Printf("AdditionalISOFile %d DeviceType not set, using default 'ide3'", idx)
c.AdditionalISOFiles[idx].DeviceType = "ide3"
if c.AdditionalISOFiles[idx].Device == "" {
log.Printf("AdditionalISOFile %d Devicenot set, using default 'ide3'", idx)
azr marked this conversation as resolved.
Show resolved Hide resolved
c.AdditionalISOFiles[idx].Device = "ide3"
}
if strings.HasPrefix(c.AdditionalISOFiles[idx].DeviceType, "ide") {
busnumber, err := strconv.Atoi(c.AdditionalISOFiles[idx].DeviceType[3:])
if strings.HasPrefix(c.AdditionalISOFiles[idx].Device, "ide") {
busnumber, err := strconv.Atoi(c.AdditionalISOFiles[idx].Device[3:])
if err != nil {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("%s is not a valid bus index", c.AdditionalISOFiles[idx].DeviceType[3:]))
errs = packer.MultiErrorAppend(errs, fmt.Errorf("%s is not a valid bus index", c.AdditionalISOFiles[idx].Device[3:]))
}
if busnumber == 2 {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("IDE bus 2 is used by boot ISO"))
Expand All @@ -225,26 +225,26 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("IDE bus index can't be higher than 3"))
}
}
if strings.HasPrefix(c.AdditionalISOFiles[idx].DeviceType, "sata") {
busnumber, err := strconv.Atoi(c.AdditionalISOFiles[idx].DeviceType[4:])
if strings.HasPrefix(c.AdditionalISOFiles[idx].Device, "sata") {
busnumber, err := strconv.Atoi(c.AdditionalISOFiles[idx].Device[4:])
if err != nil {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("%s is not a valid bus index", c.AdditionalISOFiles[idx].DeviceType[4:]))
errs = packer.MultiErrorAppend(errs, fmt.Errorf("%s is not a valid bus index", c.AdditionalISOFiles[idx].Device[4:]))
}
if busnumber > 5 {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("SATA bus index can't be higher than 5"))
}
}
if strings.HasPrefix(c.AdditionalISOFiles[idx].DeviceType, "scsi") {
busnumber, err := strconv.Atoi(c.AdditionalISOFiles[idx].DeviceType[4:])
if strings.HasPrefix(c.AdditionalISOFiles[idx].Device, "scsi") {
busnumber, err := strconv.Atoi(c.AdditionalISOFiles[idx].Device[4:])
if err != nil {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("%s is not a valid bus index", c.AdditionalISOFiles[idx].DeviceType[4:]))
errs = packer.MultiErrorAppend(errs, fmt.Errorf("%s is not a valid bus index", c.AdditionalISOFiles[idx].Device[4:]))
}
if busnumber > 30 {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("SCSI bus index can't be higher than 30"))
}
}
if (c.AdditionalISOFiles[idx].ISOFile == "" && len(c.AdditionalISOFiles[idx].ISOConfig.ISOUrls) == 0) || (c.AdditionalISOFiles[idx].ISOFile != "" && len(c.AdditionalISOFiles[idx].ISOConfig.ISOUrls) != 0) {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("either iso_file or iso_url, but not both, must be specified for AdditionalISO file %s", c.AdditionalISOFiles[idx].DeviceType))
errs = packer.MultiErrorAppend(errs, fmt.Errorf("either iso_file or iso_url, but not both, must be specified for AdditionalISO file %s", c.AdditionalISOFiles[idx].Device))
}
if len(c.ISOConfig.ISOUrls) != 0 && c.ISOStoragePool == "" {
errs = packer.MultiErrorAppend(errs, errors.New("when specifying iso_url, iso_storage_pool must also be specified"))
Expand Down
4 changes: 2 additions & 2 deletions builder/proxmox/config.hcl2spec.go

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

2 changes: 1 addition & 1 deletion builder/proxmox/step_finalize_template_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (s *stepFinalizeTemplateConfig) Run(ctx context.Context, state multistep.St
return multistep.ActionHalt
}
for idx := range c.AdditionalISOFiles {
cdrom := c.AdditionalISOFiles[idx].DeviceType
cdrom := c.AdditionalISOFiles[idx].Device
if c.AdditionalISOFiles[idx].Unmount {
if vmParams[cdrom] == nil || !strings.Contains(vmParams[cdrom].(string), "media=cdrom") {
err := fmt.Errorf("Cannot eject ISO from cdrom drive, %s is not present or not a cdrom media", cdrom)
Expand Down
2 changes: 1 addition & 1 deletion builder/proxmox/step_start_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (s *stepStartVM) Run(ctx context.Context, state multistep.StateBag) multist

for idx := range c.AdditionalISOFiles {
params := map[string]interface{}{
c.AdditionalISOFiles[idx].DeviceType: c.AdditionalISOFiles[idx].ISOFile + ",media=cdrom",
c.AdditionalISOFiles[idx].Device: c.AdditionalISOFiles[idx].ISOFile + ",media=cdrom",
}
_, err = client.SetVmConfig(vmRef, params)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion builder/proxmox/step_upload_additional_isos.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (s *stepUploadAdditionalISOs) Run(ctx context.Context, state multistep.Stat
for idx := range c.AdditionalISOFiles {
if !c.AdditionalISOFiles[idx].shouldUploadISO {
state.Put("additional_iso_files", c.AdditionalISOFiles)
return multistep.ActionContinue
continue
}

p := state.Get(c.AdditionalISOFiles[idx].downloadPathKey).(string)
Expand Down
6 changes: 3 additions & 3 deletions website/pages/docs/builders/proxmox.mdx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
---

description: |
The proxmox Packer builder is able to create new images for use with
Proxmox VE. The builder takes an ISO source, runs any provisioning
Expand Down Expand Up @@ -219,14 +219,14 @@ builder.
```json
[
{
"device_type": "scsi5",
"device": "scsi5",
"iso_file": "local:iso/virtio-win-0.1.185.iso",
"unmount": true,
"iso_checksum": "af2b3cc9fa7905dea5e58d31508d75bba717c2b0d5553962658a47aebc9cc386"
}
]
```
- `device_type` (string) - Bus type and bus index that the ISO will be mounted on. Can be `ideX`,
- `device` (string) - Bus type and bus index that the ISO will be mounted on. Can be `ideX`,
`sataX` or `scsiX`.
For `ide` the bus index ranges from 0 to 3, for `sata` form 0 to 5 and for
`scsi` from 0 to 30.
Expand Down