2013-05-24 00:37:16 -04:00
|
|
|
package plugin
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
type cmdProvisioner struct {
|
2013-05-24 00:59:03 -04:00
|
|
|
p packer.Provisioner
|
2013-06-11 14:03:36 -04:00
|
|
|
client *Client
|
2013-05-24 00:37:16 -04:00
|
|
|
}
|
|
|
|
|
2013-06-06 20:07:42 -04:00
|
|
|
func (c *cmdProvisioner) Prepare(configs ...interface{}) error {
|
2013-05-24 00:37:16 -04:00
|
|
|
defer func() {
|
|
|
|
r := recover()
|
|
|
|
c.checkExit(r, nil)
|
|
|
|
}()
|
|
|
|
|
2013-06-06 20:07:42 -04:00
|
|
|
return c.p.Prepare(configs...)
|
2013-05-24 00:37:16 -04:00
|
|
|
}
|
|
|
|
|
2013-06-26 20:50:25 -04:00
|
|
|
func (c *cmdProvisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
|
2013-05-24 00:37:16 -04:00
|
|
|
defer func() {
|
|
|
|
r := recover()
|
|
|
|
c.checkExit(r, nil)
|
|
|
|
}()
|
|
|
|
|
2013-06-26 20:50:25 -04:00
|
|
|
return c.p.Provision(ui, comm)
|
2013-05-24 00:37:16 -04:00
|
|
|
}
|
|
|
|
|
2013-08-31 02:21:15 -04:00
|
|
|
func (c *cmdProvisioner) Cancel() {
|
|
|
|
defer func() {
|
|
|
|
r := recover()
|
|
|
|
c.checkExit(r, nil)
|
|
|
|
}()
|
|
|
|
|
|
|
|
c.p.Cancel()
|
|
|
|
}
|
|
|
|
|
2013-05-24 00:37:16 -04:00
|
|
|
func (c *cmdProvisioner) checkExit(p interface{}, cb func()) {
|
2013-08-28 14:21:02 -04:00
|
|
|
if c.client.Exited() && cb != nil {
|
2013-05-24 00:37:16 -04:00
|
|
|
cb()
|
2013-08-20 02:38:22 -04:00
|
|
|
} else if p != nil && !Killed {
|
2013-05-24 00:37:16 -04:00
|
|
|
log.Panic(p)
|
|
|
|
}
|
|
|
|
}
|