Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
29 changes: 29 additions & 0 deletions pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,13 @@ type ScalewayUserdatas struct {
UserData []string `json:"user_data"`
}

type ScalewayQuota map[string]int

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exported type ScalewayQuota should have comment or be unexported


// ScalewayGetQuotas represents the response of GET /organizations/{orga_id}/quotas
type ScalewayGetQuotas struct {
Quotas ScalewayQuota `json:"quotas"`
}

// ScalewayUserdata represents []byte
type ScalewayUserdata []byte

Expand Down Expand Up @@ -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, &quotas); err != nil {
return nil, err
}
return &quotas, 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"
Expand Down
12 changes: 10 additions & 2 deletions pkg/commands/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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
}