Skip to content

Commit

Permalink
Allows for the mounting of ISOs when a Proxmox VM s created. Same as …
Browse files Browse the repository at this point in the history
…in PR 9055 but working

Fixed check-lint errors

Fixed bus_number check

Fixed check-genereate error

Revert "Fixed bus_number check"

This reverts commit ac8dc15.

fmt

Naming

Fixed hcl2 autogenerated code issue

fmt

less than is not greater than
  • Loading branch information
paginabianca committed Aug 3, 2020
1 parent b3c3e3e commit 4fd76f3
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 97 deletions.
34 changes: 33 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,11 @@ 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"`
}

func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
// Agent defaults to true
Expand Down Expand Up @@ -183,6 +190,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]))
}
if c.AdditionalISOFiles[idx].BusNumber == 0 {
log.Printf("AdditionalISOFile %d number not set, using default: '3'", idx)
c.AdditionalISOFiles[idx].BusNumber = 3
}
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

0 comments on commit 4fd76f3

Please sign in to comment.