You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by da...@apache.org on 2024/12/30 15:18:45 UTC

(cloudstack-go) 21/25: add custom quotaStatement response type to match actual cloudstack api response

This is an automated email from the ASF dual-hosted git repository.

dahn pushed a commit to branch pr90
in repository https://gitbox.apache.org/repos/asf/cloudstack-go.git

commit 224cd1681bb21a60878a6e09fa9cdddd485bac99
Author: tonymmm1 <to...@mail.magnatox.com>
AuthorDate: Sat Jul 27 12:33:51 2024 -0500

    add custom quotaStatement response type to match actual cloudstack api response
---
 cloudstack/QuotaService.go | 23 ++++++++++++++++-------
 generate/generate.go       | 37 +++++++++++++++++++++++++++++++++----
 2 files changed, 49 insertions(+), 11 deletions(-)

diff --git a/cloudstack/QuotaService.go b/cloudstack/QuotaService.go
index 53ca6f5..66aae9d 100644
--- a/cloudstack/QuotaService.go
+++ b/cloudstack/QuotaService.go
@@ -613,15 +613,24 @@ func (s *QuotaService) QuotaStatement(p *QuotaStatementParams) (*QuotaStatementR
 }
 
 type QuotaStatementResponse struct {
-	Account   string  `json:"account"`
-	Accountid int64   `json:"accountid"`
-	Domain    int64   `json:"domain"`
-	JobID     string  `json:"jobid"`
-	Jobstatus int     `json:"jobstatus"`
-	Name      string  `json:"name"`
-	Quota     float64 `json:"quota"`
+	Statement QuotaStatementResponseType `json:"statement"`
+}
+
+type QuotaStatementResponseType struct {
+	QuotaUsage []QuotaUsage `json:"quotausage"`
+	TotalQuota float64      `json:"totalquota"`
+	StartDate  string       `json:"startdate"`
+	EndDate    string       `json:"enddate"`
+	Currency   string       `json:"currency"`
+}
+
+type QuotaUsage struct {
 	Type      int     `json:"type"`
+	Accountid int     `json:"accountid"`
+	Domain    int     `json:"domain"`
+	Name      string  `json:"name"`
 	Unit      string  `json:"unit"`
+	Quota     float64 `json:"quota"`
 }
 
 type QuotaSummaryParams struct {
diff --git a/generate/generate.go b/generate/generate.go
index 004c534..1387c9f 100644
--- a/generate/generate.go
+++ b/generate/generate.go
@@ -1863,13 +1863,40 @@ func isSuccessOnlyResponse(resp APIResponses) bool {
 func (s *service) generateResponseType(a *API) {
 	pn := s.pn
 	tn := capitalize(strings.TrimPrefix(a.Name, "configure") + "Response")
+
+	// add custom response types for some specific API calls
+	if a.Name == "quotaStatement" {
+		pn("type QuotaStatementResponse struct {")
+		pn("    Statement QuotaStatementResponseType `json:\"statement\"`")
+		pn("}")
+		pn("")
+		pn("type QuotaStatementResponseType struct {")
+		pn("    QuotaUsage []QuotaUsage `json:\"quotausage\"`")
+		pn("    TotalQuota float64      `json:\"totalquota\"`")
+		pn("    StartDate  string       `json:\"startdate\"`")
+		pn("    EndDate    string       `json:\"enddate\"`")
+		pn("    Currency   string       `json:\"currency\"`")
+		pn("}")
+		pn("")
+		pn("type QuotaUsage struct {")
+		pn("    Type      int     `json:\"type\"`")
+		pn("    Accountid int     `json:\"accountid\"`")
+		pn("    Domain    int     `json:\"domain\"`")
+		pn("    Name      string  `json:\"name\"`")
+		pn("    Unit      string  `json:\"unit\"`")
+		pn("    Quota     float64 `json:\"quota\"`")
+		pn("}")
+		pn("")
+		return
+	}
+
 	ln := capitalize(strings.TrimPrefix(a.Name, "list"))
 
 	// If this is a 'list' response, we need an separate list struct. There seem to be other
 	// types of responses that also need a separate list struct, so checking on exact matches
 	// for those once.
 	if strings.HasPrefix(a.Name, "list") || a.Name == "registerTemplate" || a.Name == "findHostsForMigration" ||
-		a.Name == "quotaSummary" || a.Name == "quotaTariffList" {
+		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
@@ -1903,12 +1930,14 @@ func (s *service) generateResponseType(a *API) {
 		case "findHostsForMigration":
 			pn(" Count int `json:\"count\"`")
 			pn(" Host []*%s `json:\"%s\"`", customResponseStructTypes[a.Name], "host")
-		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 "quotaTariffList":
+			pn("	Count int `json:\"count\"`")
+			pn("	%s []*%s `json:\"%s\"`", ln, parseSingular(ln), "quotatariff")
 		default:
 			pn("	Count int `json:\"count\"`")
 			pn("	%s []*%s `json:\"%s\"`", ln, parseSingular(ln), strings.ToLower(parseSingular(ln)))