github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/cmd/objecttool/main.go (about) 1 package main 2 3 import ( 4 "flag" 5 "fmt" 6 "os" 7 "time" 8 9 "github.com/Cloud-Foundations/Dominator/lib/constants" 10 "github.com/Cloud-Foundations/Dominator/lib/flags/commands" 11 "github.com/Cloud-Foundations/Dominator/lib/flags/loadflags" 12 "github.com/Cloud-Foundations/Dominator/lib/log/cmdlogger" 13 "github.com/Cloud-Foundations/Dominator/lib/objectserver" 14 objectclient "github.com/Cloud-Foundations/Dominator/lib/objectserver/client" 15 "github.com/Cloud-Foundations/Dominator/lib/srpc/setupclient" 16 ) 17 18 var ( 19 chunkSize = flag.Uint("chunkSize", 65535, "Chunk size for bandwidth test") 20 debug = flag.Bool("debug", false, 21 "If true, show debugging output") 22 objectServerHostname = flag.String("objectServerHostname", "localhost", 23 "Hostname of image server") 24 objectServerPortNum = flag.Uint("objectServerPortNum", 25 constants.ImageServerPortNumber, 26 "Port number of image server") 27 testDuration = flag.Duration("testDuration", time.Second*10, 28 "Duration of bandwidth test") 29 30 objectServer objectserver.ObjectServer 31 ) 32 33 func printUsage() { 34 w := flag.CommandLine.Output() 35 fmt.Fprintln(w, "Usage: objecttool [flags...] check|delete|list [args...]") 36 fmt.Fprintln(w, "Common flags:") 37 flag.PrintDefaults() 38 fmt.Fprintln(w, "Commands:") 39 commands.PrintCommands(w, subcommands) 40 } 41 42 var subcommands = []commands.Command{ 43 {"add", " files...", 1, -1, addObjectsSubcommand}, 44 {"check", " hash", 1, 1, checkObjectSubcommand}, 45 {"get", " hash baseOutputFilename", 2, 2, getObjectSubcommand}, 46 {"mget", " hashesFile directory", 2, 2, getObjectsSubcommand}, 47 {"test-bandwidth-from-server", "", 0, 0, testBandwidthFromServerSubcommand}, 48 {"test-bandwidth-to-server", "", 0, 0, testBandwidthToServerSubcommand}, 49 } 50 51 func getObjectServer() objectserver.ObjectServer { 52 return objectServer 53 } 54 55 func doMain() int { 56 if err := loadflags.LoadForCli("objecttool"); err != nil { 57 fmt.Fprintln(os.Stderr, err) 58 return 1 59 } 60 flag.Usage = printUsage 61 flag.Parse() 62 if flag.NArg() < 1 { 63 printUsage() 64 return 2 65 } 66 logger := cmdlogger.New() 67 if err := setupclient.SetupTls(true); err != nil { 68 fmt.Fprintln(os.Stderr, err) 69 return 1 70 } 71 objectServer = objectclient.NewObjectClient(fmt.Sprintf("%s:%d", 72 *objectServerHostname, *objectServerPortNum)) 73 return commands.RunCommands(subcommands, printUsage, logger) 74 } 75 76 func main() { 77 os.Exit(doMain()) 78 }