Skip to content

Commit

Permalink
Merge pull request Telmate#1063 from Tinyblargon/memory
Browse files Browse the repository at this point in the history
refactor: use new memory implementation
  • Loading branch information
Tinyblargon authored Jul 29, 2024
2 parents bd164e1 + 0356ca7 commit 90bf5ae
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.21
toolchain go1.21.0

require (
github.com/Telmate/proxmox-api-go v0.0.0-20240726134822-4c4580d03d9e
github.com/Telmate/proxmox-api-go v0.0.0-20240727211724-bdb805f525a0
github.com/google/uuid v1.6.0
github.com/hashicorp/go-cty v1.4.1-0.20200414143053-d3edf31b6320
github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migc
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/ProtonMail/go-crypto v1.1.0-alpha.2-proton h1:HKz85FwoXx86kVtTvFke7rgHvq/HoloSUvW5semjFWs=
github.com/ProtonMail/go-crypto v1.1.0-alpha.2-proton/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE=
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-20240727211724-bdb805f525a0 h1:mPpJzWJBvxyqePn7lxxb7j3F3Q+IazGUiPv0OStlgmY=
github.com/Telmate/proxmox-api-go v0.0.0-20240727211724-bdb805f525a0/go.mod h1:O6yNUi0hG9GQLMBgpikSvbnuek1OMweFtbac1sfGuUs=
github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
github.com/apparentlymart/go-textseg/v12 v12.0.0/go.mod h1:S/4uRK2UtaQttw1GenVJEynmyUenKwP++x/+DdGV/Ec=
Expand Down
29 changes: 23 additions & 6 deletions proxmox/resource_vm_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -886,9 +886,8 @@ func resourceVmQemuCreate(ctx context.Context, d *schema.ResourceData, meta inte
Boot: d.Get("boot").(string),
BootDisk: d.Get("bootdisk").(string),
Agent: mapToStruct_QemuGuestAgent(d),
Memory: d.Get("memory").(int),
Memory: mapToSDK_Memory(d),
Machine: d.Get("machine").(string),
Balloon: d.Get("balloon").(int),
QemuCores: d.Get("cores").(int),
QemuSockets: d.Get("sockets").(int),
QemuVcpus: d.Get("vcpus").(int),
Expand Down Expand Up @@ -1148,9 +1147,8 @@ func resourceVmQemuUpdate(ctx context.Context, d *schema.ResourceData, meta inte
Boot: d.Get("boot").(string),
BootDisk: d.Get("bootdisk").(string),
Agent: mapToStruct_QemuGuestAgent(d),
Memory: d.Get("memory").(int),
Memory: mapToSDK_Memory(d),
Machine: d.Get("machine").(string),
Balloon: d.Get("balloon").(int),
QemuCores: d.Get("cores").(int),
QemuSockets: d.Get("sockets").(int),
QemuVcpus: d.Get("vcpus").(int),
Expand Down Expand Up @@ -1434,9 +1432,7 @@ func resourceVmQemuRead(ctx context.Context, d *schema.ResourceData, meta interf
d.Set("tablet", config.Tablet)
d.Set("boot", config.Boot)
d.Set("bootdisk", config.BootDisk)
d.Set("memory", config.Memory)
d.Set("machine", config.Machine)
d.Set("balloon", config.Balloon)
d.Set("cores", config.QemuCores)
d.Set("sockets", config.QemuSockets)
d.Set("vcpus", config.QemuVcpus)
Expand All @@ -1455,6 +1451,7 @@ func resourceVmQemuRead(ctx context.Context, d *schema.ResourceData, meta interf
d.Set("disks", mapFromStruct_ConfigQemu(config.Disks))
mapFromStruct_QemuGuestAgent(d, config.Agent)
mapToTerraform_CloudInit(config.CloudInit, d)
mapToTerraform_Memory(config.Memory, d)

// Some dirty hacks to populate undefined keys with default values.
checkedKeys := []string{"force_create", "define_connection_info"}
Expand Down Expand Up @@ -2008,6 +2005,16 @@ func mapFromStruct_LinkedCloneId(id *uint) int {
return -1
}

func mapToTerraform_Memory(config *pxapi.QemuMemory, d *schema.ResourceData) {
// no nil check as pxapi.QemuMemory is always returned
if config.CapacityMiB != nil {
d.Set("memory", int(*config.CapacityMiB))
}
if config.MinimumCapacityMiB != nil {
d.Set("balloon", int(*config.MinimumCapacityMiB))
}
}

func mapFormStruct_QemuCdRom(config *pxapi.QemuCdRom) []interface{} {
if config == nil {
return nil
Expand Down Expand Up @@ -2462,6 +2469,16 @@ func mapToSDK_CloudInitSnippet(param string) *pxapi.CloudInitSnippet {
return nil
}

func mapToSDK_Memory(d *schema.ResourceData) *pxapi.QemuMemory {
capacity := pxapi.QemuMemoryCapacity(d.Get("memory").(int))
balloon := pxapi.QemuMemoryBalloonCapacity(d.Get("balloon").(int))
var shares pxapi.QemuMemoryShares
return &pxapi.QemuMemory{
CapacityMiB: &capacity,
MinimumCapacityMiB: &balloon,
Shares: &shares,
}
}
func mapToStruct_QemuCdRom(schema map[string]interface{}) (cdRom *pxapi.QemuCdRom) {
schemaItem, ok := schema["cdrom"].([]interface{})
if !ok {
Expand Down

0 comments on commit 90bf5ae

Please sign in to comment.