github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/cmd/domtool/main.go (about) 1 package main 2 3 import ( 4 "flag" 5 "fmt" 6 "os" 7 8 "github.com/Cloud-Foundations/Dominator/lib/constants" 9 "github.com/Cloud-Foundations/Dominator/lib/flags/commands" 10 "github.com/Cloud-Foundations/Dominator/lib/flags/loadflags" 11 "github.com/Cloud-Foundations/Dominator/lib/flagutil" 12 "github.com/Cloud-Foundations/Dominator/lib/log/cmdlogger" 13 "github.com/Cloud-Foundations/Dominator/lib/srpc" 14 "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" 15 ) 16 17 var ( 18 cpuPercent = flag.Uint("cpuPercent", 0, 19 "CPU speed as percentage of capacity (default 50)") 20 networkSpeedPercent = flag.Uint("networkSpeedPercent", 21 constants.DefaultNetworkSpeedPercent, 22 "Network speed as percentage of capacity") 23 scanExcludeList flagutil.StringList = constants.ScanExcludeList 24 scanSpeedPercent = flag.Uint("scanSpeedPercent", 25 constants.DefaultScanSpeedPercent, 26 "Scan speed as percentage of capacity") 27 domHostname = flag.String("domHostname", "localhost", 28 "Hostname of dominator") 29 domPortNum = flag.Uint("domPortNum", constants.DominatorPortNumber, 30 "Port number of dominator") 31 32 dominatorSrpcClient *srpc.Client 33 ) 34 35 func init() { 36 flag.Var(&scanExcludeList, "scanExcludeList", 37 "Comma separated list of patterns to exclude from scanning") 38 } 39 40 func printUsage() { 41 w := flag.CommandLine.Output() 42 fmt.Fprintln(w, "Usage: domtool [flags...] command") 43 fmt.Fprintln(w, "Common flags:") 44 flag.PrintDefaults() 45 fmt.Fprintln(w, "Commands:") 46 commands.PrintCommands(w, subcommands) 47 } 48 49 var subcommands = []commands.Command{ 50 {"clear-safety-shutoff", "sub", 1, 1, clearSafetyShutoffSubcommand}, 51 {"configure-subs", "", 0, 0, configureSubsSubcommand}, 52 {"disable-updates", "reason", 1, 1, disableUpdatesSubcommand}, 53 {"enable-updates", "reason", 1, 1, enableUpdatesSubcommand}, 54 {"get-default-image", "", 0, 0, getDefaultImageSubcommand}, 55 {"get-subs-configuration", "", 0, 0, getSubsConfigurationSubcommand}, 56 {"set-default-image", "", 1, 1, setDefaultImageSubcommand}, 57 } 58 59 func getClient() *srpc.Client { 60 return dominatorSrpcClient 61 } 62 63 func doMain() int { 64 if err := loadflags.LoadForCli("domtool"); err != nil { 65 fmt.Fprintln(os.Stderr, err) 66 return 1 67 } 68 flag.Usage = printUsage 69 flag.Parse() 70 if flag.NArg() < 1 { 71 printUsage() 72 return 2 73 } 74 logger := cmdlogger.New() 75 if err := setupclient.SetupTls(true); err != nil { 76 fmt.Fprintln(os.Stderr, err) 77 return 1 78 } 79 clientName := fmt.Sprintf("%s:%d", *domHostname, *domPortNum) 80 client, err := srpc.DialHTTP("tcp", clientName, 0) 81 if err != nil { 82 fmt.Fprintf(os.Stderr, "Error dialing\t%s\n", err) 83 os.Exit(1) 84 } 85 dominatorSrpcClient = client 86 return commands.RunCommands(subcommands, printUsage, logger) 87 } 88 89 func main() { 90 os.Exit(doMain()) 91 }