Add winrm functionality to vmware-iso builder (#3738)
* Use winrm_host, if provided, this allows packer to work in ESXi environments without DHCP. Signed-off-by: Charlie Vieth <cviethjr@pivotal.io>
This commit is contained in:
parent
a7de2d0f7a
commit
d14d62074e
|
@ -61,6 +61,8 @@ type Config struct {
|
|||
RemotePassword string `mapstructure:"remote_password"`
|
||||
RemotePrivateKey string `mapstructure:"remote_private_key_file"`
|
||||
|
||||
CommConfig communicator.Config `mapstructure:",squash"`
|
||||
|
||||
ctx interpolate.Context
|
||||
}
|
||||
|
||||
|
|
|
@ -338,3 +338,61 @@ func TestBuilderPrepare_VNCPort(t *testing.T) {
|
|||
t.Fatalf("should not have error: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBuilderPrepare_CommConfig(t *testing.T) {
|
||||
// Test Winrm
|
||||
{
|
||||
config := testConfig()
|
||||
config["communicator"] = "winrm"
|
||||
config["winrm_username"] = "username"
|
||||
config["winrm_password"] = "password"
|
||||
config["winrm_host"] = "1.2.3.4"
|
||||
|
||||
var b Builder
|
||||
warns, err := b.Prepare(config)
|
||||
if len(warns) > 0 {
|
||||
t.Fatalf("bad: %#v", warns)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("should not have error: %s", err)
|
||||
}
|
||||
|
||||
if b.config.CommConfig.WinRMUser != "username" {
|
||||
t.Errorf("bad winrm_username: %s", b.config.CommConfig.WinRMUser)
|
||||
}
|
||||
if b.config.CommConfig.WinRMPassword != "password" {
|
||||
t.Errorf("bad winrm_password: %s", b.config.CommConfig.WinRMPassword)
|
||||
}
|
||||
if host := b.config.CommConfig.Host(); host != "1.2.3.4" {
|
||||
t.Errorf("bad host: %s", host)
|
||||
}
|
||||
}
|
||||
|
||||
// Test SSH
|
||||
{
|
||||
config := testConfig()
|
||||
config["communicator"] = "ssh"
|
||||
config["ssh_username"] = "username"
|
||||
config["ssh_password"] = "password"
|
||||
config["ssh_host"] = "1.2.3.4"
|
||||
|
||||
var b Builder
|
||||
warns, err := b.Prepare(config)
|
||||
if len(warns) > 0 {
|
||||
t.Fatalf("bad: %#v", warns)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("should not have error: %s", err)
|
||||
}
|
||||
|
||||
if b.config.CommConfig.SSHUsername != "username" {
|
||||
t.Errorf("bad ssh_username: %s", b.config.CommConfig.SSHUsername)
|
||||
}
|
||||
if b.config.CommConfig.SSHPassword != "password" {
|
||||
t.Errorf("bad ssh_password: %s", b.config.CommConfig.SSHPassword)
|
||||
}
|
||||
if host := b.config.CommConfig.Host(); host != "1.2.3.4" {
|
||||
t.Errorf("bad host: %s", host)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -239,6 +239,11 @@ func (d *ESX5Driver) CommHost(state multistep.StateBag) (string, error) {
|
|||
return address.(string), nil
|
||||
}
|
||||
|
||||
if address := config.CommConfig.Host(); address != "" {
|
||||
state.Put("vm_address", address)
|
||||
return address, nil
|
||||
}
|
||||
|
||||
r, err := d.esxcli("network", "vm", "list")
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
|
@ -2,9 +2,11 @@ package iso
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
vmwcommon "github.com/mitchellh/packer/builder/vmware/common"
|
||||
"net"
|
||||
"testing"
|
||||
|
||||
"github.com/mitchellh/multistep"
|
||||
vmwcommon "github.com/mitchellh/packer/builder/vmware/common"
|
||||
)
|
||||
|
||||
func TestESX5Driver_implDriver(t *testing.T) {
|
||||
|
@ -33,3 +35,44 @@ func TestESX5Driver_HostIP(t *testing.T) {
|
|||
t.Error(fmt.Sprintf("Expected string, %s but got %s", expected_host, host))
|
||||
}
|
||||
}
|
||||
|
||||
func TestESX5Driver_CommHost(t *testing.T) {
|
||||
const expected_host = "127.0.0.1"
|
||||
|
||||
config := testConfig()
|
||||
config["communicator"] = "winrm"
|
||||
config["winrm_username"] = "username"
|
||||
config["winrm_password"] = "password"
|
||||
config["winrm_host"] = expected_host
|
||||
|
||||
var b Builder
|
||||
warns, err := b.Prepare(config)
|
||||
if len(warns) > 0 {
|
||||
t.Fatalf("bad: %#v", warns)
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("should not have error: %s", err)
|
||||
}
|
||||
if host := b.config.CommConfig.Host(); host != expected_host {
|
||||
t.Fatalf("setup failed, bad host name: %s", host)
|
||||
}
|
||||
|
||||
state := new(multistep.BasicStateBag)
|
||||
state.Put("config", &b.config)
|
||||
|
||||
var driver ESX5Driver
|
||||
host, err := driver.CommHost(state)
|
||||
if err != nil {
|
||||
t.Fatalf("should not have error: %s", err)
|
||||
}
|
||||
if host != expected_host {
|
||||
t.Errorf("bad host name: %s", host)
|
||||
}
|
||||
address, ok := state.GetOk("vm_address")
|
||||
if !ok {
|
||||
t.Error("state not updated with vm_address")
|
||||
}
|
||||
if address.(string) != expected_host {
|
||||
t.Errorf("bad vm_address: %s", address.(string))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue