github.com/emate/packer@v0.8.1-0.20150625195101-fe0fde195dc6/builder/openstack/run_config.go (about)

     1  package openstack
     2  
     3  import (
     4  	"errors"
     5  
     6  	"github.com/mitchellh/packer/helper/communicator"
     7  	"github.com/mitchellh/packer/template/interpolate"
     8  )
     9  
    10  // RunConfig contains configuration for running an instance from a source
    11  // image and details on how to access that launched image.
    12  type RunConfig struct {
    13  	Comm         communicator.Config `mapstructure:",squash"`
    14  	SSHInterface string              `mapstructure:"ssh_interface"`
    15  
    16  	SourceImage      string   `mapstructure:"source_image"`
    17  	Flavor           string   `mapstructure:"flavor"`
    18  	AvailabilityZone string   `mapstructure:"availability_zone"`
    19  	RackconnectWait  bool     `mapstructure:"rackconnect_wait"`
    20  	FloatingIpPool   string   `mapstructure:"floating_ip_pool"`
    21  	FloatingIp       string   `mapstructure:"floating_ip"`
    22  	SecurityGroups   []string `mapstructure:"security_groups"`
    23  	Networks         []string `mapstructure:"networks"`
    24  	UserData         string   `mapstructure:"user_data"`
    25  	UserDataFile     string   `mapstructure:"user_data_file"`
    26  
    27  	// Not really used, but here for BC
    28  	OpenstackProvider string `mapstructure:"openstack_provider"`
    29  	UseFloatingIp     bool   `mapstructure:"use_floating_ip"`
    30  }
    31  
    32  func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
    33  	// Defaults
    34  	if c.Comm.SSHUsername == "" {
    35  		c.Comm.SSHUsername = "root"
    36  	}
    37  
    38  	if c.UseFloatingIp && c.FloatingIpPool == "" {
    39  		c.FloatingIpPool = "public"
    40  	}
    41  
    42  	// Validation
    43  	errs := c.Comm.Prepare(ctx)
    44  	if c.SourceImage == "" {
    45  		errs = append(errs, errors.New("A source_image must be specified"))
    46  	}
    47  
    48  	if c.Flavor == "" {
    49  		errs = append(errs, errors.New("A flavor must be specified"))
    50  	}
    51  
    52  	return errs
    53  }