packer-cn/packer/plugin/provisioner.go

40 lines
742 B
Go
Raw Normal View History

2013-05-24 00:37:16 -04:00
package plugin
import (
"context"
2013-05-24 00:37:16 -04:00
"log"
2018-01-22 20:21:10 -05:00
"github.com/hashicorp/packer/packer"
2013-05-24 00:37:16 -04:00
)
type cmdProvisioner struct {
2013-05-24 00:59:03 -04:00
p packer.Provisioner
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
}
func (c *cmdProvisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, generatedData *packer.ProvisionHookData) error {
2013-05-24 00:37:16 -04:00
defer func() {
r := recover()
c.checkExit(r, nil)
}()
return c.p.Provision(ctx, ui, comm, generatedData)
}
2013-05-24 00:37:16 -04:00
func (c *cmdProvisioner) checkExit(p interface{}, cb func()) {
if c.client.Exited() && cb != nil {
2013-05-24 00:37:16 -04:00
cb()
} else if p != nil && !Killed {
2013-05-24 00:37:16 -04:00
log.Panic(p)
}
}