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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1131,6 +1131,7 @@ $ scw inspect myserver | jq '.[0].public_ip.address'

### master (unreleased)

* 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))
* Support of `scw restart -w` ([#185](https://github.com/scaleway/scaleway-cli/issues/185))
* Restarting multiple servers in parallel ([#185](https://github.com/scaleway/scaleway-cli/issues/185))
Expand Down
36 changes: 35 additions & 1 deletion pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,21 @@ type ScalewayUserPatchSSHKeyDefinition struct {
SSHPublicKeys []ScalewayKeyDefinition `json:"ssh_public_keys"`
}

// ScalewayDashboardResp represents a dashboard received from the API
type ScalewayDashboardResp struct {
Dashboard ScalewayDashboard
}

// ScalewayDashboard represents a dashboard
type ScalewayDashboard struct {
VolumesCount int `json:"volumes_count"`
RunningServersCount int `json:"running_servers_count"`
ImagesCount int `json:"images_count"`
SnapshotsCount int `json:"snapshots_count"`
ServersCount int `json:"servers_count"`
IPsCount int `json:"ips_count"`
}

// FuncMap used for json inspection
var FuncMap = template.FuncMap{
"json": func(v interface{}) string {
Expand Down Expand Up @@ -1659,7 +1674,26 @@ func (s *ScalewayAPI) GetUser() (*ScalewayUserDefinition, error) {
return &user.User, nil
}

//
// GetDashboard returns the dashboard
func (s *ScalewayAPI) GetDashboard() (*ScalewayDashboard, error) {
resp, err := s.GetResponse("dashboard")
if err != nil {
return nil, err
}
defer resp.Body.Close()

if resp.StatusCode != 200 {
return nil, fmt.Errorf("[%d] no such dashboard", resp.StatusCode)
}
var dashboard ScalewayDashboardResp

decoder := json.NewDecoder(resp.Body)
err = decoder.Decode(&dashboard)
if err != nil {
return nil, err
}
return &dashboard.Dashboard, nil
}

// GetServerID returns exactly one server matching or dies
func (s *ScalewayAPI) GetServerID(needle string) string {
Expand Down
66 changes: 41 additions & 25 deletions pkg/commands/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,59 @@ type InfoArgs struct{}
func RunInfo(ctx CommandContext, args InfoArgs) error {
// FIXME: fmt.Fprintf(ctx.Stdout, "Servers: %s\n", "quantity")
// FIXME: fmt.Fprintf(ctx.Stdout, "Images: %s\n", "quantity")
fmt.Fprintf(ctx.Stdout, "Debug mode (client): %v\n", ctx.Getenv("DEBUG") != "")
fmt.Fprintf(ctx.Stdout, "Debug mode (client):\t%v\n", ctx.Getenv("DEBUG") != "")

fmt.Fprintf(ctx.Stdout, "Organization: %s\n", ctx.API.Organization)
fmt.Fprintf(ctx.Stdout, "Organization:\t\t%s\n", ctx.API.Organization)
// FIXME: add partially-masked token
fmt.Fprintf(ctx.Stdout, "API Endpoint: %s\n", ctx.Getenv("scaleway_api_endpoint"))
fmt.Fprintf(ctx.Stdout, "API Endpoint:\t\t%s\n", ctx.Getenv("scaleway_api_endpoint"))
configPath, _ := config.GetConfigFilePath()
fmt.Fprintf(ctx.Stdout, "RC file: %s\n", configPath)
fmt.Fprintf(ctx.Stdout, "User: %s\n", ctx.Getenv("USER"))
fmt.Fprintf(ctx.Stdout, "CPUs: %d\n", runtime.NumCPU())
fmt.Fprintf(ctx.Stdout, "RC file:\t\t%s\n", configPath)
fmt.Fprintf(ctx.Stdout, "User:\t\t\t%s\n", ctx.Getenv("USER"))
fmt.Fprintf(ctx.Stdout, "CPUs:\t\t\t%d\n", runtime.NumCPU())
hostname, _ := os.Hostname()
fmt.Fprintf(ctx.Stdout, "Hostname: %s\n", hostname)
fmt.Fprintf(ctx.Stdout, "Hostname:\t\t%s\n", hostname)
cliPath, _ := osext.Executable()
fmt.Fprintf(ctx.Stdout, "CLI Path: %s\n", cliPath)
fmt.Fprintf(ctx.Stdout, "CLI Path:\t\t%s\n", cliPath)

fmt.Fprintln(ctx.Stdout, "")
fmt.Fprintf(ctx.Stdout, "Cache:\t\t\t%s\n", ctx.API.Cache.Path)
fmt.Fprintf(ctx.Stdout, " Servers:\t\t%d\n", ctx.API.Cache.GetNbServers())
fmt.Fprintf(ctx.Stdout, " Images:\t\t%d\n", ctx.API.Cache.GetNbImages())
fmt.Fprintf(ctx.Stdout, " Snapshots:\t\t%d\n", ctx.API.Cache.GetNbSnapshots())
fmt.Fprintf(ctx.Stdout, " Volumes:\t\t%d\n", ctx.API.Cache.GetNbVolumes())
fmt.Fprintf(ctx.Stdout, " Bootscripts:\t\t%d\n", ctx.API.Cache.GetNbBootscripts())

fmt.Fprintf(ctx.Stdout, "Cache: %s\n", ctx.API.Cache.Path)
fmt.Fprintf(ctx.Stdout, " Servers: %d\n", ctx.API.Cache.GetNbServers())
fmt.Fprintf(ctx.Stdout, " Images: %d\n", ctx.API.Cache.GetNbImages())
fmt.Fprintf(ctx.Stdout, " Snapshots: %d\n", ctx.API.Cache.GetNbSnapshots())
fmt.Fprintf(ctx.Stdout, " Volumes: %d\n", ctx.API.Cache.GetNbVolumes())
fmt.Fprintf(ctx.Stdout, " Bootscripts: %d\n", ctx.API.Cache.GetNbBootscripts())
user, err := ctx.API.GetUser()
if err != nil {
return fmt.Errorf("Unable to get your SSH Keys")
}

if len(user.SSHPublicKeys) == 0 {
fmt.Fprintln(ctx.Stdout, "You have no ssh keys")
} else {
if len(user.SSHPublicKeys) == 0 {
fmt.Fprintln(ctx.Stdout, "You have no ssh keys")
} else {
fmt.Fprintln(ctx.Stdout, "SSH Keys:")
for id, key := range user.SSHPublicKeys {
fingerprint, err := utils.SSHGetFingerprint(key.Key)
if err != nil {
return err
} else {
fmt.Fprintf(ctx.Stdout, " [%d] %s\n", id, fingerprint)
}
fmt.Fprintln(ctx.Stdout, "")
fmt.Fprintln(ctx.Stdout, "SSH Keys:")
for id, key := range user.SSHPublicKeys {
fingerprint, err := utils.SSHGetFingerprint(key.Key)
if err != nil {
return err
} else {
fmt.Fprintf(ctx.Stdout, " [%d] %s\n", id, fingerprint)
}
}
}

dashboard, err := ctx.API.GetDashboard()
if err != nil {
return fmt.Errorf("Unable to get your dashboard")
}
fmt.Fprintln(ctx.Stdout, "Dashboard:")
fmt.Fprintf(ctx.Stdout, " Volumes:\t\t%d\n", dashboard.VolumesCount)
fmt.Fprintf(ctx.Stdout, " Running servers:\t%d\n", dashboard.RunningServersCount)
fmt.Fprintf(ctx.Stdout, " Images:\t\t%d\n", dashboard.ImagesCount)
fmt.Fprintf(ctx.Stdout, " Snapshots:\t\t%d\n", dashboard.SnapshotsCount)
fmt.Fprintf(ctx.Stdout, " Servers:\t\t%d\n", dashboard.ServersCount)
fmt.Fprintf(ctx.Stdout, " Ips:\t\t\t%d\n", dashboard.IPsCount)

return nil
}