Skip to content

Commit d717c7f

Browse files
author
Sander van Harmelen
authored
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.
1 parent f607e24 commit d717c7f

4 files changed

Lines changed: 11 additions & 8 deletions

File tree

cloudstack/ISOService.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1770,7 +1770,6 @@ func (s *ISOService) GetIsoPermissionByID(id string, opts ...OptionFunc) (*IsoPe
17701770
p := &ListIsoPermissionsParams{}
17711771
p.p = make(map[string]interface{})
17721772

1773-
p.p["id"] = id
17741773
p.p["id"] = id
17751774

17761775
for _, fn := range opts {

cloudstack/LoadBalancerService.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1959,11 +1959,10 @@ func (s *LoadBalancerService) NewListLoadBalancerRuleInstancesParams(id string)
19591959
}
19601960

19611961
// This is a courtesy helper function, which in some cases may not work as expected!
1962-
func (s *LoadBalancerService) GetLoadBalancerRuleInstanceByID(id string, opts ...OptionFunc) (*LoadBalancerRuleInstance, int, error) {
1962+
func (s *LoadBalancerService) GetLoadBalancerRuleInstanceByID(id string, opts ...OptionFunc) (*VirtualMachine, int, error) {
19631963
p := &ListLoadBalancerRuleInstancesParams{}
19641964
p.p = make(map[string]interface{})
19651965

1966-
p.p["id"] = id
19671966
p.p["id"] = id
19681967

19691968
for _, fn := range opts {
@@ -2008,7 +2007,8 @@ func (s *LoadBalancerService) ListLoadBalancerRuleInstances(p *ListLoadBalancerR
20082007

20092008
type ListLoadBalancerRuleInstancesResponse struct {
20102009
Count int `json:"count"`
2011-
LoadBalancerRuleInstances []*LoadBalancerRuleInstance `json:"lbrulevmidip"`
2010+
LBRuleVMIDIPs []*LoadBalancerRuleInstance `json:"lbrulevmidip,omitempty"`
2011+
LoadBalancerRuleInstances []*VirtualMachine `json:"loadbalancerruleinstance,omitempty"`
20122012
}
20132013

20142014
type LoadBalancerRuleInstance struct {

cloudstack/TemplateService.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1627,7 +1627,6 @@ func (s *TemplateService) GetTemplatePermissionByID(id string, opts ...OptionFun
16271627
p := &ListTemplatePermissionsParams{}
16281628
p.p = make(map[string]interface{})
16291629

1630-
p.p["id"] = id
16311630
p.p["id"] = id
16321631

16331632
for _, fn := range opts {

generate/generate.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,15 +904,19 @@ func (s *service) generateHelperFuncs(a *API) {
904904
p("%s %s, ", s.parseParamName(ap.Name), mapType(ap.Type))
905905
}
906906
}
907-
pn("opts ...OptionFunc) (*%s, int, error) {", parseSingular(ln))
907+
if ln == "LoadBalancerRuleInstances" {
908+
pn("opts ...OptionFunc) (*VirtualMachine, int, error) {")
909+
} else {
910+
pn("opts ...OptionFunc) (*%s, int, error) {", parseSingular(ln))
911+
}
908912

909913
// Generate the function body
910914
pn(" p := &List%sParams{}", ln)
911915
pn(" p.p = make(map[string]interface{})")
912916
pn("")
913917
pn(" p.p[\"id\"] = id")
914918
for _, ap := range a.Params {
915-
if ap.Required {
919+
if ap.Required && s.parseParamName(ap.Name) != "id" {
916920
pn(" p.p[\"%s\"] = %s", s.parseParamName(ap.Name), s.parseParamName(ap.Name))
917921
}
918922
}
@@ -1102,7 +1106,8 @@ func (s *service) generateResponseType(a *API) {
11021106
case "listEgressFirewallRules":
11031107
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "firewallrule")
11041108
case "listLoadBalancerRuleInstances":
1105-
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "lbrulevmidip")
1109+
pn(" LBRuleVMIDIPs []*%s `json:\"%s,omitempty\"`", parseSingular(ln), "lbrulevmidip")
1110+
pn(" LoadBalancerRuleInstances []*VirtualMachine `json:\"%s,omitempty\"`", strings.ToLower(parseSingular(ln)))
11061111
case "registerTemplate":
11071112
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "template")
11081113
default:

0 commit comments

Comments
 (0)