2017-02-13 05:35:14 -05:00
|
|
|
// Copyright (c) 2017 Oracle America, Inc.
|
|
|
|
// The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
// 2.0 (the "License"); you may not use this file except in compliance with the
|
|
|
|
// License. If a copy of the MPL was not distributed with this file, You can
|
|
|
|
// obtain one at http://mozilla.org/MPL/2.0/
|
|
|
|
|
|
|
|
package bmcs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2017-04-07 06:20:33 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2017-02-13 05:35:14 -05:00
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
)
|
|
|
|
|
|
|
|
type stepInstanceInfo struct{}
|
|
|
|
|
|
|
|
func (s *stepInstanceInfo) Run(state multistep.StateBag) multistep.StepAction {
|
|
|
|
var (
|
|
|
|
driver = state.Get("driver").(Driver)
|
|
|
|
ui = state.Get("ui").(packer.Ui)
|
|
|
|
id = state.Get("instance_id").(string)
|
|
|
|
)
|
|
|
|
|
|
|
|
ip, err := driver.GetInstanceIP(id)
|
|
|
|
if err != nil {
|
2017-08-02 06:53:14 -04:00
|
|
|
err = fmt.Errorf("Error getting instance's public IP: %s", err)
|
|
|
|
ui.Error(err.Error())
|
|
|
|
state.Put("error", err)
|
2017-02-13 05:35:14 -05:00
|
|
|
return multistep.ActionHalt
|
|
|
|
}
|
|
|
|
|
|
|
|
state.Put("instance_ip", ip)
|
|
|
|
|
|
|
|
ui.Say(fmt.Sprintf("Instance has public IP: %s.", ip))
|
|
|
|
|
|
|
|
return multistep.ActionContinue
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *stepInstanceInfo) Cleanup(state multistep.StateBag) {
|
|
|
|
// no cleanup
|
|
|
|
}
|