forked from Cloud-Foundations/Dominator
/
main.go
92 lines (82 loc) · 2.68 KB
/
main.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
package main
import (
"flag"
"fmt"
"os"
"github.com/Cloud-Foundations/Dominator/lib/constants"
"github.com/Cloud-Foundations/Dominator/lib/flags/commands"
"github.com/Cloud-Foundations/Dominator/lib/flags/loadflags"
"github.com/Cloud-Foundations/Dominator/lib/flagutil"
"github.com/Cloud-Foundations/Dominator/lib/log/cmdlogger"
"github.com/Cloud-Foundations/Dominator/lib/srpc"
"github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient"
)
var (
cpuPercent = flag.Uint("cpuPercent", 0,
"CPU speed as percentage of capacity (default 50)")
networkSpeedPercent = flag.Uint("networkSpeedPercent",
constants.DefaultNetworkSpeedPercent,
"Network speed as percentage of capacity")
scanExcludeList flagutil.StringList = constants.ScanExcludeList
scanSpeedPercent = flag.Uint("scanSpeedPercent",
constants.DefaultScanSpeedPercent,
"Scan speed as percentage of capacity")
domHostname = flag.String("domHostname", "localhost",
"Hostname of dominator")
domPortNum = flag.Uint("domPortNum", constants.DominatorPortNumber,
"Port number of dominator")
dominatorSrpcClient *srpc.Client
)
func init() {
flag.Var(&scanExcludeList, "scanExcludeList",
"Comma separated list of patterns to exclude from scanning")
}
func printUsage() {
w := flag.CommandLine.Output()
fmt.Fprintln(w, "Usage: domtool [flags...] command")
fmt.Fprintln(w, "Common flags:")
flag.PrintDefaults()
fmt.Fprintln(w, "Commands:")
commands.PrintCommands(w, subcommands)
}
var subcommands = []commands.Command{
{"clear-safety-shutoff", "sub", 1, 1, clearSafetyShutoffSubcommand},
{"configure-subs", "", 0, 0, configureSubsSubcommand},
{"disable-updates", "reason", 1, 1, disableUpdatesSubcommand},
{"enable-updates", "reason", 1, 1, enableUpdatesSubcommand},
{"get-default-image", "", 0, 0, getDefaultImageSubcommand},
{"get-subs-configuration", "", 0, 0, getSubsConfigurationSubcommand},
{"set-default-image", "", 1, 1, setDefaultImageSubcommand},
}
func getClient() *srpc.Client {
return dominatorSrpcClient
}
func doMain() int {
if err := loadflags.LoadForCli("domtool"); err != nil {
fmt.Fprintln(os.Stderr, err)
return 1
}
flag.Usage = printUsage
flag.Parse()
if flag.NArg() < 1 {
printUsage()
return 2
}
logger := cmdlogger.New()
srpc.SetDefaultLogger(logger)
if err := setupclient.SetupTls(true); err != nil {
fmt.Fprintln(os.Stderr, err)
return 1
}
clientName := fmt.Sprintf("%s:%d", *domHostname, *domPortNum)
client, err := srpc.DialHTTP("tcp", clientName, 0)
if err != nil {
fmt.Fprintf(os.Stderr, "Error dialing: %s\n", err)
os.Exit(1)
}
dominatorSrpcClient = client
return commands.RunCommands(subcommands, printUsage, logger)
}
func main() {
os.Exit(doMain())
}