Fix the ListLoadBalancerRuleInstances response (#59)
This one can have two possible response types, depending on the query values used. By adding this, both types are supported.
diff --git a/cloudstack/ISOService.go b/cloudstack/ISOService.go
index af18d18..a4ad582 100644
--- a/cloudstack/ISOService.go
+++ b/cloudstack/ISOService.go
@@ -1771,7 +1771,6 @@
p.p = make(map[string]interface{})
p.p["id"] = id
- p.p["id"] = id
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
diff --git a/cloudstack/LoadBalancerService.go b/cloudstack/LoadBalancerService.go
index 6376199..9900a07 100644
--- a/cloudstack/LoadBalancerService.go
+++ b/cloudstack/LoadBalancerService.go
@@ -1959,12 +1959,11 @@
}
// This is a courtesy helper function, which in some cases may not work as expected!
-func (s *LoadBalancerService) GetLoadBalancerRuleInstanceByID(id string, opts ...OptionFunc) (*LoadBalancerRuleInstance, int, error) {
+func (s *LoadBalancerService) GetLoadBalancerRuleInstanceByID(id string, opts ...OptionFunc) (*VirtualMachine, int, error) {
p := &ListLoadBalancerRuleInstancesParams{}
p.p = make(map[string]interface{})
p.p["id"] = id
- p.p["id"] = id
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
@@ -2008,7 +2007,8 @@
type ListLoadBalancerRuleInstancesResponse struct {
Count int `json:"count"`
- LoadBalancerRuleInstances []*LoadBalancerRuleInstance `json:"lbrulevmidip"`
+ LBRuleVMIDIPs []*LoadBalancerRuleInstance `json:"lbrulevmidip,omitempty"`
+ LoadBalancerRuleInstances []*VirtualMachine `json:"loadbalancerruleinstance,omitempty"`
}
type LoadBalancerRuleInstance struct {
diff --git a/cloudstack/TemplateService.go b/cloudstack/TemplateService.go
index f8e5cf8..30498c7 100644
--- a/cloudstack/TemplateService.go
+++ b/cloudstack/TemplateService.go
@@ -1628,7 +1628,6 @@
p.p = make(map[string]interface{})
p.p["id"] = id
- p.p["id"] = id
for _, fn := range opts {
if err := fn(s.cs, p); err != nil {
diff --git a/generate/generate.go b/generate/generate.go
index 8ecbac2..f6895b6 100644
--- a/generate/generate.go
+++ b/generate/generate.go
@@ -904,7 +904,11 @@
p("%s %s, ", s.parseParamName(ap.Name), mapType(ap.Type))
}
}
- pn("opts ...OptionFunc) (*%s, int, error) {", parseSingular(ln))
+ if ln == "LoadBalancerRuleInstances" {
+ pn("opts ...OptionFunc) (*VirtualMachine, int, error) {")
+ } else {
+ pn("opts ...OptionFunc) (*%s, int, error) {", parseSingular(ln))
+ }
// Generate the function body
pn(" p := &List%sParams{}", ln)
@@ -912,7 +916,7 @@
pn("")
pn(" p.p[\"id\"] = id")
for _, ap := range a.Params {
- if ap.Required {
+ if ap.Required && s.parseParamName(ap.Name) != "id" {
pn(" p.p[\"%s\"] = %s", s.parseParamName(ap.Name), s.parseParamName(ap.Name))
}
}
@@ -1102,7 +1106,8 @@
case "listEgressFirewallRules":
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "firewallrule")
case "listLoadBalancerRuleInstances":
- pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "lbrulevmidip")
+ pn(" LBRuleVMIDIPs []*%s `json:\"%s,omitempty\"`", parseSingular(ln), "lbrulevmidip")
+ pn(" LoadBalancerRuleInstances []*VirtualMachine `json:\"%s,omitempty\"`", strings.ToLower(parseSingular(ln)))
case "registerTemplate":
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "template")
default: