-
Notifications
You must be signed in to change notification settings - Fork 1
/
show.go
121 lines (113 loc) · 3.8 KB
/
show.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
package main
import (
"github.com/BytemarkHosting/bytemark-client/lib"
"github.com/BytemarkHosting/bytemark-client/util/log"
"github.com/urfave/cli"
"os"
)
func init() {
commands = append(commands, cli.Command{
Name: "show",
Action: cli.ShowSubcommandHelp,
Usage: `displays information about the given server, group, or account`,
UsageText: "bytemark show account|server|group|user [flags] <name>",
Description: `displays information about the given server, group, or account`,
Subcommands: []cli.Command{{
Name: "account",
Usage: `displays information about the given account`,
UsageText: "bytemark show account [--json] <name>",
Description: `This command displays information about the given account, including contact details and how many servers are in it across its groups.
If the --json flag is specified, prints a complete overview of the account in JSON format, including all groups and their servers.`,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "json",
Usage: "Output account details as a JSON object",
},
},
Action: With(AccountProvider, func(c *Context) error {
return c.IfNotMarshalJSON(c.Account, func() error {
def, err := global.Client.GetDefaultAccount()
if err != nil {
return err
}
err = lib.FormatAccount(os.Stderr, c.Account, def, "account_overview")
if err != nil {
return err
}
log.Output()
log.Output()
for _, g := range c.Account.Groups {
for _, vm := range g.VirtualMachines {
err := lib.FormatVirtualMachine(os.Stderr, vm, lib.TwoLine)
log.Output()
log.Output()
if err != nil {
return err
}
}
}
return nil
})
}),
}, {
Name: "group",
Usage: "outputs info about a group",
UsageText: "bytemark show group [--json] <name>",
Description: `This command displays information about how many servers are in the given group.
If the --json flag is specified, prints a complete overview of the group in JSON format, including all servers.`,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "json",
Usage: "Output group details as a JSON object",
},
},
Action: With(GroupProvider, func(c *Context) error {
return c.IfNotMarshalJSON(c.Group, func() error {
s := ""
if len(c.Group.VirtualMachines) != 1 {
s = "s"
}
log.Outputf("%s - Group containing %d cloud server%s\r\n", c.Group.Name, len(c.Group.VirtualMachines), s)
log.Output()
for _, vm := range c.Group.VirtualMachines {
err := lib.FormatVirtualMachine(os.Stderr, vm, lib.TwoLine)
log.Output()
log.Output()
if err != nil {
return err
}
}
return nil
})
}),
}, {
Name: "server",
Usage: "displays details about a server",
UsageText: "bytemark show server [--json] <name>",
Description: `Displays a collection of details about the server, including its full hostname, CPU and memory allocation, power status, disc capacities and IP addresses.`,
Flags: []cli.Flag{
cli.BoolFlag{
Name: "json",
Usage: "Output server details as a JSON object.",
},
},
Action: With(VirtualMachineProvider, func(c *Context) error {
return c.IfNotMarshalJSON(c.VirtualMachine, func() error {
return lib.FormatVirtualMachine(os.Stderr, c.VirtualMachine, lib.All)
})
}),
}, {
Name: "user",
Usage: "displays info about a user",
UsageText: "bytemark show user <name>",
Description: `Currently the only details are what SSH keys are authorised for this user`,
Action: With(UserProvider, func(c *Context) error {
log.Outputf("User %s:\n\nAuthorized keys:\n", c.User.Username)
for _, k := range c.User.AuthorizedKeys {
log.Output(k)
}
return nil
}),
}},
})
}