cloudstack-go icon indicating copy to clipboard operation
cloudstack-go copied to clipboard

update listApis.json, Quota API, and fixed double url value handling

Open tonymmm1 opened this issue 1 year ago • 8 comments

https://cloudstack.apache.org/api/apidocs-4.19/

Quota api implementation

tonymmm1 avatar Jul 22 '24 08:07 tonymmm1

Requesting a review to check any mistakes/issues in implementation. @vishesh92 @mlsorensen

tonymmm1 avatar Jul 22 '24 23:07 tonymmm1

I noticed that the listApis.json was missing the api functions.

tonymmm1 avatar Jul 24 '24 00:07 tonymmm1

quotaUpdate that was generated has additional response fields in the struct when the documentation states it should only show "updated_on".

type QuotaUpdateResponse struct {
	JobID      string `json:"jobid"`
	Jobstatus  int    `json:"jobstatus"`
	Updated_on string `json:"updated_on"`
}

However the new listApis.json from cloudmonkey cli seems to show more fields than the documentation. So documentation might be a bit stale.

    {
      "description": "Update quota calculations, alerts and statements",
      "isasync": false,
      "name": "quotaUpdate",
      "params": [],
      "related": "",
      "response": [
        {},
        {},
        {
          "description": "the current status of the latest async job acting on this object",
          "name": "jobstatus",
          "type": "integer"
        },
        {
          "description": "timestamp when the run got over",
          "name": "updated_on",
          "type": "date"
        },
        {
          "description": "the UUID of the latest async job acting on this object",
          "name": "jobid",
          "type": "string"
        }
      ],
      "since": "4.7.0"
    },

tonymmm1 avatar Jul 24 '24 01:07 tonymmm1

# github.com/apache/cloudstack-go/v2/cloudstack
cloudstack/QuotaService.go:235:5: v declared and not used
cloudstack/QuotaService.go:241:5: v declared and not used
cloudstack/QuotaService.go:849:5: v declared and not used
cloudstack/QuotaService.go:1418:5: v declared and not used
FAIL    github.com/apache/cloudstack-go/v2/cloudstack [build failed]
FAIL    github.com/apache/cloudstack-go/v2/examples [build failed]
?       github.com/apache/cloudstack-go/v2/generate     [no test files]
FAIL    github.com/apache/cloudstack-go/v2/test [build failed]
FAIL

tonymmm1 avatar Jul 24 '24 02:07 tonymmm1

seems to be an issue with generator.go on double types

tonymmm1 avatar Jul 24 '24 02:07 tonymmm1

Fixed the double/float type generation.

==================================================================
Random Seed: 1721788077

Will run 4 of 4 specs
••••

Ran 4 of 4 Specs in 0.000 seconds
SUCCESS! -- 4 Passed | 0 Failed | 0 Pending | 0 Skipped
--- PASS: TestEncodeValues (0.00s)
=== RUN   TestUUID
--- PASS: TestUUID (0.00s)
PASS
ok      github.com/apache/cloudstack-go/v2/test 0.044s

tonymmm1 avatar Jul 24 '24 02:07 tonymmm1

As of cloudstack 14.19.0.2 it seems like the quotaBalance response object does not match listApis.json from cmk-cli.

Is the object I am receiving from cloudstack api.

{
  "quotabalanceresponse": {
    "balance": {
      "startquota": 0,
      "credits": [],
      "startdate": "2024-07-27T11:32:15-0500",
      "currency": "$"
    }
  }
}

Is the generated type.

type QuotaBalanceResponse struct {
	QuotaBalance []*QuotaBalance `json:"balance"`
}

type QuotaBalance 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"`
	Type      int     `json:"type"`
	Unit      string  `json:"unit"`
}

There seems to be no correlation between these types?

tonymmm1 avatar Jul 27 '24 16:07 tonymmm1

Implemented response type overrides for quotaBalance and quotaStatement that should work.

tonymmm1 avatar Jul 27 '24 17:07 tonymmm1

@tonymmm1 can you deal with the conflict, please?

DaanHoogland avatar Dec 13 '24 14:12 DaanHoogland

@tonymmm1 , I rebased your code in PR #98 . please have a quick review if you can.

DaanHoogland avatar Dec 30 '24 16:12 DaanHoogland