builder/virtualbox: treat guest_additions_path as a template
This commit is contained in:
parent
a599074185
commit
27c9e8cf92
|
@ -1,30 +1,50 @@
|
||||||
package virtualbox
|
package virtualbox
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/mitchellh/multistep"
|
"github.com/mitchellh/multistep"
|
||||||
"github.com/mitchellh/packer/packer"
|
"github.com/mitchellh/packer/packer"
|
||||||
"os"
|
"os"
|
||||||
|
"text/template"
|
||||||
)
|
)
|
||||||
|
|
||||||
// This step uploads a file containing the VirtualBox version, which
|
type guestAdditionsPathTemplate struct {
|
||||||
// can be useful for various provisioning reasons.
|
Version string
|
||||||
|
}
|
||||||
|
|
||||||
|
// This step uploads the guest additions ISO to the VM.
|
||||||
type stepUploadGuestAdditions struct{}
|
type stepUploadGuestAdditions struct{}
|
||||||
|
|
||||||
func (s *stepUploadGuestAdditions) Run(state map[string]interface{}) multistep.StepAction {
|
func (s *stepUploadGuestAdditions) Run(state map[string]interface{}) multistep.StepAction {
|
||||||
comm := state["communicator"].(packer.Communicator)
|
comm := state["communicator"].(packer.Communicator)
|
||||||
config := state["config"].(*config)
|
config := state["config"].(*config)
|
||||||
|
driver := state["driver"].(Driver)
|
||||||
guestAdditionsPath := state["guest_additions_path"].(string)
|
guestAdditionsPath := state["guest_additions_path"].(string)
|
||||||
ui := state["ui"].(packer.Ui)
|
ui := state["ui"].(packer.Ui)
|
||||||
|
|
||||||
|
version, err := driver.Version()
|
||||||
|
if err != nil {
|
||||||
|
state["error"] = fmt.Errorf("Error reading version for guest additions upload: %s", err)
|
||||||
|
return multistep.ActionHalt
|
||||||
|
}
|
||||||
|
|
||||||
f, err := os.Open(guestAdditionsPath)
|
f, err := os.Open(guestAdditionsPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
state["error"] = fmt.Errorf("Error opening guest additions ISO: %s", err)
|
state["error"] = fmt.Errorf("Error opening guest additions ISO: %s", err)
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tplData := &guestAdditionsPathTemplate{
|
||||||
|
Version: version,
|
||||||
|
}
|
||||||
|
|
||||||
|
var processedPath bytes.Buffer
|
||||||
|
t := template.Must(template.New("path").Parse(config.GuestAdditionsPath))
|
||||||
|
t.Execute(&processedPath, tplData)
|
||||||
|
|
||||||
ui.Say("Upload VirtualBox guest additions ISO...")
|
ui.Say("Upload VirtualBox guest additions ISO...")
|
||||||
if err := comm.Upload(config.GuestAdditionsPath, f); err != nil {
|
if err := comm.Upload(processedPath.String(), f); err != nil {
|
||||||
state["error"] = fmt.Errorf("Error uploading guest additions: %s", err)
|
state["error"] = fmt.Errorf("Error uploading guest additions: %s", err)
|
||||||
return multistep.ActionHalt
|
return multistep.ActionHalt
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue