github.com/Cloud-Foundations/Dominator@v0.3.4/cmd/subtool/fetchImage.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/Cloud-Foundations/Dominator/dom/lib"
     7  	"github.com/Cloud-Foundations/Dominator/lib/log"
     8  	"github.com/Cloud-Foundations/Dominator/lib/srpc"
     9  )
    10  
    11  func fetchImageSubcommand(args []string, logger log.DebugLogger) error {
    12  	startTime := showStart("getSubClient()")
    13  	srpcClient := getSubClientRetry(logger)
    14  	defer srpcClient.Close()
    15  	showTimeTaken(startTime)
    16  	if err := fetchImage(srpcClient, args[0]); err != nil {
    17  		return fmt.Errorf("error fetching image: %s: %s", args[0], err)
    18  	}
    19  	return nil
    20  }
    21  
    22  func fetchImage(srpcClient *srpc.Client, imageName string) error {
    23  	imageServerAddress := fmt.Sprintf("%s:%d",
    24  		*imageServerHostname, *imageServerPortNum)
    25  	img, err := getImageRetry(imageServerAddress, imageName, timeoutTime)
    26  	if err != nil {
    27  		logger.Fatalf("Error getting image: %s\n", err)
    28  	}
    29  	subObj := lib.Sub{
    30  		Hostname: *subHostname,
    31  		Client:   srpcClient,
    32  	}
    33  	return pollFetchAndPush(&subObj, img, imageServerAddress, timeoutTime, true,
    34  		logger)
    35  }