github.com/coreos/mantle@v0.13.0/cmd/ore/aws/copy-image.go (about) 1 // Copyright 2017 CoreOS, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package aws 16 17 import ( 18 "encoding/json" 19 "fmt" 20 "os" 21 22 "github.com/spf13/cobra" 23 ) 24 25 var ( 26 cmdCopyImage = &cobra.Command{ 27 Use: "copy-image <dest-region...>", 28 Short: "Copy AWS image between regions", 29 Long: `Copy an AWS image to one or more regions. 30 31 After a successful run, the final line of output will be a line of JSON describing the resources created. 32 `, 33 RunE: runCopyImage, 34 } 35 36 sourceImageID string 37 ) 38 39 func init() { 40 AWS.AddCommand(cmdCopyImage) 41 cmdCopyImage.Flags().StringVar(&sourceImageID, "image", "", "source AMI") 42 } 43 44 func runCopyImage(cmd *cobra.Command, args []string) error { 45 if len(args) == 0 { 46 fmt.Fprintf(os.Stderr, "Specify one or more regions.\n") 47 os.Exit(2) 48 } 49 50 amis, err := API.CopyImage(sourceImageID, args) 51 if err != nil { 52 fmt.Fprintf(os.Stderr, "Couldn't copy images: %v\n", err) 53 os.Exit(1) 54 } 55 56 err = json.NewEncoder(os.Stdout).Encode(amis) 57 if err != nil { 58 fmt.Fprintf(os.Stderr, "Couldn't encode result: %v\n", err) 59 os.Exit(1) 60 } 61 return nil 62 }