github.com/coreos/mantle@v0.13.0/cmd/ore/azure/replicate-image.go (about) 1 // Copyright 2016 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 azure 16 17 import ( 18 "fmt" 19 20 "github.com/coreos/go-semver/semver" 21 "github.com/spf13/cobra" 22 ) 23 24 var ( 25 cmdReplicateImage = &cobra.Command{ 26 Use: "replicate-image image", 27 Short: "Replicate an OS image in Azure", 28 RunE: runReplicateImage, 29 } 30 31 defaultRegions = []string{ 32 "East US", 33 "West US", 34 "South Central US", 35 "Central US", 36 "North Central US", 37 "East US 2", 38 "North Europe", 39 "West Europe", 40 "Southeast Asia", 41 "East Asia", 42 "Japan West", 43 "Japan East", 44 "Brazil South", 45 "Australia Southeast", 46 "Australia East", 47 "Central India", 48 "South India", 49 "West India", 50 "Canada Central", 51 "Canada East", 52 "UK North", 53 "UK South 2", 54 "West US 2", 55 "West Central US", 56 "UK West", 57 "UK South", 58 "Central US EUAP", 59 "East US 2 EUAP", 60 } 61 62 // replicate image options 63 rio struct { 64 offer string 65 sku string 66 version string 67 regions []string 68 } 69 ) 70 71 func init() { 72 sv := cmdReplicateImage.Flags().StringVar 73 74 sv(&rio.offer, "offer", "CoreOS", "Azure image product name") 75 sv(&rio.sku, "sku", "", "Azure image SKU (stable, beta, alpha for CoreOS)") 76 sv(&rio.version, "version", "", "Azure image version") 77 78 cmdReplicateImage.Flags().StringSliceVar(&rio.regions, "region", defaultRegions, 79 "Azure regions to replicate to") 80 81 Azure.AddCommand(cmdReplicateImage) 82 } 83 84 func runReplicateImage(cmd *cobra.Command, args []string) error { 85 if len(args) != 1 { 86 return fmt.Errorf("expecting 1 argument, got %d", len(args)) 87 } 88 89 if rio.offer == "" { 90 return fmt.Errorf("offer name is required") 91 } 92 93 if rio.sku == "" { 94 return fmt.Errorf("sku is required") 95 } 96 97 if rio.version == "" { 98 return fmt.Errorf("version is required") 99 } 100 101 _, err := semver.NewVersion(rio.version) 102 if err != nil { 103 return fmt.Errorf("version is not valid semver: %v", err) 104 } 105 106 return api.ReplicateImage(args[0], rio.offer, rio.sku, rio.version, rio.regions...) 107 }