github.com/HashDataInc/packer@v1.3.2/packer/plugin/provisioner.go (about)

     1  package plugin
     2  
     3  import (
     4  	"log"
     5  
     6  	"github.com/hashicorp/packer/packer"
     7  )
     8  
     9  type cmdProvisioner struct {
    10  	p      packer.Provisioner
    11  	client *Client
    12  }
    13  
    14  func (c *cmdProvisioner) Prepare(configs ...interface{}) error {
    15  	defer func() {
    16  		r := recover()
    17  		c.checkExit(r, nil)
    18  	}()
    19  
    20  	return c.p.Prepare(configs...)
    21  }
    22  
    23  func (c *cmdProvisioner) Provision(ui packer.Ui, comm packer.Communicator) error {
    24  	defer func() {
    25  		r := recover()
    26  		c.checkExit(r, nil)
    27  	}()
    28  
    29  	return c.p.Provision(ui, comm)
    30  }
    31  
    32  func (c *cmdProvisioner) Cancel() {
    33  	defer func() {
    34  		r := recover()
    35  		c.checkExit(r, nil)
    36  	}()
    37  
    38  	c.p.Cancel()
    39  }
    40  
    41  func (c *cmdProvisioner) checkExit(p interface{}, cb func()) {
    42  	if c.client.Exited() && cb != nil {
    43  		cb()
    44  	} else if p != nil && !Killed {
    45  		log.Panic(p)
    46  	}
    47  }