github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/cmd/subtool/listMissingObjects.go (about) 1 package main 2 3 import ( 4 "errors" 5 "fmt" 6 7 "github.com/Cloud-Foundations/Dominator/dom/lib" 8 "github.com/Cloud-Foundations/Dominator/lib/filter" 9 "github.com/Cloud-Foundations/Dominator/lib/log" 10 "github.com/Cloud-Foundations/Dominator/lib/srpc" 11 "github.com/Cloud-Foundations/Dominator/proto/sub" 12 "github.com/Cloud-Foundations/Dominator/sub/client" 13 ) 14 15 func listMissingObjectsSubcommand(args []string, logger log.DebugLogger) error { 16 srpcClient := getSubClientRetry(logger) 17 defer srpcClient.Close() 18 if err := listMissingObjects(srpcClient, args[0]); err != nil { 19 return fmt.Errorf("Error listing missing objects: %s: %s", args[0], err) 20 } 21 return nil 22 } 23 24 func listMissingObjects(srpcClient *srpc.Client, imageName string) error { 25 // Start querying the imageserver for the image. 26 imageServerAddress := fmt.Sprintf("%s:%d", 27 *imageServerHostname, *imageServerPortNum) 28 imgChannel := getImageChannel(imageServerAddress, imageName, timeoutTime) 29 subObj := lib.Sub{ 30 Hostname: *subHostname, 31 Client: srpcClient, 32 } 33 pollRequest := sub.PollRequest{} 34 var pollReply sub.PollResponse 35 if err := client.CallPoll(srpcClient, pollRequest, &pollReply); err != nil { 36 return err 37 } 38 fs := pollReply.FileSystem 39 if fs == nil { 40 return errors.New("sub not ready") 41 } 42 subObj.FileSystem = fs 43 imageResult := <-imgChannel 44 img := imageResult.image 45 if *filterFile != "" { 46 var err error 47 img.Filter, err = filter.Load(*filterFile) 48 if err != nil { 49 return err 50 } 51 } 52 objectsToFetch, _ := lib.BuildMissingLists(subObj, img, false, true, 53 logger) 54 for hashVal := range objectsToFetch { 55 fmt.Printf("%x\n", hashVal) 56 } 57 return nil 58 }