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