github.com/sneal/packer@v0.5.2/builder/openstack/image_config.go (about) 1 package openstack 2 3 import ( 4 "fmt" 5 "github.com/mitchellh/packer/packer" 6 ) 7 8 // ImageConfig is for common configuration related to creating Images. 9 type ImageConfig struct { 10 ImageName string `mapstructure:"image_name"` 11 } 12 13 func (c *ImageConfig) Prepare(t *packer.ConfigTemplate) []error { 14 if t == nil { 15 var err error 16 t, err = packer.NewConfigTemplate() 17 if err != nil { 18 return []error{err} 19 } 20 } 21 22 templates := map[string]*string{ 23 "image_name": &c.ImageName, 24 } 25 26 errs := make([]error, 0) 27 for n, ptr := range templates { 28 var err error 29 *ptr, err = t.Process(*ptr, nil) 30 if err != nil { 31 errs = append( 32 errs, fmt.Errorf("Error processing %s: %s", n, err)) 33 } 34 } 35 36 if c.ImageName == "" { 37 errs = append(errs, fmt.Errorf("An image_name must be specified")) 38 } 39 40 if len(errs) > 0 { 41 return errs 42 } 43 44 return nil 45 }