Skip to content

Commit

Permalink
api: pool assignment fix
Browse files Browse the repository at this point in the history
- updated proxmox-api-go to version containing pool assignment fix
- handled CPU, Memory, Serials changes added to API between versions
  • Loading branch information
mpywell authored and lbajolet-hashicorp committed Oct 28, 2024
1 parent ebbd33b commit 75dded5
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 51 deletions.
8 changes: 4 additions & 4 deletions .web-docs/components/builder/clone/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,23 +185,23 @@ boot time.
- `boot` (string) - Override default boot order. Format example `order=virtio0;ide2;net0`.
Prior to Proxmox 6.2-15 the format was `cdn` (c:CDROM -> d:Disk -> n:Network)

- `memory` (int) - How much memory (in megabytes) to give the virtual
- `memory` (uint32) - How much memory (in megabytes) to give the virtual
machine. If `ballooning_minimum` is also set, `memory` defines the maximum amount
of memory the VM will be able to use.
Defaults to `512`.

- `ballooning_minimum` (int) - Setting this option enables KVM memory ballooning and
- `ballooning_minimum` (uint32) - Setting this option enables KVM memory ballooning and
defines the minimum amount of memory (in megabytes) the VM will have.
Defaults to `0` (memory ballooning disabled).

- `cores` (int) - How many CPU cores to give the virtual machine. Defaults
- `cores` (uint8) - How many CPU cores to give the virtual machine. Defaults
to `1`.

- `cpu_type` (string) - The CPU type to emulate. See the Proxmox API
documentation for the complete list of accepted values. For best
performance, set this to `host`. Defaults to `kvm64`.

- `sockets` (int) - How many CPU sockets to give the virtual machine.
- `sockets` (uint8) - How many CPU sockets to give the virtual machine.
Defaults to `1`

- `numa` (bool) - If true, support for non-uniform memory access (NUMA)
Expand Down
8 changes: 4 additions & 4 deletions .web-docs/components/builder/iso/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,23 +120,23 @@ in the image's Cloud-Init settings for provisioning.
- `boot` (string) - Override default boot order. Format example `order=virtio0;ide2;net0`.
Prior to Proxmox 6.2-15 the format was `cdn` (c:CDROM -> d:Disk -> n:Network)

- `memory` (int) - How much memory (in megabytes) to give the virtual
- `memory` (uint32) - How much memory (in megabytes) to give the virtual
machine. If `ballooning_minimum` is also set, `memory` defines the maximum amount
of memory the VM will be able to use.
Defaults to `512`.

- `ballooning_minimum` (int) - Setting this option enables KVM memory ballooning and
- `ballooning_minimum` (uint32) - Setting this option enables KVM memory ballooning and
defines the minimum amount of memory (in megabytes) the VM will have.
Defaults to `0` (memory ballooning disabled).

- `cores` (int) - How many CPU cores to give the virtual machine. Defaults
- `cores` (uint8) - How many CPU cores to give the virtual machine. Defaults
to `1`.

- `cpu_type` (string) - The CPU type to emulate. See the Proxmox API
documentation for the complete list of accepted values. For best
performance, set this to `host`. Defaults to `kvm64`.

- `sockets` (int) - How many CPU sockets to give the virtual machine.
- `sockets` (uint8) - How many CPU sockets to give the virtual machine.
Defaults to `1`

- `numa` (bool) - If true, support for non-uniform memory access (NUMA)
Expand Down
8 changes: 4 additions & 4 deletions builder/proxmox/clone/config.hcl2spec.go

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

