github.com/coreos/mantle@v0.13.0/cmd/ore/azure/create-image-arm.go (about) 1 // Copyright 2018 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 "encoding/json" 19 "fmt" 20 "os" 21 22 "github.com/spf13/cobra" 23 ) 24 25 var ( 26 cmdCreateImageARM = &cobra.Command{ 27 Use: "create-image-arm", 28 Short: "Create Azure image", 29 Long: "Create Azure image from a blob url", 30 RunE: runCreateImageARM, 31 } 32 33 imageName string 34 blobUrl string 35 resourceGroup string 36 ) 37 38 func init() { 39 sv := cmdCreateImageARM.Flags().StringVar 40 41 sv(&imageName, "image-name", "", "image name") 42 sv(&blobUrl, "image-blob", "", "source blob url") 43 sv(&resourceGroup, "resource-group", "kola", "resource group name") 44 45 Azure.AddCommand(cmdCreateImageARM) 46 } 47 48 func runCreateImageARM(cmd *cobra.Command, args []string) error { 49 if err := api.SetupClients(); err != nil { 50 fmt.Fprintf(os.Stderr, "setting up clients: %v\n", err) 51 os.Exit(1) 52 } 53 img, err := api.CreateImage(imageName, resourceGroup, blobUrl) 54 if err != nil { 55 fmt.Fprintf(os.Stderr, "Couldn't create image: %v\n", err) 56 os.Exit(1) 57 } 58 if img.ID == nil { 59 fmt.Fprintf(os.Stderr, "received nil image\n") 60 os.Exit(1) 61 } 62 err = json.NewEncoder(os.Stdout).Encode(&struct { 63 ID *string 64 Location *string 65 }{ 66 ID: img.ID, 67 Location: img.Location, 68 }) 69 if err != nil { 70 fmt.Fprintf(os.Stderr, "Couldn't encode result: %v\n", err) 71 os.Exit(1) 72 } 73 return nil 74 }