Merge pull request #5002 from pragkent/alicloud-ecs-fix

Fix builder alicloud-ecs
This commit is contained in:
Matthew Hooker 2017-06-12 10:37:29 -07:00 committed by GitHub
commit 6df85f6e97
4 changed files with 31 additions and 9 deletions

View File

@ -211,13 +211,31 @@ func (b *Builder) Cancel() {
} }
func (b *Builder) chooseNetworkType() InstanceNetWork { func (b *Builder) chooseNetworkType() InstanceNetWork {
//Alicloud userdata require vpc network and public key require userdata, so besides user specific vpc network, if b.isVpcNetRequired() {
//choose vpc networks in those cases
if b.config.RunConfig.Comm.SSHPrivateKey != "" || b.config.UserData != "" || b.config.UserDataFile != "" ||
b.config.VpcId != "" || b.config.VSwitchId != "" || b.config.TemporaryKeyPairName != "" {
return VpcNet return VpcNet
} else { } else {
return ClassicNet return ClassicNet
} }
}
func (b *Builder) isVpcNetRequired() bool {
// UserData and KeyPair only works in VPC
return b.isVpcSpecified() || b.isUserDataNeeded() || b.isKeyPairNeeded()
}
func (b *Builder) isVpcSpecified() bool {
return b.config.VpcId != "" || b.config.VSwitchId != ""
}
func (b *Builder) isUserDataNeeded() bool {
// Public key setup requires userdata
if b.config.RunConfig.Comm.SSHPrivateKey != "" {
return true
}
return b.config.UserData != "" || b.config.UserDataFile != ""
}
func (b *Builder) isKeyPairNeeded() bool {
return b.config.SSHKeyPairName != "" || b.config.TemporaryKeyPairName != ""
} }

View File

@ -4,11 +4,11 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"strings"
"github.com/hashicorp/packer/common/uuid" "github.com/hashicorp/packer/common/uuid"
"github.com/hashicorp/packer/helper/communicator" "github.com/hashicorp/packer/helper/communicator"
"github.com/hashicorp/packer/template/interpolate" "github.com/hashicorp/packer/template/interpolate"
"strings"
) )
type RunConfig struct { type RunConfig struct {
@ -30,7 +30,7 @@ type RunConfig struct {
VSwitchName string `mapstructure:"vswitch_id"` VSwitchName string `mapstructure:"vswitch_id"`
InstanceName string `mapstructure:"instance_name"` InstanceName string `mapstructure:"instance_name"`
InternetChargeType string `mapstructure:"internet_charge_type"` InternetChargeType string `mapstructure:"internet_charge_type"`
InternetMaxBandwidthOut int `mapstructure:"internet_max_bandwith_out"` InternetMaxBandwidthOut int `mapstructure:"internet_max_bandwidth_out"`
TemporaryKeyPairName string `mapstructure:"temporary_key_pair_name"` TemporaryKeyPairName string `mapstructure:"temporary_key_pair_name"`
// Communicator settings // Communicator settings

View File

@ -49,6 +49,7 @@ func SSHConfig(useAgent bool, username, password string) func(multistep.StateBag
Auth: []ssh.AuthMethod{ Auth: []ssh.AuthMethod{
ssh.PublicKeysCallback(agent.NewClient(sshAgent).Signers), ssh.PublicKeysCallback(agent.NewClient(sshAgent).Signers),
}, },
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}, nil }, nil
} }
@ -64,6 +65,7 @@ func SSHConfig(useAgent bool, username, password string) func(multistep.StateBag
Auth: []ssh.AuthMethod{ Auth: []ssh.AuthMethod{
ssh.PublicKeys(signer), ssh.PublicKeys(signer),
}, },
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}, nil }, nil
} else { } else {
@ -73,7 +75,9 @@ func SSHConfig(useAgent bool, username, password string) func(multistep.StateBag
ssh.Password(password), ssh.Password(password),
ssh.KeyboardInteractive( ssh.KeyboardInteractive(
packerssh.PasswordKeyboardInteractive(password)), packerssh.PasswordKeyboardInteractive(password)),
}}, nil },
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}, nil
} }
} }
} }

View File

@ -173,7 +173,7 @@ builder.
If this parameter is not specified, the default value is `PayByBandwidth`. If this parameter is not specified, the default value is `PayByBandwidth`.
- `internet_max_bandwith_out` (string) - Maximum outgoing bandwidth to the public - `internet_max_bandwidth_out` (string) - Maximum outgoing bandwidth to the public
network, measured in Mbps (Mega bit per second). network, measured in Mbps (Mega bit per second).
Value range: Value range: