Skip to content

Commit

Permalink
make show servers take a group name instead of account
Browse files Browse the repository at this point in the history
  • Loading branch information
telyn committed May 14, 2018
1 parent 5cf2c38 commit 0510018
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 9 deletions.
36 changes: 27 additions & 9 deletions cmd/bytemark/commands/show/servers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package show

import (
"errors"

"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/args"
"github.com/BytemarkHosting/bytemark-client/cmd/bytemark/app/with"
Expand All @@ -13,23 +15,39 @@ func init() {
Commands = append(Commands, cli.Command{
Name: "servers",
Usage: "show all the servers in an account",
UsageText: "show servers [account]",
UsageText: "show servers [--group <group> | --account <account>] [group]",
Description: `This command shows all the servers in the given account, or in your default account if not specified.
Deleted servers are included in the list, with ' (deleted)' appended.`,
Deleted servers are included in the list, with ' (deleted)' appended.
If --group and --account are specified, the group will be displayed and the account will be ignored.`,
Flags: append(app.OutputFlags("servers", "array"),
cli.GenericFlag{
Name: "group",
Usage: "the group to list the servers of",
Value: new(app.GroupNameFlag),
},
cli.StringFlag{
Name: "account",
Usage: "the account to list the servers of",
Value: new(app.AccountNameFlag),
Usage: "the account to show all the servers of",
},
),
Action: app.Action(args.Optional("account"), with.Account("account"), with.Auth, func(c *app.Context) error {
Action: app.Action(args.Optional("group"), with.Auth, func(c *app.Context) error {
servers := brain.VirtualMachines{}

for _, g := range c.Account.Groups {
servers = append(servers, g.VirtualMachines...)
if c.IsSet("group") {
groupName := c.GroupName("group")
group, err := c.Client().GetGroup(groupName)
if err != nil {
return err
}
return c.OutputInDesiredForm(brain.VirtualMachines(group.VirtualMachines), output.List)
}
if c.IsSet("account") {
for _, g := range c.Account.Groups {
servers = append(servers, g.VirtualMachines...)
}
return c.OutputInDesiredForm(servers, output.List)
}
return c.OutputInDesiredForm(servers, output.List)
return errors.New("A group or account must be specified")
}),
})
}
8 changes: 8 additions & 0 deletions doc/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
bytemark-client (3.2) UNRELEASED; urgency=low

### Changes:
* `show servers` now takes a group instead of an account by default.
`--account <account>` can be specified to list all servers on an account.

-- telyn <telyn@bytemark.co.uk> Mon, 14 May 2018 11:31:25 +0100

bytemark-client (3.1) UNRELEASED; urgency=low

### Admin changes:
Expand Down

0 comments on commit 0510018

Please sign in to comment.