github.com/rothwerx/packer@v0.9.0/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  	SSHIPVersion   string              `mapstructure:"ssh_ip_version"`
    17  
    18  	SourceImage      string   `mapstructure:"source_image"`
    19  	SourceImageName  string   `mapstructure:"source_image_name"`
    20  	Flavor           string   `mapstructure:"flavor"`
    21  	AvailabilityZone string   `mapstructure:"availability_zone"`
    22  	RackconnectWait  bool     `mapstructure:"rackconnect_wait"`
    23  	FloatingIpPool   string   `mapstructure:"floating_ip_pool"`
    24  	FloatingIp       string   `mapstructure:"floating_ip"`
    25  	SecurityGroups   []string `mapstructure:"security_groups"`
    26  	Networks         []string `mapstructure:"networks"`
    27  	UserData         string   `mapstructure:"user_data"`
    28  	UserDataFile     string   `mapstructure:"user_data_file"`
    29  
    30  	ConfigDrive bool `mapstructure:"config_drive"`
    31  
    32  	// Not really used, but here for BC
    33  	OpenstackProvider string `mapstructure:"openstack_provider"`
    34  	UseFloatingIp     bool   `mapstructure:"use_floating_ip"`
    35  }
    36  
    37  func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
    38  	// Defaults
    39  	if c.Comm.SSHUsername == "" {
    40  		c.Comm.SSHUsername = "root"
    41  	}
    42  
    43  	if c.UseFloatingIp && c.FloatingIpPool == "" {
    44  		c.FloatingIpPool = "public"
    45  	}
    46  
    47  	// Validation
    48  	errs := c.Comm.Prepare(ctx)
    49  	if c.SourceImage == "" && c.SourceImageName == "" {
    50  		errs = append(errs, errors.New("Either a source_image or a source_image_name must be specified"))
    51  	} else if len(c.SourceImage) > 0 && len(c.SourceImageName) > 0 {
    52  		errs = append(errs, errors.New("Only a source_image or a source_image_name can be specified, not both."))
    53  	}
    54  
    55  	if c.Flavor == "" {
    56  		errs = append(errs, errors.New("A flavor must be specified"))
    57  	}
    58  
    59  	if c.SSHIPVersion != "" && c.SSHIPVersion != "4" && c.SSHIPVersion != "6" {
    60  		errs = append(errs, errors.New("SSH IP version must be either 4 or 6"))
    61  	}
    62  
    63  	return errs
    64  }