github.com/kimor79/packer@v0.8.7-0.20151221212622-d507b18eb4cf/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  	SSHKeyPairName string              `mapstructure:"ssh_keypair_name"`
    15  	SSHInterface   string              `mapstructure:"ssh_interface"`
    16  
    17  	SourceImage      string   `mapstructure:"source_image"`
    18  	Flavor           string   `mapstructure:"flavor"`
    19  	AvailabilityZone string   `mapstructure:"availability_zone"`
    20  	RackconnectWait  bool     `mapstructure:"rackconnect_wait"`
    21  	FloatingIpPool   string   `mapstructure:"floating_ip_pool"`
    22  	FloatingIp       string   `mapstructure:"floating_ip"`
    23  	SecurityGroups   []string `mapstructure:"security_groups"`
    24  	Networks         []string `mapstructure:"networks"`
    25  	UserData         string   `mapstructure:"user_data"`
    26  	UserDataFile     string   `mapstructure:"user_data_file"`
    27  
    28  	ConfigDrive bool `mapstructure:"config_drive"`
    29  
    30  	// Not really used, but here for BC
    31  	OpenstackProvider string `mapstructure:"openstack_provider"`
    32  	UseFloatingIp     bool   `mapstructure:"use_floating_ip"`
    33  }
    34  
    35  func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
    36  	// Defaults
    37  	if c.Comm.SSHUsername == "" {
    38  		c.Comm.SSHUsername = "root"
    39  	}
    40  
    41  	if c.UseFloatingIp && c.FloatingIpPool == "" {
    42  		c.FloatingIpPool = "public"
    43  	}
    44  
    45  	// Validation
    46  	errs := c.Comm.Prepare(ctx)
    47  	if c.SourceImage == "" {
    48  		errs = append(errs, errors.New("A source_image must be specified"))
    49  	}
    50  
    51  	if c.Flavor == "" {
    52  		errs = append(errs, errors.New("A flavor must be specified"))
    53  	}
    54  
    55  	return errs
    56  }