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 2 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
35 changes: 34 additions & 1 deletion builder/proxmox/config.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//go:generate mapstructure-to-hcl2 -type Config,nicConfig,diskConfig,vgaConfig
//go:generate mapstructure-to-hcl2 -type Config,nicConfig,diskConfig,vgaConfig,storageConfig

package proxmox

Expand Down Expand Up @@ -64,6 +64,8 @@ type Config struct {

shouldUploadISO bool

AdditionalISOFiles []storageConfig `mapstructure:"additional_iso_files"`

ctx interpolate.Context
}

Expand All @@ -87,6 +89,12 @@ type vgaConfig struct {
Type string `mapstructure:"type"`
Memory int `mapstructure:"memory"`
}
type storageConfig struct {
Device string `mapstructure:"device"`
BusNumber int `mapstructure:"bus_number"`
Filename string `mapstructure:"filename"`
Unmount bool `mapstructure:"unmount"`
}

func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
// Agent defaults to true
Expand Down Expand Up @@ -183,6 +191,31 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("disk format must be specified for pool type %q", c.Disks[idx].StoragePoolType))
}
}
for idx := range c.AdditionalISOFiles {
if c.AdditionalISOFiles[idx].Device == "" {
log.Printf("AdditionalISOFile %d Device not set, using default 'ide'", idx)
c.AdditionalISOFiles[idx].Device = "ide"
}
if !contains([]string{"ide", "sata", "scsi"}, c.AdditionalISOFiles[idx].Device) {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("%q is not a valid AdditionalISOFile Device", c.AdditionalISOFiles[idx].Device))
}
if c.AdditionalISOFiles[idx].BusNumber == 0 {
log.Printf("AdditionalISOFile %d number not set, using default: '3'", idx)
c.AdditionalISOFiles[idx].BusNumber = 3
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I leave multiple additional isos without a bus number, they will overwrite each other this way. I can see three options:

  1. Make bus_number mandatory (and in that case, maybe merge it with device_type so you'd specify the entire device like device="ide3")
  2. Keep track of what device numbers we've used and use the next unused one. This will probably get tricky.
  3. Error out if there's more than one element without a set number.

I'd lean towards option 1 because it will more obvious, although it does sacrifice a small amount of convenience when just adding a single additional iso.

if c.AdditionalISOFiles[idx].Device == "ide" && c.AdditionalISOFiles[idx].BusNumber == 2 {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("IDE bus 2 is used by boot ISO"))
}
if c.AdditionalISOFiles[idx].Device == "ide" && c.AdditionalISOFiles[idx].BusNumber > 3 {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("IDE bus number can't be higher than 3"))
}
if c.AdditionalISOFiles[idx].Device == "sata" && c.AdditionalISOFiles[idx].BusNumber > 5 {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("SATA bus number can't be higher than 5"))
}
if c.AdditionalISOFiles[idx].Device == "scsi" && c.AdditionalISOFiles[idx].BusNumber > 30 {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("SCSI bus number can't be higher than 30"))
}
}
if c.SCSIController == "" {
log.Printf("SCSI controller not set, using default 'lsi'")
c.SCSIController = "lsi"
Expand Down
Loading