github.com/rothwerx/packer@v0.9.0/builder/openstack/image_config.go (about)

     1  package openstack
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/mitchellh/packer/template/interpolate"
     7  )
     8  
     9  // ImageConfig is for common configuration related to creating Images.
    10  type ImageConfig struct {
    11  	ImageName     string            `mapstructure:"image_name"`
    12  	ImageMetadata map[string]string `mapstructure:"metadata"`
    13  }
    14  
    15  func (c *ImageConfig) Prepare(ctx *interpolate.Context) []error {
    16  	errs := make([]error, 0)
    17  	if c.ImageName == "" {
    18  		errs = append(errs, fmt.Errorf("An image_name must be specified"))
    19  	}
    20  
    21  	// By default, OpenStack seems to create the image with an image_type of
    22  	// "snapshot", since it came from snapshotting a VM. A "snapshot" looks
    23  	// slightly different in the OpenStack UI and OpenStack won't show "snapshot"
    24  	// images as a choice in the list of images to boot from for a new instance.
    25  	// See https://github.com/mitchellh/packer/issues/3038
    26  	if c.ImageMetadata == nil {
    27  		c.ImageMetadata = map[string]string{"image_type": "image"}
    28  	} else if c.ImageMetadata["image_type"] == "" {
    29  		c.ImageMetadata["image_type"] = "image"
    30  	}
    31  
    32  	if len(errs) > 0 {
    33  		return errs
    34  	}
    35  
    36  	return nil
    37  }