equinix-labs / metal-go

[Deprecated] Golang client for Equinix Metal
https://deploy.equinix.com/labs/equinix-sdk-go/
MIT License
3 stars 2 forks source link

Returns wrong quantity in capacities check #142

Closed codinja1188 closed 1 year ago

codinja1188 commented 1 year ago

Description:

The quantity filed type is changed from string to int32 (v0.17.0 - v0.19.0). But it returns zero in all cases.

index c745da9..f3c6081 100644
--- a/docs/CapacityCheckPerMetroInfo.md
+++ b/docs/CapacityCheckPerMetroInfo.md
@@ -7,7 +7,7 @@ Name | Type | Description | Notes
 **Available** | Pointer to **bool** | Returns true if there is enough capacity in the metro to fulfill the quantity set. Returns false if there is not enough. | [optional]
 **Metro** | Pointer to **string** | The metro ID or code sent to check capacity. | [optional]
 **Plan** | Pointer to **string** | The plan ID or slug sent to check capacity. | [optional]
-**Quantity** | Pointer to **string** | The number of servers sent to check capacity. | [optional]
+**Quantity** | Pointer to **int32** | The number of servers sent to check capacity. | [optional]

 ## Methods

@@ -105,20 +105,20 @@ HasPlan returns a boolean if a field has been set.

 ### GetQuantity

-`func (o *CapacityCheckPerMetroInfo) GetQuantity() string`
+`func (o *CapacityCheckPerMetroInfo) GetQuantity() int32`

 GetQuantity returns the Quantity field if non-nil, zero value otherwise.

 ### GetQuantityOk

-`func (o *CapacityCheckPerMetroInfo) GetQuantityOk() (*string, bool)`
+`func (o *CapacityCheckPerMetroInfo) GetQuantityOk() (*int32, bool)`

 GetQuantityOk returns a tuple with the Quantity field if it's non-nil, zero value otherwise
 and a boolean to check if the value has been set.

 ### SetQuantity

-`func (o *CapacityCheckPerMetroInfo) SetQuantity(v string)`
+`func (o *CapacityCheckPerMetroInfo) SetQuantity(v int32)`

 SetQuantity sets Quantity field to given value.
Vasubabus-MacBook-Pro:bin vasubabu$ ./metal capacity check -m sv,da -P c3.medium.x86,m3.large.x86 -q 4

+-------+------+----------+--------------+
| METRO | PLAN | QUANTITY | AVAILABILITY |
+-------+------+----------+--------------+
|       |      | 0        | false        |
|       |      | 0        | false        |
|       |      | 0        | false        |
|       |      | 0        | false        |
+-------+------+----------+--------------+
ctreatma commented 1 year ago

@vasubabu can you provide a sample JSON response from the API?

codinja1188 commented 1 year ago

Sample JSON Output

Vasubabus-MacBook-Pro:bin vasubabu$ ./metal capacity check -m sv,da -P c3.medium.x86,m3.large.x86 -q 4
2023/09/07 22:26:46
POST /metal/v1/capacity/metros HTTP/1.1
Host: api.equinix.com
User-Agent: metal-cli/53a8fe2 metal-go/0.19.0
Content-Length: 224
Accept: application/json
Content-Type: application/json
X-Auth-Token: ***
Accept-Encoding: gzip

{"servers":[{"metro":"sv","plan":"c3.medium.x86","quantity":"4"},{"metro":"sv","plan":"m3.large.x86","quantity":"4"},{"metro":"da","plan":"c3.medium.x86","quantity":"4"},{"metro":"da","plan":"m3.large.x86","quantity":"4"}]}

2023/09/07 22:26:48
HTTP/1.1 200 OK
Content-Length: 291
Cache-Control: max-age=0, private, must-revalidate
Connection: keep-alive
Content-Type: application/json; charset=utf-8
Date: Thu, 07 Sep 2023 16:56:48 GMT
Etag: W/"c9f88dbeb76b7a803330ddb59c27ae2b"
Referrer-Policy: strict-origin-when-cross-origin
Strict-Transport-Security: max-age=15724800; includeSubDomains
X-Content-Type-Options: nosniff
X-Download-Options: noopen
X-Frame-Options: SAMEORIGIN
X-Permitted-Cross-Domain-Policies: none
X-Request-Id: 739040d9c2d701ab1bdd8472512b8708
X-Xss-Protection: 1; mode=block

{"servers":[{"metro":"sv","plan":"c3.medium.x86","quantity":"4","available":true},{"metro":"sv","plan":"m3.large.x86","quantity":"4","available":true},{"metro":"da","plan":"c3.medium.x86","quantity":"4","available":true},{"metro":"da","plan":"m3.large.x86","quantity":"4","available":true}]}
+-------+------+----------+--------------+
| METRO | PLAN | QUANTITY | AVAILABILITY |
+-------+------+----------+--------------+
|       |      | 0        | false        |
|       |      | 0        | false        |
|       |      | 0        | false        |
|       |      | 0        | false        |
+-------+------+----------+--------------+
ctreatma commented 1 year ago

It looks like the spec was updated to specify the quantity field as an integer, but the response still has it as a double-quoted string:

{"metro":"sv","plan":"c3.medium.x86","quantity":"4","available":true}

ctreatma commented 1 year ago

This was fixed with a local patch in #143 and then fixed with an upstream fix to the official API spec in #161.