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

     1  package main
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  
     7  	"github.com/Cloud-Foundations/Dominator/imageserver/client"
     8  	"github.com/Cloud-Foundations/Dominator/lib/log"
     9  	"github.com/Cloud-Foundations/Dominator/lib/srpc"
    10  )
    11  
    12  func copyImageSubcommand(args []string, logger log.DebugLogger) error {
    13  	imageSClient, _ := getClients()
    14  	if err := copyImage(imageSClient, args[0], args[1], logger); err != nil {
    15  		return fmt.Errorf("error copying image: %s", err)
    16  	}
    17  	return nil
    18  }
    19  
    20  func copyImage(imageSClient *srpc.Client, name, oldImageName string,
    21  	logger log.DebugLogger) error {
    22  	imageExists, err := client.CheckImage(imageSClient, name)
    23  	if err != nil {
    24  		return errors.New("error checking for image existence: " + err.Error())
    25  	}
    26  	if imageExists {
    27  		return errors.New("image exists")
    28  	}
    29  	image, err := getTypedImage(oldImageName)
    30  	if err != nil {
    31  		return err
    32  	}
    33  	return addImage(imageSClient, name, image, logger)
    34  }