Skip to content

Commit cf004e9

Browse files
authored
Fix format of details map for update VM (#118)
1 parent 9a71f69 commit cf004e9

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

cloudstack/VirtualMachineService.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9858,8 +9858,8 @@ func (p *UpdateVirtualMachineParams) toURLValues() url.Values {
98589858
}
98599859
if v, found := p.p["details"]; found {
98609860
m := v.(map[string]string)
9861-
for i, k := range getSortedKeysFromMap(m) {
9862-
u.Set(fmt.Sprintf("details[%d].%s", i, k), m[k])
9861+
for _, k := range getSortedKeysFromMap(m) {
9862+
u.Set(fmt.Sprintf("details[0].%s", k), m[k])
98639863
}
98649864
}
98659865
if v, found := p.p["dhcpoptionsnetworklist"]; found {

generate/generate.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,23 @@ var detailsRequireKeyValue = map[string]bool{
5454
// detailsRequireZeroIndex is a prefilled map with a list of details
5555
// that need to be encoded using zero indexing
5656
var detailsRequireZeroIndex = map[string]bool{
57-
"registerTemplate": true,
58-
"updateTemplate": true,
59-
"createAccount": true,
60-
"updateAccount": true,
57+
"registerTemplate": true,
58+
"updateTemplate": true,
59+
"createAccount": true,
60+
"updateAccount": true,
61+
"updateVirtualMachine": true,
62+
}
63+
64+
// parametersRequireIndexing contains map parameters that always need
65+
// index variables (i) even when the command uses zero indexing
66+
var parametersRequireIndexing = map[string]bool{
67+
"userdatadetails": true,
68+
"serviceproviderlist": true,
69+
"usersecuritygrouplist": true,
70+
"tags": true,
71+
"nicnetworklist": true,
72+
"nicipaddresslist": true,
73+
"datadiskofferinglist": true,
6174
}
6275

6376
// requiresPost is a prefilled set of API names that require POST
@@ -1363,7 +1376,11 @@ func (s *service) generateConvertCode(cmd, name, typ string) {
13631376
case "map[string]string":
13641377
pn("m := v.(map[string]string)")
13651378
zeroIndex := detailsRequireZeroIndex[cmd]
1366-
if zeroIndex {
1379+
needsIndex := parametersRequireIndexing[name]
1380+
1381+
shouldUseStaticZeroIndex := zeroIndex && !needsIndex
1382+
1383+
if shouldUseStaticZeroIndex {
13671384
pn("for _, k := range getSortedKeysFromMap(m) {")
13681385
} else {
13691386
pn("for i, k := range getSortedKeysFromMap(m) {")
@@ -1408,7 +1425,7 @@ func (s *service) generateConvertCode(cmd, name, typ string) {
14081425
pn(" u.Set(fmt.Sprintf(\"%s[%%d].name\", i), k)", name)
14091426
pn(" u.Set(fmt.Sprintf(\"%s[%%d].value\", i), m[k])", name)
14101427
default:
1411-
if zeroIndex && !detailsRequireKeyValue[cmd] {
1428+
if shouldUseStaticZeroIndex && !detailsRequireKeyValue[cmd] {
14121429
pn(" u.Set(fmt.Sprintf(\"%s[0].%%s\", k), m[k])", name)
14131430
} else {
14141431
pn(" u.Set(fmt.Sprintf(\"%s[%%d].key\", i), k)", name)

0 commit comments

Comments
 (0)