Merge pull request #8084 from carlpett/check-disk-format-set

builder/proxmox: Check that disk format is set when pool type requires it
This commit is contained in:
Adrien Delorme 2019-09-09 10:33:50 +02:00 committed by GitHub
commit dad3ae1535
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 15 additions and 0 deletions

View File

@ -151,6 +151,12 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
log.Printf("Disk %d cache mode not set, using default 'none'", idx)
c.Disks[idx].CacheMode = "none"
}
// For any storage pool types which aren't in rxStorageTypes in proxmox-api/proxmox/config_qemu.go:651
// (currently zfspool and lvm), the format parameter is mandatory. Make sure this is still up to date
// when updating the vendored code!
if !contains([]string{"zfspool", "lvm"}, c.Disks[idx].StoragePoolType) && c.Disks[idx].DiskFormat == "" {
errs = packer.MultiErrorAppend(errs, errors.New(fmt.Sprintf("disk format must be specified for pool type %q", c.Disks[idx].StoragePoolType)))
}
}
errs = packer.MultiErrorAppend(errs, c.Comm.Prepare(&c.ctx)...)
@ -197,3 +203,12 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
packer.LogSecretFilter.Set(c.Password)
return c, nil, nil
}
func contains(haystack []string, needle string) bool {
for _, candidate := range haystack {
if candidate == needle {
return true
}
}
return false
}