2017-02-02 02:13:23 -06:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-09-13 03:21:07 -05:00
|
|
|
|
2017-02-02 02:13:23 -06:00
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
)
|
|
|
|
|
|
|
|
type StepSetVmHostSshAddress struct{}
|
|
|
|
|
|
|
|
func (self *StepSetVmHostSshAddress) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
|
2020-09-13 03:21:07 -05:00
|
|
|
c := state.Get("client").(*Connection)
|
2017-02-02 02:13:23 -06:00
|
|
|
ui := state.Get("ui").(packer.Ui)
|
|
|
|
|
|
|
|
ui.Say("Step: Set SSH address to VM host IP")
|
|
|
|
|
|
|
|
uuid := state.Get("instance_uuid").(string)
|
2020-09-13 03:21:07 -05:00
|
|
|
instance, err := c.client.VM.GetByUUID(c.session, uuid)
|
2017-02-02 02:13:23 -06:00
|
|
|
if err != nil {
|
|
|
|
ui.Error(fmt.Sprintf("Unable to get VM from UUID '%s': %s", uuid, err.Error()))
|
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
2020-09-13 03:21:07 -05:00
|
|
|
host, err := c.client.VM.GetResidentOn(c.session, instance)
|
2017-02-02 02:13:23 -06:00
|
|
|
if err != nil {
|
|
|
|
ui.Error(fmt.Sprintf("Unable to get VM Host for VM '%s': %s", uuid, err.Error()))
|
|
|
|
}
|
|
|
|
|
2020-09-13 03:21:07 -05:00
|
|
|
address, err := c.client.Host.GetAddress(c.session, host)
|
2017-02-02 02:13:23 -06:00
|
|
|
if err != nil {
|
|
|
|
ui.Error(fmt.Sprintf("Unable to get address from VM Host: %s", err.Error()))
|
|
|
|
}
|
|
|
|
|
|
|
|
state.Put("ssh_address", address)
|
|
|
|
ui.Say(fmt.Sprintf("Set host SSH address to '%s'.", address))
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (self *StepSetVmHostSshAddress) Cleanup(state multistep.StateBag) {}
|