8 changes: 4 additions & 4 deletions builder/proxmox/common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,21 +104,21 @@ type Config struct {
// machine. If `ballooning_minimum` is also set, `memory` defines the maximum amount
// of memory the VM will be able to use.
// Defaults to `512`.
Memory int `mapstructure:"memory"`
Memory uint32 `mapstructure:"memory"`
// Setting this option enables KVM memory ballooning and
// defines the minimum amount of memory (in megabytes) the VM will have.
// Defaults to `0` (memory ballooning disabled).
BalloonMinimum int `mapstructure:"ballooning_minimum"`
BalloonMinimum uint32 `mapstructure:"ballooning_minimum"`
// How many CPU cores to give the virtual machine. Defaults
// to `1`.
Cores int `mapstructure:"cores"`
Cores uint8 `mapstructure:"cores"`
// The CPU type to emulate. See the Proxmox API
// documentation for the complete list of accepted values. For best
// performance, set this to `host`. Defaults to `kvm64`.
CPUType string `mapstructure:"cpu_type"`
// How many CPU sockets to give the virtual machine.
// Defaults to `1`
Sockets int `mapstructure:"sockets"`
Sockets uint8 `mapstructure:"sockets"`
// If true, support for non-uniform memory access (NUMA)
// is enabled. Defaults to `false`.
Numa bool `mapstructure:"numa"`
Expand Down
8 changes: 4 additions & 4 deletions builder/proxmox/common/config.hcl2spec.go

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

47 changes: 29 additions & 18 deletions builder/proxmox/common/step_start_vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,20 @@ func (s *stepStartVM) Run(ctx context.Context, state multistep.StateBag) multist
var description = "Packer ephemeral build VM"

config := proxmox.ConfigQemu{
Name: c.VMName,
Agent: generateAgentConfig(c.Agent),
QemuKVM: &kvm,
Tags: generateTags(c.Tags),
Boot: c.Boot, // Boot priority, example: "order=virtio0;ide2;net0", virtio0:Disk0 -> ide0:CDROM -> net0:Network
QemuCpu: c.CPUType,
Description: &description,
Memory: c.Memory,
QemuCores: c.Cores,
QemuSockets: c.Sockets,
QemuNuma: &c.Numa,
Name: c.VMName,
Agent: generateAgentConfig(c.Agent),
QemuKVM: &kvm,
Tags: generateTags(c.Tags),
Boot: c.Boot, // Boot priority, example: "order=virtio0;ide2;net0", virtio0:Disk0 -> ide0:CDROM -> net0:Network
CPU: &proxmox.QemuCPU{
Cores: (*proxmox.QemuCpuCores)(&c.Cores),
Sockets: (*proxmox.QemuCpuSockets)(&c.Sockets),
Numa: &c.Numa,
},
Description: &description,
Memory: &proxmox.QemuMemory{
CapacityMiB: (*proxmox.QemuMemoryCapacity)(&c.Memory),
},
QemuOs: c.OS,
Bios: c.BIOS,
EFIDisk: generateProxmoxEfi(c.EFIConfig),
Expand All @@ -143,7 +146,7 @@ func (s *stepStartVM) Run(ctx context.Context, state multistep.StateBag) multist
QemuNetworks: generateProxmoxNetworkAdapters(c.NICs),
Disks: disks,
QemuPCIDevices: generateProxmoxPCIDeviceMap(c.PCIDevices),
QemuSerials: generateProxmoxSerials(c.Serials),
Serials: generateProxmoxSerials(c.Serials),
Scsihw: c.SCSIController,
Onboot: &c.Onboot,
Args: c.AdditionalArgs,
Expand All @@ -154,7 +157,7 @@ func (s *stepStartVM) Run(ctx context.Context, state multistep.StateBag) multist
// and should be kept enabled by default.
// See https://github.com/hashicorp/packer-plugin-proxmox/issues/127#issuecomment-1464030102
if c.BalloonMinimum > 0 {
config.Balloon = c.BalloonMinimum
config.Memory.MinimumCapacityMiB = (*proxmox.QemuMemoryBalloonCapacity)(&c.BalloonMinimum)
}

if c.PackerForce {
Expand Down Expand Up @@ -697,11 +700,19 @@ func generateProxmoxPCIDeviceMap(devices []pciDeviceConfig) proxmox.QemuDevices
return devs
}

func generateProxmoxSerials(serials []string) proxmox.QemuDevices {
devs := make(proxmox.QemuDevices)
for idx := range serials {
devs[idx] = make(proxmox.QemuDevice)
setDeviceParamIfDefined(devs[idx], "type", serials[idx])
func generateProxmoxSerials(serials []string) proxmox.SerialInterfaces {
devs := make(proxmox.SerialInterfaces)
for idx, serial := range serials {
switch serial {
case "socket":
devs[proxmox.SerialID(idx)] = proxmox.SerialInterface{
Socket: true,
}
default:
devs[proxmox.SerialID(idx)] = proxmox.SerialInterface{
Path: proxmox.SerialPath(serial),
}
}
}
return devs
}
Expand Down
8 changes: 4 additions & 4 deletions builder/proxmox/iso/config.hcl2spec.go

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

8 changes: 4 additions & 4 deletions docs-partials/builder/proxmox/common/Config-not-required.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,23 @@
- `boot` (string) - Override default boot order. Format example `order=virtio0;ide2;net0`.
Prior to Proxmox 6.2-15 the format was `cdn` (c:CDROM -> d:Disk -> n:Network)

- `memory` (int) - How much memory (in megabytes) to give the virtual
- `memory` (uint32) - How much memory (in megabytes) to give the virtual
machine. If `ballooning_minimum` is also set, `memory` defines the maximum amount
of memory the VM will be able to use.
Defaults to `512`.

- `ballooning_minimum` (int) - Setting this option enables KVM memory ballooning and
- `ballooning_minimum` (uint32) - Setting this option enables KVM memory ballooning and
defines the minimum amount of memory (in megabytes) the VM will have.
Defaults to `0` (memory ballooning disabled).

- `cores` (int) - How many CPU cores to give the virtual machine. Defaults
- `cores` (uint8) - How many CPU cores to give the virtual machine. Defaults
to `1`.

- `cpu_type` (string) - The CPU type to emulate. See the Proxmox API
documentation for the complete list of accepted values. For best
performance, set this to `host`. Defaults to `kvm64`.

- `sockets` (int) - How many CPU sockets to give the virtual machine.
- `sockets` (uint8) - How many CPU sockets to give the virtual machine.
Defaults to `1`

- `numa` (bool) - If true, support for non-uniform memory access (NUMA)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/hashicorp/packer-plugin-proxmox
go 1.21.0

require (
github.com/Telmate/proxmox-api-go v0.0.0-20240726134822-4c4580d03d9e
github.com/Telmate/proxmox-api-go v0.0.0-20241022204517-b149708f750b
github.com/hashicorp/go-getter/v2 v2.2.2
github.com/hashicorp/hcl/v2 v2.19.1
github.com/hashicorp/packer-plugin-sdk v0.5.4
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@ github.com/Telmate/proxmox-api-go v0.0.0-20240409105641-32c480fe008e h1:NdpVflh7
github.com/Telmate/proxmox-api-go v0.0.0-20240409105641-32c480fe008e/go.mod h1:bscBzOUx0tJAdVGmQvcnoWPg5eI2eJ6anJKV1ueZ1oU=
github.com/Telmate/proxmox-api-go v0.0.0-20240525163725-6676d8933df0 h1:VK35Q0s1IayA2Nwm0uREu+LVs0WWPq9Zsn3Oic1q5eg=
github.com/Telmate/proxmox-api-go v0.0.0-20240525163725-6676d8933df0/go.mod h1:bscBzOUx0tJAdVGmQvcnoWPg5eI2eJ6anJKV1ueZ1oU=
github.com/Telmate/proxmox-api-go v0.0.0-20240615154505-578dffaf4d38 h1:ViSuq1kQmOHycY8pvwDo319UwuuEnqhRXp4b0EiMJW4=
github.com/Telmate/proxmox-api-go v0.0.0-20240615154505-578dffaf4d38/go.mod h1:bscBzOUx0tJAdVGmQvcnoWPg5eI2eJ6anJKV1ueZ1oU=
github.com/Telmate/proxmox-api-go v0.0.0-20240726134822-4c4580d03d9e h1:e2StaFGv+J2yhCP29DBQmchLQHNqbCnLomZGx66p6/Q=
github.com/Telmate/proxmox-api-go v0.0.0-20240726134822-4c4580d03d9e/go.mod h1:O6yNUi0hG9GQLMBgpikSvbnuek1OMweFtbac1sfGuUs=
github.com/Telmate/proxmox-api-go v0.0.0-20241022204517-b149708f750b h1:vgK9CbUZpd37RYab6lCEQTyP0fw/Ygq5NOWctBI5rpA=
github.com/Telmate/proxmox-api-go v0.0.0-20241022204517-b149708f750b/go.mod h1:Gu6n6vEn1hlyFUkjrvU+X1fdgaSXLoM9HKYYJqy1fsY=
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand Down

0 comments on commit 75dded5

Please sign in to comment.