2014-04-06 13:21:22 -04:00
|
|
|
package pvm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
2015-06-13 18:43:27 -04:00
|
|
|
"log"
|
|
|
|
|
2014-04-06 13:21:22 -04:00
|
|
|
"github.com/mitchellh/multistep"
|
|
|
|
parallelscommon "github.com/mitchellh/packer/builder/parallels/common"
|
|
|
|
"github.com/mitchellh/packer/common"
|
2015-06-13 18:43:27 -04:00
|
|
|
"github.com/mitchellh/packer/helper/communicator"
|
2014-04-06 13:21:22 -04:00
|
|
|
"github.com/mitchellh/packer/packer"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Builder implements packer.Builder and builds the actual Parallels
|
|
|
|
// images.
|
|
|
|
type Builder struct {
|
|
|
|
config *Config
|
|
|
|
runner multistep.Runner
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare processes the build configuration parameters.
|
|
|
|
func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
|
|
|
|
c, warnings, errs := NewConfig(raws...)
|
|
|
|
if errs != nil {
|
|
|
|
return warnings, errs
|
|
|
|
}
|
|
|
|
b.config = c
|
|
|
|
|
|
|
|
return warnings, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Run executes a Packer build and returns a packer.Artifact representing
|
|
|
|
// a Parallels appliance.
|
|
|
|
func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packer.Artifact, error) {
|
|
|
|
// Create the driver that we'll use to communicate with Parallels
|
|
|
|
driver, err := parallelscommon.NewDriver()
|
|
|
|
if err != nil {
|
2017-03-28 20:45:01 -04:00
|
|
|
return nil, fmt.Errorf("Failed creating Parallels driver: %s", err)
|
2014-04-06 13:21:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set up the state.
|
|
|
|
state := new(multistep.BasicStateBag)
|
|
|
|
state.Put("config", b.config)
|
2016-05-17 17:10:10 -04:00
|
|
|
state.Put("debug", b.config.PackerDebug)
|
2014-04-06 13:21:22 -04:00
|
|
|
state.Put("driver", driver)
|
|
|
|
state.Put("hook", hook)
|
|
|
|
state.Put("ui", ui)
|
2014-05-13 17:39:00 -04:00
|
|
|
state.Put("http_port", uint(0))
|
2014-04-06 13:21:22 -04:00
|
|
|
|
|
|
|
// Build the steps.
|
|
|
|
steps := []multistep.Step{
|
2014-09-02 04:42:12 -04:00
|
|
|
¶llelscommon.StepPrepareParallelsTools{
|
|
|
|
ParallelsToolsMode: b.config.ParallelsToolsMode,
|
|
|
|
ParallelsToolsFlavor: b.config.ParallelsToolsFlavor,
|
|
|
|
},
|
2014-04-06 13:21:22 -04:00
|
|
|
¶llelscommon.StepOutputDir{
|
|
|
|
Force: b.config.PackerForce,
|
|
|
|
Path: b.config.OutputDir,
|
|
|
|
},
|
|
|
|
&common.StepCreateFloppy{
|
2016-10-11 17:43:50 -04:00
|
|
|
Files: b.config.FloppyConfig.FloppyFiles,
|
2016-09-28 00:31:42 -04:00
|
|
|
Directories: b.config.FloppyConfig.FloppyDirectories,
|
2014-04-06 13:21:22 -04:00
|
|
|
},
|
|
|
|
&StepImport{
|
|
|
|
Name: b.config.VMName,
|
|
|
|
SourcePath: b.config.SourcePath,
|
|
|
|
},
|
|
|
|
¶llelscommon.StepAttachParallelsTools{
|
2014-09-02 05:28:04 -04:00
|
|
|
ParallelsToolsMode: b.config.ParallelsToolsMode,
|
2014-04-06 13:21:22 -04:00
|
|
|
},
|
|
|
|
new(parallelscommon.StepAttachFloppy),
|
|
|
|
¶llelscommon.StepPrlctl{
|
|
|
|
Commands: b.config.Prlctl,
|
2015-05-27 16:51:24 -04:00
|
|
|
Ctx: b.config.ctx,
|
2014-04-06 13:21:22 -04:00
|
|
|
},
|
|
|
|
¶llelscommon.StepRun{
|
|
|
|
BootWait: b.config.BootWait,
|
|
|
|
},
|
2014-05-13 17:39:00 -04:00
|
|
|
¶llelscommon.StepTypeBootCommand{
|
|
|
|
BootCommand: b.config.BootCommand,
|
|
|
|
HostInterfaces: []string{},
|
|
|
|
VMName: b.config.VMName,
|
2015-05-27 16:51:24 -04:00
|
|
|
Ctx: b.config.ctx,
|
2014-05-13 17:39:00 -04:00
|
|
|
},
|
2015-06-13 18:43:27 -04:00
|
|
|
&communicator.StepConnect{
|
2015-06-13 19:23:33 -04:00
|
|
|
Config: &b.config.SSHConfig.Comm,
|
|
|
|
Host: parallelscommon.CommHost,
|
|
|
|
SSHConfig: parallelscommon.SSHConfigFunc(b.config.SSHConfig),
|
2014-04-06 13:21:22 -04:00
|
|
|
},
|
|
|
|
¶llelscommon.StepUploadVersion{
|
|
|
|
Path: b.config.PrlctlVersionFile,
|
|
|
|
},
|
|
|
|
¶llelscommon.StepUploadParallelsTools{
|
2014-09-02 05:28:04 -04:00
|
|
|
ParallelsToolsFlavor: b.config.ParallelsToolsFlavor,
|
2014-04-06 13:21:22 -04:00
|
|
|
ParallelsToolsGuestPath: b.config.ParallelsToolsGuestPath,
|
|
|
|
ParallelsToolsMode: b.config.ParallelsToolsMode,
|
2015-05-27 16:51:24 -04:00
|
|
|
Ctx: b.config.ctx,
|
2014-04-06 13:21:22 -04:00
|
|
|
},
|
|
|
|
new(common.StepProvision),
|
|
|
|
¶llelscommon.StepShutdown{
|
|
|
|
Command: b.config.ShutdownCommand,
|
|
|
|
Timeout: b.config.ShutdownTimeout,
|
|
|
|
},
|
2015-05-03 05:18:48 -04:00
|
|
|
¶llelscommon.StepPrlctl{
|
|
|
|
Commands: b.config.PrlctlPost,
|
2015-06-22 15:46:13 -04:00
|
|
|
Ctx: b.config.ctx,
|
2015-05-03 05:18:48 -04:00
|
|
|
},
|
2014-04-06 13:21:22 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Run the steps.
|
2016-09-13 20:04:18 -04:00
|
|
|
b.runner = common.NewRunnerWithPauseFn(steps, b.config.PackerConfig, ui, state)
|
2014-04-06 13:21:22 -04:00
|
|
|
b.runner.Run(state)
|
|
|
|
|
|
|
|
// Report any errors.
|
|
|
|
if rawErr, ok := state.GetOk("error"); ok {
|
|
|
|
return nil, rawErr.(error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we were interrupted or cancelled, then just exit.
|
|
|
|
if _, ok := state.GetOk(multistep.StateCancelled); ok {
|
|
|
|
return nil, errors.New("Build was cancelled.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, ok := state.GetOk(multistep.StateHalted); ok {
|
|
|
|
return nil, errors.New("Build was halted.")
|
|
|
|
}
|
|
|
|
|
|
|
|
return parallelscommon.NewArtifact(b.config.OutputDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cancel.
|
|
|
|
func (b *Builder) Cancel() {
|
|
|
|
if b.runner != nil {
|
|
|
|
log.Println("Cancelling the step runner...")
|
|
|
|
b.runner.Cancel()
|
|
|
|
}
|
|
|
|
}
|