From c151ae3db73cc552b0c6328b385cac18e576c9bb Mon Sep 17 00:00:00 2001 From: vishesh92 Date: Mon, 1 Sep 2025 13:12:11 +0530 Subject: [PATCH 1/2] Fix format of details map for update VM --- cloudstack/VirtualMachineService.go | 4 ++-- generate/generate.go | 28 ++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/cloudstack/VirtualMachineService.go b/cloudstack/VirtualMachineService.go index 9bb79a8..8a9166c 100644 --- a/cloudstack/VirtualMachineService.go +++ b/cloudstack/VirtualMachineService.go @@ -9858,8 +9858,8 @@ func (p *UpdateVirtualMachineParams) toURLValues() url.Values { } if v, found := p.p["details"]; found { m := v.(map[string]string) - for i, k := range getSortedKeysFromMap(m) { - u.Set(fmt.Sprintf("details[%d].%s", i, k), m[k]) + for _, k := range getSortedKeysFromMap(m) { + u.Set(fmt.Sprintf("details[0].%s", k), m[k]) } } if v, found := p.p["dhcpoptionsnetworklist"]; found { diff --git a/generate/generate.go b/generate/generate.go index bd330a7..20ea4f5 100644 --- a/generate/generate.go +++ b/generate/generate.go @@ -54,10 +54,23 @@ var detailsRequireKeyValue = map[string]bool{ // detailsRequireZeroIndex is a prefilled map with a list of details // that need to be encoded using zero indexing var detailsRequireZeroIndex = map[string]bool{ - "registerTemplate": true, - "updateTemplate": true, - "createAccount": true, - "updateAccount": true, + "registerTemplate": true, + "updateTemplate": true, + "createAccount": true, + "updateAccount": true, + "updateVirtualMachine": true, +} + +// parametersRequireIndexing contains map parameters that always need +// index variables (i) even when the command uses zero indexing +var parametersRequireIndexing = map[string]bool{ + "userdatadetails": true, + "serviceproviderlist": true, + "usersecuritygrouplist": true, + "tags": true, + "nicnetworklist": true, + "nicipaddresslist": true, + "datadiskofferinglist": true, } // requiresPost is a prefilled set of API names that require POST @@ -1363,7 +1376,10 @@ func (s *service) generateConvertCode(cmd, name, typ string) { case "map[string]string": pn("m := v.(map[string]string)") zeroIndex := detailsRequireZeroIndex[cmd] - if zeroIndex { + needsIndex := parametersRequireIndexing[name] + + // Use index variable if parameter requires it or command doesn't use zero indexing + if zeroIndex && !needsIndex { pn("for _, k := range getSortedKeysFromMap(m) {") } else { pn("for i, k := range getSortedKeysFromMap(m) {") @@ -1408,7 +1424,7 @@ func (s *service) generateConvertCode(cmd, name, typ string) { pn(" u.Set(fmt.Sprintf(\"%s[%%d].name\", i), k)", name) pn(" u.Set(fmt.Sprintf(\"%s[%%d].value\", i), m[k])", name) default: - if zeroIndex && !detailsRequireKeyValue[cmd] { + if zeroIndex && !detailsRequireKeyValue[cmd] && !needsIndex { pn(" u.Set(fmt.Sprintf(\"%s[0].%%s\", k), m[k])", name) } else { pn(" u.Set(fmt.Sprintf(\"%s[%%d].key\", i), k)", name) From e17d224c55e55a4e5ad9283abc0e5907a721a9c3 Mon Sep 17 00:00:00 2001 From: vishesh92 Date: Tue, 2 Sep 2025 11:14:18 +0530 Subject: [PATCH 2/2] fixup --- generate/generate.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/generate/generate.go b/generate/generate.go index 20ea4f5..975bcf2 100644 --- a/generate/generate.go +++ b/generate/generate.go @@ -1378,8 +1378,9 @@ func (s *service) generateConvertCode(cmd, name, typ string) { zeroIndex := detailsRequireZeroIndex[cmd] needsIndex := parametersRequireIndexing[name] - // Use index variable if parameter requires it or command doesn't use zero indexing - if zeroIndex && !needsIndex { + shouldUseStaticZeroIndex := zeroIndex && !needsIndex + + if shouldUseStaticZeroIndex { pn("for _, k := range getSortedKeysFromMap(m) {") } else { pn("for i, k := range getSortedKeysFromMap(m) {") @@ -1424,7 +1425,7 @@ func (s *service) generateConvertCode(cmd, name, typ string) { pn(" u.Set(fmt.Sprintf(\"%s[%%d].name\", i), k)", name) pn(" u.Set(fmt.Sprintf(\"%s[%%d].value\", i), m[k])", name) default: - if zeroIndex && !detailsRequireKeyValue[cmd] && !needsIndex { + if shouldUseStaticZeroIndex && !detailsRequireKeyValue[cmd] { pn(" u.Set(fmt.Sprintf(\"%s[0].%%s\", k), m[k])", name) } else { pn(" u.Set(fmt.Sprintf(\"%s[%%d].key\", i), k)", name)