github.com/coreos/mantle@v0.13.0/cmd/ore/openstack/create.go (about) 1 // Copyright 2018 Red Hat 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 openstack 16 17 import ( 18 "fmt" 19 "os" 20 21 "github.com/coreos/mantle/sdk" 22 "github.com/spf13/cobra" 23 ) 24 25 var ( 26 cmdCreate = &cobra.Command{ 27 Use: "create-image", 28 Short: "Create image on OpenStack", 29 Long: `Upload an image to OpenStack. 30 31 After a successful run, the final line of output will be the ID of the image. 32 `, 33 RunE: runCreate, 34 } 35 36 path string 37 name string 38 ) 39 40 func init() { 41 OpenStack.AddCommand(cmdCreate) 42 cmdCreate.Flags().StringVar(&path, "file", 43 sdk.BuildRoot()+"/images/amd64-usr/latest/coreos_production_openstack_image.img", 44 "path to CoreOS image (build with: ./image_to_vm.sh --format=openstack ...)") 45 cmdCreate.Flags().StringVar(&name, "name", "", "image name") 46 } 47 48 func runCreate(cmd *cobra.Command, args []string) error { 49 id, err := API.UploadImage(name, path) 50 if err != nil { 51 fmt.Fprintf(os.Stderr, "Couldn't create image: %v\n", err) 52 os.Exit(1) 53 } 54 fmt.Println(id) 55 return nil 56 }