From 10cb11794094753966cd588d10ef94ee76535741 Mon Sep 17 00:00:00 2001 From: Quentin Perez Date: Sat, 17 Oct 2015 13:28:44 +0200 Subject: [PATCH 1/2] Add GetQuotas --- pkg/api/api.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/pkg/api/api.go b/pkg/api/api.go index 19a73e2d46..22d42e9c9d 100644 --- a/pkg/api/api.go +++ b/pkg/api/api.go @@ -734,6 +734,13 @@ type ScalewayUserdatas struct { UserData []string `json:"user_data"` } +type ScalewayQuota map[string]int + +// ScalewayGetQuotas represents the response of GET /organizations/{orga_id}/quotas +type ScalewayGetQuotas struct { + Quotas ScalewayQuota `json:"quotas"` +} + // ScalewayUserdata represents []byte type ScalewayUserdata []byte @@ -2027,6 +2034,28 @@ func (s *ScalewayAPI) GetIP(ipID string) (*ScalewayGetIP, error) { return &ip, nil } +// GetQuotas returns a ScalewayGetQuotas +func (s *ScalewayAPI) GetQuotas() (*ScalewayGetQuotas, error) { + s.EnableAccountAPI() + defer s.DisableAccountAPI() + resp, err := s.GetResponse(fmt.Sprintf("organizations/%s/quotas", s.Organization)) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + body, err := s.handleHTTPError([]int{200}, resp) + if err != nil { + return nil, err + } + var quotas ScalewayGetQuotas + + if err = json.Unmarshal(body, "as); err != nil { + return nil, err + } + return "as, nil +} + // GetBootscriptID returns exactly one bootscript matching or dies func (s *ScalewayAPI) GetBootscriptID(needle string) string { // Parses optional type prefix, i.e: "bootscript:name" -> "name" From 0d7393b83c055ea52f49a6b1bf916eee3298bb09 Mon Sep 17 00:00:00 2001 From: Quentin Perez Date: Mon, 19 Oct 2015 10:51:57 +0200 Subject: [PATCH 2/2] Add quota informations in scw info --- README.md | 5 +++-- pkg/commands/info.go | 12 ++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9425569ebd..270e5c8cad 100644 --- a/README.md +++ b/README.md @@ -1132,8 +1132,9 @@ $ scw inspect myserver | jq '.[0].public_ip.address' ### master (unreleased) * Added _cs ([#180](https://github.com/scaleway/scaleway-cli/issues/180)) -* Added SCALEWAY_VERBOSE_API to make the API more verbose -* Support of 'scw _ips' command ... ([#196](https://github.com/scaleway/scaleway-cli/issues/196)) +* Report **quotas** in `scw info` ([#130](https://github.com/scaleway/scaleway-cli/issues/130)) +* Added `SCALEWAY_VERBOSE_API` to make the API more verbose +* Support of `scw _ips` command ... ([#196](https://github.com/scaleway/scaleway-cli/issues/196)) * Report **permissions** in `scw info` ([#191](https://github.com/scaleway/scaleway-cli/issues/191)) * Report **dashboard** statistics in `scw info` ([#177](https://github.com/scaleway/scaleway-cli/issues/177)) * Support of `scw _userdata name VAR=@/path/to/file` ([#183](https://github.com/scaleway/scaleway-cli/issues/183)) diff --git a/pkg/commands/info.go b/pkg/commands/info.go index 28d666a026..694a73b433 100644 --- a/pkg/commands/info.go +++ b/pkg/commands/info.go @@ -58,9 +58,8 @@ func RunInfo(ctx CommandContext, args InfoArgs) error { fingerprint, err := utils.SSHGetFingerprint(key.Key) if err != nil { return err - } else { - fmt.Fprintf(ctx.Stdout, " [%d] %s", id, fingerprint) } + fmt.Fprintf(ctx.Stdout, " [%d] %s", id, fingerprint) } fmt.Fprintf(ctx.Stdout, "\n") } @@ -91,5 +90,14 @@ func RunInfo(ctx CommandContext, args InfoArgs) error { } } } + fmt.Fprintf(ctx.Stdout, "\n") + quotas, err := ctx.API.GetQuotas() + if err != nil { + return fmt.Errorf("Unable to get your quotas") + } + fmt.Fprintln(ctx.Stdout, "Quotas:") + for key, value := range quotas.Quotas { + fmt.Fprintf(ctx.Stdout, " %-20s: %d\n", key, value) + } return nil }