2013-08-27 00:57:23 -04:00
|
|
|
package openstack
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
"time"
|
2015-05-27 16:02:57 -04:00
|
|
|
|
|
|
|
"github.com/mitchellh/packer/template/interpolate"
|
2013-08-27 00:57:23 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// RunConfig contains configuration for running an instance from a source
|
|
|
|
// image and details on how to access that launched image.
|
|
|
|
type RunConfig struct {
|
2015-06-12 11:10:10 -04:00
|
|
|
SourceImage string `mapstructure:"source_image"`
|
|
|
|
Flavor string `mapstructure:"flavor"`
|
|
|
|
RawSSHTimeout string `mapstructure:"ssh_timeout"`
|
|
|
|
SSHUsername string `mapstructure:"ssh_username"`
|
|
|
|
SSHPort int `mapstructure:"ssh_port"`
|
|
|
|
SSHInterface string `mapstructure:"ssh_interface"`
|
|
|
|
AvailabilityZone string `mapstructure:"availability_zone"`
|
|
|
|
RackconnectWait bool `mapstructure:"rackconnect_wait"`
|
|
|
|
FloatingIpPool string `mapstructure:"floating_ip_pool"`
|
|
|
|
FloatingIp string `mapstructure:"floating_ip"`
|
|
|
|
SecurityGroups []string `mapstructure:"security_groups"`
|
|
|
|
Networks []string `mapstructure:"networks"`
|
2015-06-12 10:05:03 -04:00
|
|
|
|
|
|
|
// Not really used, but here for BC
|
|
|
|
OpenstackProvider string `mapstructure:"openstack_provider"`
|
|
|
|
UseFloatingIp bool `mapstructure:"use_floating_ip"`
|
2013-08-27 00:57:23 -04:00
|
|
|
|
|
|
|
// Unexported fields that are calculated from others
|
|
|
|
sshTimeout time.Duration
|
|
|
|
}
|
|
|
|
|
2015-05-27 16:02:57 -04:00
|
|
|
func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
|
2013-08-27 00:57:23 -04:00
|
|
|
// Defaults
|
|
|
|
if c.SSHUsername == "" {
|
|
|
|
c.SSHUsername = "root"
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.SSHPort == 0 {
|
|
|
|
c.SSHPort = 22
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.RawSSHTimeout == "" {
|
2013-09-01 17:36:59 -04:00
|
|
|
c.RawSSHTimeout = "5m"
|
2013-08-27 00:57:23 -04:00
|
|
|
}
|
|
|
|
|
2014-02-27 03:34:24 -05:00
|
|
|
if c.UseFloatingIp && c.FloatingIpPool == "" {
|
|
|
|
c.FloatingIpPool = "public"
|
|
|
|
}
|
|
|
|
|
2013-08-27 00:57:23 -04:00
|
|
|
// Validation
|
|
|
|
var err error
|
|
|
|
errs := make([]error, 0)
|
|
|
|
if c.SourceImage == "" {
|
|
|
|
errs = append(errs, errors.New("A source_image must be specified"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.Flavor == "" {
|
|
|
|
errs = append(errs, errors.New("A flavor must be specified"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.SSHUsername == "" {
|
|
|
|
errs = append(errs, errors.New("An ssh_username must be specified"))
|
|
|
|
}
|
|
|
|
|
|
|
|
c.sshTimeout, err = time.ParseDuration(c.RawSSHTimeout)
|
|
|
|
if err != nil {
|
|
|
|
errs = append(errs, fmt.Errorf("Failed parsing ssh_timeout: %s", err))
|
|
|
|
}
|
|
|
|
|
|
|
|
return errs
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *RunConfig) SSHTimeout() time.Duration {
|
|
|
|
return c.sshTimeout
|
|
|
|
}
|