Skip to content

Commit

Permalink
fix handling of map parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
psycofdj committed Aug 30, 2021
1 parent d0a8e7d commit f98e41d
Show file tree
Hide file tree
Showing 2 changed files with 165 additions and 49 deletions.
125 changes: 100 additions & 25 deletions cloudstack/VirtualMachineService.go
Expand Up @@ -849,10 +849,11 @@ func (p *DeployVirtualMachineParams) toURLValues() url.Values {
}
}
if v, found := p.p["dhcpoptionsnetworklist"]; found {
m := v.(map[string]string)
for i, k := range getSortedKeysFromMap(m) {
u.Set(fmt.Sprintf("dhcpoptionsnetworklist[%d].key", i), k)
u.Set(fmt.Sprintf("dhcpoptionsnetworklist[%d].value", i), m[k])
l := v.([]map[string]string)
for i, m := range l {
for key, val := range m {
u.Set(fmt.Sprintf("dhcpoptionsnetworklist[%d].%s", i, key), val)
}
}
}
if v, found := p.p["diskofferingid"]; found {
Expand Down Expand Up @@ -887,10 +888,11 @@ func (p *DeployVirtualMachineParams) toURLValues() url.Values {
u.Set("ipaddress", v.(string))
}
if v, found := p.p["iptonetworklist"]; found {
m := v.(map[string]string)
for i, k := range getSortedKeysFromMap(m) {
u.Set(fmt.Sprintf("iptonetworklist[%d].key", i), k)
u.Set(fmt.Sprintf("iptonetworklist[%d].value", i), m[k])
l := v.([]map[string]string)
for i, m := range l {
for key, val := range m {
u.Set(fmt.Sprintf("iptonetworklist[%d].%s", i, key), val)
}
}
}
if v, found := p.p["keyboard"]; found {
Expand All @@ -910,10 +912,11 @@ func (p *DeployVirtualMachineParams) toURLValues() url.Values {
u.Set("networkids", vv)
}
if v, found := p.p["nicnetworklist"]; found {
m := v.(map[string]string)
for i, k := range getSortedKeysFromMap(m) {
u.Set(fmt.Sprintf("nicnetworklist[%d].key", i), k)
u.Set(fmt.Sprintf("nicnetworklist[%d].value", i), m[k])
l := v.([]map[string]string)
for i, m := range l {
for key, val := range m {
u.Set(fmt.Sprintf("nicnetworklist[%d].%s", i, key), val)
}
}
}
if v, found := p.p["podid"]; found {
Expand Down Expand Up @@ -1048,13 +1051,27 @@ func (p *DeployVirtualMachineParams) SetDetails(v map[string]string) {
p.p["details"] = v
}

func (p *DeployVirtualMachineParams) SetDhcpoptionsnetworklist(v map[string]string) {
func (p *DeployVirtualMachineParams) SetDhcpoptionsnetworklist(v []map[string]string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["dhcpoptionsnetworklist"] = v
}

func (p *DeployVirtualMachineParams) AddDhcpoptionsnetworklist(item map[string]string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
val, found := p.p["dhcpoptionsnetworklist"]
if !found {
p.p["dhcpoptionsnetworklist"] = []map[string]string{}
val = p.p["dhcpoptionsnetworklist"]
}
l := val.([]map[string]string)
l = append(l, item)
p.p["dhcpoptionsnetworklist"] = l
}

func (p *DeployVirtualMachineParams) SetDiskofferingid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
Expand Down Expand Up @@ -1125,13 +1142,27 @@ func (p *DeployVirtualMachineParams) SetIpaddress(v string) {
p.p["ipaddress"] = v
}

func (p *DeployVirtualMachineParams) SetIptonetworklist(v map[string]string) {
func (p *DeployVirtualMachineParams) SetIptonetworklist(v []map[string]string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["iptonetworklist"] = v
}

func (p *DeployVirtualMachineParams) AddIptonetworklist(item map[string]string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
val, found := p.p["iptonetworklist"]
if !found {
p.p["iptonetworklist"] = []map[string]string{}
val = p.p["iptonetworklist"]
}
l := val.([]map[string]string)
l = append(l, item)
p.p["iptonetworklist"] = l
}

func (p *DeployVirtualMachineParams) SetKeyboard(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
Expand Down Expand Up @@ -1167,13 +1198,27 @@ func (p *DeployVirtualMachineParams) SetNetworkids(v []string) {
p.p["networkids"] = v
}

func (p *DeployVirtualMachineParams) SetNicnetworklist(v map[string]string) {
func (p *DeployVirtualMachineParams) SetNicnetworklist(v []map[string]string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["nicnetworklist"] = v
}

func (p *DeployVirtualMachineParams) AddNicnetworklist(item map[string]string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
val, found := p.p["nicnetworklist"]
if !found {
p.p["nicnetworklist"] = []map[string]string{}
val = p.p["nicnetworklist"]
}
l := val.([]map[string]string)
l = append(l, item)
p.p["nicnetworklist"] = l
}

func (p *DeployVirtualMachineParams) SetPodid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
Expand Down Expand Up @@ -3255,10 +3300,11 @@ func (p *MigrateVirtualMachineWithVolumeParams) toURLValues() url.Values {
u.Set("hostid", v.(string))
}
if v, found := p.p["migrateto"]; found {
m := v.(map[string]string)
for i, k := range getSortedKeysFromMap(m) {
u.Set(fmt.Sprintf("migrateto[%d].key", i), k)
u.Set(fmt.Sprintf("migrateto[%d].value", i), m[k])
l := v.([]map[string]string)
for i, m := range l {
for key, val := range m {
u.Set(fmt.Sprintf("migrateto[%d].%s", i, key), val)
}
}
}
if v, found := p.p["virtualmachineid"]; found {
Expand All @@ -3274,13 +3320,27 @@ func (p *MigrateVirtualMachineWithVolumeParams) SetHostid(v string) {
p.p["hostid"] = v
}

func (p *MigrateVirtualMachineWithVolumeParams) SetMigrateto(v map[string]string) {
func (p *MigrateVirtualMachineWithVolumeParams) SetMigrateto(v []map[string]string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["migrateto"] = v
}

func (p *MigrateVirtualMachineWithVolumeParams) AddMigrateto(item map[string]string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
val, found := p.p["migrateto"]
if !found {
p.p["migrateto"] = []map[string]string{}
val = p.p["migrateto"]
}
l := val.([]map[string]string)
l = append(l, item)
p.p["migrateto"] = l
}

func (p *MigrateVirtualMachineWithVolumeParams) SetVirtualmachineid(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
Expand Down Expand Up @@ -5348,10 +5408,11 @@ func (p *UpdateVirtualMachineParams) toURLValues() url.Values {
}
}
if v, found := p.p["dhcpoptionsnetworklist"]; found {
m := v.(map[string]string)
for i, k := range getSortedKeysFromMap(m) {
u.Set(fmt.Sprintf("dhcpoptionsnetworklist[%d].key", i), k)
u.Set(fmt.Sprintf("dhcpoptionsnetworklist[%d].value", i), m[k])
l := v.([]map[string]string)
for i, m := range l {
for key, val := range m {
u.Set(fmt.Sprintf("dhcpoptionsnetworklist[%d].%s", i, key), val)
}
}
}
if v, found := p.p["displayname"]; found {
Expand Down Expand Up @@ -5422,13 +5483,27 @@ func (p *UpdateVirtualMachineParams) SetDetails(v map[string]string) {
p.p["details"] = v
}

func (p *UpdateVirtualMachineParams) SetDhcpoptionsnetworklist(v map[string]string) {
func (p *UpdateVirtualMachineParams) SetDhcpoptionsnetworklist(v []map[string]string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
p.p["dhcpoptionsnetworklist"] = v
}

func (p *UpdateVirtualMachineParams) AddDhcpoptionsnetworklist(item map[string]string) {
if p.p == nil {
p.p = make(map[string]interface{})
}
val, found := p.p["dhcpoptionsnetworklist"]
if !found {
p.p["dhcpoptionsnetworklist"] = []map[string]string{}
val = p.p["dhcpoptionsnetworklist"]
}
l := val.([]map[string]string)
l = append(l, item)
p.p["dhcpoptionsnetworklist"] = l
}

func (p *UpdateVirtualMachineParams) SetDisplayname(v string) {
if p.p == nil {
p.p = make(map[string]interface{})
Expand Down

0 comments on commit f98e41d

Please sign in to comment.