Fix to get ssh password

This commit is contained in:
유성덕 2018-12-21 17:53:52 +09:00
parent 8b99260040
commit 38c4e21563
4 changed files with 17 additions and 9 deletions

View File

@ -44,7 +44,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
NewStepCreateLoginKey(conn, ui),
NewStepCreateServerInstance(conn, ui, b.config),
NewStepCreateBlockStorageInstance(conn, ui, b.config),
NewStepGetRootPassword(conn, ui),
NewStepGetRootPassword(conn, ui, b.config),
NewStepCreatePublicIPInstance(conn, ui, b.config),
&communicator.StepConnectSSH{
Config: &b.config.Comm,
@ -68,7 +68,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
NewStepCreateLoginKey(conn, ui),
NewStepCreateServerInstance(conn, ui, b.config),
NewStepCreateBlockStorageInstance(conn, ui, b.config),
NewStepGetRootPassword(conn, ui),
NewStepGetRootPassword(conn, ui, b.config),
NewStepCreatePublicIPInstance(conn, ui, b.config),
&communicator.StepConnectWinRM{
Config: &b.config.Comm,
@ -78,7 +78,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
WinRMConfig: func(state multistep.StateBag) (*communicator.WinRMConfig, error) {
return &communicator.WinRMConfig{
Username: b.config.Comm.WinRMUser,
Password: state.Get("Password").(string),
Password: b.config.Comm.WinRMPassword,
}, nil
},
},

View File

@ -105,7 +105,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
errs = packer.MultiErrorAppend(errs, errors.New("If user_data field is set, length of UserData should be max 21847"))
}
if c.Comm.Type == "wrinrm" && c.AccessControlGroupConfigurationNo == "" {
if c.Comm.Type == "winrm" && c.AccessControlGroupConfigurationNo == "" {
errs = packer.MultiErrorAppend(errs, errors.New("If Communicator is winrm, access_control_group_configuration_no is required"))
}

View File

@ -14,13 +14,15 @@ type StepGetRootPassword struct {
GetRootPassword func(serverInstanceNo string, privateKey string) (string, error)
Say func(message string)
Error func(e error)
Config *Config
}
func NewStepGetRootPassword(conn *ncloud.Conn, ui packer.Ui) *StepGetRootPassword {
func NewStepGetRootPassword(conn *ncloud.Conn, ui packer.Ui, config *Config) *StepGetRootPassword {
var step = &StepGetRootPassword{
Conn: conn,
Say: func(message string) { ui.Say(message) },
Error: func(e error) { ui.Error(e.Error()) },
Conn: conn,
Say: func(message string) { ui.Say(message) },
Error: func(e error) { ui.Error(e.Error()) },
Config: config,
}
step.GetRootPassword = step.getRootPassword
@ -51,7 +53,11 @@ func (s *StepGetRootPassword) Run(_ context.Context, state multistep.StateBag) m
rootPassword, err := s.GetRootPassword(serverInstanceNo, loginKey.PrivateKey)
state.Put("Password", rootPassword)
if s.Config.Comm.Type == "ssh" {
s.Config.Comm.SSHPassword = rootPassword
} else if s.Config.Comm.Type == "winrm" {
s.Config.Comm.WinRMPassword = rootPassword
}
return processStepResult(err, s.Error, state)
}

View File

@ -13,6 +13,7 @@ func TestStepGetRootPasswordShouldFailIfOperationGetRootPasswordFails(t *testing
GetRootPassword: func(string, string) (string, error) { return "", fmt.Errorf("!! Unit Test FAIL !!") },
Say: func(message string) {},
Error: func(e error) {},
Config: &Config{},
}
stateBag := DeleteTestStateBagStepGetRootPassword()
@ -33,6 +34,7 @@ func TestStepGetRootPasswordShouldPassIfOperationGetRootPasswordPasses(t *testin
GetRootPassword: func(string, string) (string, error) { return "a", nil },
Say: func(message string) {},
Error: func(e error) {},
Config: &Config{},
}
stateBag := DeleteTestStateBagStepGetRootPassword()