github.com/cloud-foundations/dominator@v0.0.0-20221004181915-6e4fee580046/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]); 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) error { 21 imageExists, err := client.CheckImage(imageSClient, name) 22 if err != nil { 23 return errors.New("error checking for image existence: " + err.Error()) 24 } 25 if imageExists { 26 return errors.New("image exists") 27 } 28 image, err := getImage(imageSClient, oldImageName) 29 if err != nil { 30 return err 31 } 32 return addImage(imageSClient, name, image) 33 }