Skip to content

Commit 95a19e4

Browse files
committed
Merge pull request #221 from QuentinPerez/quotas
Quotas
2 parents e8825d4 + 0d7393b commit 95a19e4

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,8 +1132,9 @@ $ scw inspect myserver | jq '.[0].public_ip.address'
11321132
### master (unreleased)
11331133

11341134
* Added _cs ([#180](https://github.com/scaleway/scaleway-cli/issues/180))
1135-
* Added SCALEWAY_VERBOSE_API to make the API more verbose
1136-
* Support of 'scw _ips' command ... ([#196](https://github.com/scaleway/scaleway-cli/issues/196))
1135+
* Report **quotas** in `scw info` ([#130](https://github.com/scaleway/scaleway-cli/issues/130))
1136+
* Added `SCALEWAY_VERBOSE_API` to make the API more verbose
1137+
* Support of `scw _ips` command ... ([#196](https://github.com/scaleway/scaleway-cli/issues/196))
11371138
* Report **permissions** in `scw info` ([#191](https://github.com/scaleway/scaleway-cli/issues/191))
11381139
* Report **dashboard** statistics in `scw info` ([#177](https://github.com/scaleway/scaleway-cli/issues/177))
11391140
* Support of `scw _userdata name VAR=@/path/to/file` ([#183](https://github.com/scaleway/scaleway-cli/issues/183))

pkg/api/api.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,13 @@ type ScalewayUserdatas struct {
734734
UserData []string `json:"user_data"`
735735
}
736736

737+
type ScalewayQuota map[string]int
738+
739+
// ScalewayGetQuotas represents the response of GET /organizations/{orga_id}/quotas
740+
type ScalewayGetQuotas struct {
741+
Quotas ScalewayQuota `json:"quotas"`
742+
}
743+
737744
// ScalewayUserdata represents []byte
738745
type ScalewayUserdata []byte
739746

@@ -2027,6 +2034,28 @@ func (s *ScalewayAPI) GetIP(ipID string) (*ScalewayGetIP, error) {
20272034
return &ip, nil
20282035
}
20292036

2037+
// GetQuotas returns a ScalewayGetQuotas
2038+
func (s *ScalewayAPI) GetQuotas() (*ScalewayGetQuotas, error) {
2039+
s.EnableAccountAPI()
2040+
defer s.DisableAccountAPI()
2041+
resp, err := s.GetResponse(fmt.Sprintf("organizations/%s/quotas", s.Organization))
2042+
if err != nil {
2043+
return nil, err
2044+
}
2045+
defer resp.Body.Close()
2046+
2047+
body, err := s.handleHTTPError([]int{200}, resp)
2048+
if err != nil {
2049+
return nil, err
2050+
}
2051+
var quotas ScalewayGetQuotas
2052+
2053+
if err = json.Unmarshal(body, &quotas); err != nil {
2054+
return nil, err
2055+
}
2056+
return &quotas, nil
2057+
}
2058+
20302059
// GetBootscriptID returns exactly one bootscript matching or dies
20312060
func (s *ScalewayAPI) GetBootscriptID(needle string) string {
20322061
// Parses optional type prefix, i.e: "bootscript:name" -> "name"

pkg/commands/info.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ func RunInfo(ctx CommandContext, args InfoArgs) error {
5858
fingerprint, err := utils.SSHGetFingerprint(key.Key)
5959
if err != nil {
6060
return err
61-
} else {
62-
fmt.Fprintf(ctx.Stdout, " [%d] %s", id, fingerprint)
6361
}
62+
fmt.Fprintf(ctx.Stdout, " [%d] %s", id, fingerprint)
6463
}
6564
fmt.Fprintf(ctx.Stdout, "\n")
6665
}
@@ -91,5 +90,14 @@ func RunInfo(ctx CommandContext, args InfoArgs) error {
9190
}
9291
}
9392
}
93+
fmt.Fprintf(ctx.Stdout, "\n")
94+
quotas, err := ctx.API.GetQuotas()
95+
if err != nil {
96+
return fmt.Errorf("Unable to get your quotas")
97+
}
98+
fmt.Fprintln(ctx.Stdout, "Quotas:")
99+
for key, value := range quotas.Quotas {
100+
fmt.Fprintf(ctx.Stdout, " %-20s: %d\n", key, value)
101+
}
94102
return nil
95103
}

0 commit comments

Comments
 (0)