Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cloudstack/ASNumberRangeService.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ func (s *ASNumberRangeService) ListASNRanges(p *ListASNRangesParams) (*ListASNRa

type ListASNRangesResponse struct {
Count int `json:"count"`
ASNRanges []*ASNRange `json:"asnrange"`
ASNRanges []*ASNRange `json:"asnumberrange"`
}

type ASNRange struct {
Expand Down
2 changes: 1 addition & 1 deletion cloudstack/BackupService.go
Original file line number Diff line number Diff line change
Expand Up @@ -3544,7 +3544,7 @@ func (s *BackupService) ListBackupProviders(p *ListBackupProvidersParams) (*List

type ListBackupProvidersResponse struct {
Count int `json:"count"`
BackupProviders []*BackupProvider `json:"backupprovider"`
BackupProviders []*BackupProvider `json:"providers"`
}

type BackupProvider struct {
Expand Down
3 changes: 1 addition & 2 deletions cloudstack/CertificateService.go
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,7 @@ func (s *CertificateService) ListCaCertificate(p *ListCaCertificateParams) (*Lis
}

type ListCaCertificateResponse struct {
Count int `json:"count"`
CaCertificate []*CaCertificate `json:"cacertificate"`
CaCertificate *CaCertificate `json:"cacertificates"`
}

type CaCertificate struct {
Expand Down
2 changes: 1 addition & 1 deletion cloudstack/ClusterService.go
Original file line number Diff line number Diff line change
Expand Up @@ -2686,7 +2686,7 @@ func (s *ClusterService) ListClustersMetrics(p *ListClustersMetricsParams) (*Lis

type ListClustersMetricsResponse struct {
Count int `json:"count"`
ClustersMetrics []*ClustersMetric `json:"clustersmetric"`
ClustersMetrics []*ClustersMetric `json:"cluster"`
}

type ClustersMetric struct {
Expand Down
2 changes: 1 addition & 1 deletion cloudstack/ExtensionService.go
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ func (s *ExtensionService) ListCustomActions(p *ListCustomActionsParams) (*ListC

type ListCustomActionsResponse struct {
Count int `json:"count"`
CustomActions []*CustomAction `json:"customaction"`
CustomActions []*CustomAction `json:"extensioncustomaction"`
}

type CustomAction struct {
Expand Down
2 changes: 1 addition & 1 deletion cloudstack/FirewallService.go
Original file line number Diff line number Diff line change
Expand Up @@ -4094,7 +4094,7 @@ func (s *FirewallService) ListRoutingFirewallRules(p *ListRoutingFirewallRulesPa

type ListRoutingFirewallRulesResponse struct {
Count int `json:"count"`
RoutingFirewallRules []*RoutingFirewallRule `json:"routingfirewallrule"`
RoutingFirewallRules []*RoutingFirewallRule `json:"firewallrule"`
}

type RoutingFirewallRule struct {
Expand Down
2 changes: 1 addition & 1 deletion cloudstack/HostService.go
Original file line number Diff line number Diff line change
Expand Up @@ -4193,7 +4193,7 @@ func (s *HostService) ListHostsMetrics(p *ListHostsMetricsParams) (*ListHostsMet

type ListHostsMetricsResponse struct {
Count int `json:"count"`
HostsMetrics []*HostsMetric `json:"hostsmetric"`
HostsMetrics []*HostsMetric `json:"host"`
}

type HostsMetric struct {
Expand Down
4 changes: 2 additions & 2 deletions cloudstack/NetworkService.go
Original file line number Diff line number Diff line change
Expand Up @@ -3775,7 +3775,7 @@ func (s *NetworkService) ListNetworkIsolationMethods(p *ListNetworkIsolationMeth

type ListNetworkIsolationMethodsResponse struct {
Count int `json:"count"`
NetworkIsolationMethods []*NetworkIsolationMethod `json:"networkisolationmethod"`
NetworkIsolationMethods []*NetworkIsolationMethod `json:"isolationmethod"`
}

type NetworkIsolationMethod struct {
Expand Down Expand Up @@ -6424,7 +6424,7 @@ func (s *NetworkService) ListSupportedNetworkServices(p *ListSupportedNetworkSer

type ListSupportedNetworkServicesResponse struct {
Count int `json:"count"`
SupportedNetworkServices []*SupportedNetworkService `json:"supportednetworkservice"`
SupportedNetworkServices []*SupportedNetworkService `json:"networkservice"`
}

type SupportedNetworkService struct {
Expand Down
2 changes: 1 addition & 1 deletion cloudstack/SystemVMService.go
Original file line number Diff line number Diff line change
Expand Up @@ -1108,7 +1108,7 @@ func (s *SystemVMService) ListSystemVmsUsageHistory(p *ListSystemVmsUsageHistory

type ListSystemVmsUsageHistoryResponse struct {
Count int `json:"count"`
SystemVmsUsageHistory []*SystemVmsUsageHistory `json:"systemvmsusagehistory"`
SystemVmsUsageHistory []*SystemVmsUsageHistory `json:"virtualmachine"`
}

type SystemVmsUsageHistory struct {
Expand Down
5 changes: 2 additions & 3 deletions cloudstack/UsageService.go
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,7 @@ func (s *UsageService) ListTrafficTypeImplementors(p *ListTrafficTypeImplementor

type ListTrafficTypeImplementorsResponse struct {
Count int `json:"count"`
TrafficTypeImplementors []*TrafficTypeImplementor `json:"traffictypeimplementor"`
TrafficTypeImplementors []*TrafficTypeImplementor `json:"traffictypeimplementorresponse"`
}

type TrafficTypeImplementor struct {
Expand Down Expand Up @@ -2128,8 +2128,7 @@ func (s *UsageService) ListUsageServerMetrics(p *ListUsageServerMetricsParams) (
}

type ListUsageServerMetricsResponse struct {
Count int `json:"count"`
UsageServerMetrics []*UsageServerMetric `json:"usageservermetric"`
UsageServerMetrics *UsageServerMetric `json:"usageMetrics"`
}

type UsageServerMetric struct {
Expand Down
2 changes: 1 addition & 1 deletion cloudstack/UserService.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ func (s *UserService) ListUserTwoFactorAuthenticatorProviders(p *ListUserTwoFact

type ListUserTwoFactorAuthenticatorProvidersResponse struct {
Count int `json:"count"`
UserTwoFactorAuthenticatorProviders []*UserTwoFactorAuthenticatorProvider `json:"usertwofactorauthenticatorprovider"`
UserTwoFactorAuthenticatorProviders []*UserTwoFactorAuthenticatorProvider `json:"providers"`
}

type UserTwoFactorAuthenticatorProvider struct {
Expand Down
2 changes: 1 addition & 1 deletion cloudstack/VolumeService.go
Original file line number Diff line number Diff line change
Expand Up @@ -4490,7 +4490,7 @@ func (s *VolumeService) ListVolumesMetrics(p *ListVolumesMetricsParams) (*ListVo

type ListVolumesMetricsResponse struct {
Count int `json:"count"`
VolumesMetrics []*VolumesMetric `json:"volumesmetric"`
VolumesMetrics []*VolumesMetric `json:"volume"`
}

type VolumesMetric struct {
Expand Down
4 changes: 2 additions & 2 deletions cloudstack/ZoneService.go
Original file line number Diff line number Diff line change
Expand Up @@ -2113,7 +2113,7 @@ func (s *ZoneService) ListIpv4SubnetsForZone(p *ListIpv4SubnetsForZoneParams) (*

type ListIpv4SubnetsForZoneResponse struct {
Count int `json:"count"`
Ipv4SubnetsForZone []*Ipv4SubnetsForZone `json:"ipv4subnetsforzone"`
Ipv4SubnetsForZone []*Ipv4SubnetsForZone `json:"zoneipv4subnet"`
}

type Ipv4SubnetsForZone struct {
Expand Down Expand Up @@ -3076,7 +3076,7 @@ func (s *ZoneService) ListZonesMetrics(p *ListZonesMetricsParams) (*ListZonesMet

type ListZonesMetricsResponse struct {
Count int `json:"count"`
ZonesMetrics []*ZonesMetric `json:"zonesmetric"`
ZonesMetrics []*ZonesMetric `json:"zone"`
}

type ZonesMetric struct {
Expand Down
145 changes: 67 additions & 78 deletions generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,59 @@ var customResponseStructTypes = map[string]string{
"findHostsForMigration": "HostForMigration",
}

// listResponseKeys records the JSON key CloudStack uses for the items of a list
// response, for every API where that key differs from the one derived from the
// API name.
var listResponseKeys = map[string]string{
"listAsyncJobs": "asyncjobs",
"listDomainChildren": "domain",
"listEgressFirewallRules": "firewallrule",
"listGuestNetworkIpv6Prefixes": "guestnetworkipv6prefix",
"listHostHAProviders": "haprovider",
"listHostHAResources": "hostha",
"listHypervisorCapabilities": "hypervisorCapabilities",
"listImageStoreObjects": "datastoreobject",
"listLBHealthCheckPolicies": "healthcheckpolicies",
"listLBStickinessPolicies": "stickinesspolicies",
"listManagementServersMetrics": "managementserver",
"listObjectStoragePools": "objectstore",
"listSecondaryStorageSelectors": "heuristics",
"listStoragePoolObjects": "datastoreobject",
"listStoragePoolsMetrics": "storagepool",
"listVirtualMachinesMetrics": "virtualmachine",
"listVirtualMachinesUsageHistory": "virtualmachine",
"listVmwareDcVms": "unmanagedinstance",
"listVolumesUsageHistory": "volume",
"quotaSummary": "summary",
"quotaTariffList": "quotatariff",
"registerTemplate": "template",
"listVnfAppliances": "virtualmachine",
"listVnfTemplates": "template",
"listBackupProviders": "providers",
"listClustersMetrics": "cluster",
"listCustomActions": "extensioncustomaction",
"listHostsMetrics": "host",
"listNetworkIsolationMethods": "isolationmethod",
"listRoutingFirewallRules": "firewallrule",
"listSupportedNetworkServices": "networkservice",
"listSystemVmsUsageHistory": "virtualmachine",
"listTrafficTypeImplementors": "traffictypeimplementorresponse",
"listUserTwoFactorAuthenticatorProviders": "providers",
"listVolumesMetrics": "volume",
"listZonesMetrics": "zone",
"listASNRanges": "asnumberrange",
"listIpv4SubnetsForZone": "zoneipv4subnet",
}

// listResponseKey returns the JSON key for an API's list items, preferring an
// observed key over the one derived from the API name.
func listResponseKey(apiName, listName string) string {
if key, ok := listResponseKeys[apiName]; ok {
return key
}
return strings.ToLower(parseSingular(listName))
}

// We prefill this one value to make sure it is not
// created twice, as this is also a top level type.
var typeNames = map[string]bool{"Nic": true}
Expand Down Expand Up @@ -726,6 +779,9 @@ func (as *allServices) GeneralCode() ([]byte, error) {
pn(" if err := json.Unmarshal(v, &resp); err != nil {")
pn(" return nil, err")
pn(" }")
pn(" if len(resp) == 0 {")
pn(" return nil, fmt.Errorf(\"Unable to extract raw value: empty array for key %%q in:\\n\\n%%s\\n\\n\", k, string(b))")
pn(" }")
pn(" return resp[0], nil")
pn(" }")
pn(" }")
Expand Down Expand Up @@ -2078,40 +2134,28 @@ func (s *service) generateResponseType(a *API) {
a.Name == "registerCniConfiguration" || a.Name == "quotaBalance" || a.Name == "quotaSummary" || a.Name == "quotaTariffList" {
pn("type %s struct {", tn)

// This nasty check is for some specific response that do not behave consistent
// Responses whose *shape* differs: a single object instead of an array,
// no count, more than one collection, or a hand-written field list.
// Responses that differ only in the item key are handled by the default
// arm through listResponseKeys.
switch a.Name {
case "listAsyncJobs":
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "asyncjobs")
case "listCapabilities":
pn(" %s *%s `json:\"%s\"`", ln, parseSingular(ln), "capability")
case "listEgressFirewallRules":
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "firewallrule")
case "listCaCertificate":
// Returns a single object under "cacertificates", with no count.
pn(" %s *%s `json:\"%s\"`", ln, parseSingular(ln), "cacertificates")
case "listUsageServerMetrics":
// Returns a single object under "usageMetrics", with no count.
pn(" %s *%s `json:\"%s\"`", ln, parseSingular(ln), "usageMetrics")
case "listLoadBalancerRuleInstances":
pn(" Count int `json:\"count\"`")
pn(" LBRuleVMIDIPs []*%s `json:\"%s\"`", parseSingular(ln), "lbrulevmidip")
pn(" LoadBalancerRuleInstances []*VirtualMachine `json:\"%s\"`", strings.ToLower(parseSingular(ln)))
case "listVirtualMachinesMetrics":
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "virtualmachine")
case "listManagementServersMetrics":
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "managementserver")
case "listDbMetrics":
pn(" %s %s `json:\"%s\"`", ln, parseSingular(ln), "dbMetrics")
case "registerTemplate":
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "template")
case "listDomainChildren":
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "domain")
case "findHostsForMigration":
pn(" Count int `json:\"count\"`")
pn(" Host []*%s `json:\"%s\"`", customResponseStructTypes[a.Name], "host")
case "listVmwareDcVms":
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "unmanagedinstance")
case "registerUserData":
pn(" Account string `json:\"account\"`")
pn(" Accountid string `json:\"accountid\"`")
Expand All @@ -2126,69 +2170,14 @@ func (s *service) generateResponseType(a *API) {
pn(" Userdata string `json:\"userdata\"`")
case "registerCniConfiguration":
pn(" CniConfiguration *UserData `json:\"cniconfig\"`")
case "listObjectStoragePools":
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "objectstore")
case "listStoragePoolObjects":
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "datastoreobject")
case "listImageStoreObjects":
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "datastoreobject")
case "listVolumesUsageHistory":
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "volume")
case "listHostHAProviders":
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "haprovider")
case "listSecondaryStorageSelectors":
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "heuristics")
case "listVirtualMachinesUsageHistory":
pn(" Count int `json:\"count\"`")
pn(" VirtualMachinesUsageHistory []*VirtualMachinesUsageHistory `json:\"virtualmachine\"`")
case "listHostHAResources":
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "hostha")
case "listInfrastructure":
pn(" Count int `json:\"count\"`")
pn(" %s *%s `json:\"%s\"`", ln, parseSingular(ln), "infrastructure")
case "listStoragePoolsMetrics":
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "storagepool")
case "quotaTariffList":
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "quotatariff")
case "quotaBalance":
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "balance")
case "quotaSummary":
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "summary")
case "listHypervisorCapabilities":
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "hypervisorCapabilities")
case "listGuestNetworkIpv6Prefixes":
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "guestnetworkipv6prefix")
case "listLBHealthCheckPolicies":
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "healthcheckpolicies")
case "listLBStickinessPolicies":
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "stickinesspolicies")
case "listVnfTemplates":
// ListVnfTemplatesCmd is an empty subclass of ListTemplatesCmd, so the
// server returns the items under "template", not "vnftemplate".
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "template")
case "listVnfAppliances":
// ListVnfAppliancesCmd inherits execute() from ListVMsCmd, so the server
// returns the items under "virtualmachine", not "vnfappliance".
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), "virtualmachine")
default:
pn(" Count int `json:\"count\"`")
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), strings.ToLower(parseSingular(ln)))
pn(" %s []*%s `json:\"%s\"`", ln, parseSingular(ln), listResponseKey(a.Name, ln))
}
pn("}")
pn("")
Expand Down
Loading
Loading