Permalink
Browse files

Crashes

  • Loading branch information...
1 parent 7e3e598 commit 8a4818b70efee4facd417b6d1f746cdcddb26bbc @rickard-von-essen committed Feb 25, 2014
View
@@ -1,12 +1,9 @@
package common
import (
+ "github.com/rickard-von-essen/goprlapi"
"log"
- //"os"
"os/exec"
- //"path/filepath"
- //"runtime"
- //"strings"
)
// A driver is able to talk to Parallels and perform certain
@@ -44,6 +41,9 @@ type Driver interface {
// Version reads the version of Parallels that is installed.
Version() (string, error)
+
+ // Get Virtual Machine abstraction
+ GetVm(string) (DriverVm, error)
}
func NewDriver() (Driver, error) {
@@ -57,8 +57,12 @@ func NewDriver() (Driver, error) {
}
}
+ server, err := goprlapi.LoginLocal()
+ if err != nil {
+ return nil, err
+ }
log.Printf("prlctl path: %s", prlctlPath)
- driver := &Parallels9Driver{prlctlPath}
+ driver := &Parallels9Driver{prlctlPath, server}
if err := driver.Verify(); err != nil {
return nil, err
}
View
@@ -3,6 +3,7 @@ package common
import (
"bytes"
"fmt"
+ "github.com/rickard-von-essen/goprlapi"
"log"
"os/exec"
"regexp"
@@ -13,6 +14,7 @@ import (
type Parallels9Driver struct {
// This is the path to the "prlctl" application.
PrlctlPath string
+ server goprlapi.Server
}
func (d *Parallels9Driver) CreateSATAController(vmName string, name string) error {
@@ -141,3 +143,12 @@ func (d *Parallels9Driver) Version() (string, error) {
log.Printf("prlctl version: %s", matches[0])
return matches[0], nil
}
+
+func (d *Parallels9Driver) GetVm(vmName string) (DriverVm, error) {
+ vm, err := d.server.GetVm(vmName)
+ if err != nil {
+ return nil, err
+
+ }
+ return &Parallels9DriverVm{vm}, nil
+}
View
@@ -0,0 +1,21 @@
+package common
+
+import (
+ "github.com/rickard-von-essen/goprlapi"
+)
+
+type Parallels9DriverVm struct {
+ vm goprlapi.VirtualMachine
+}
+
+func (v *Parallels9DriverVm) DisplayConnect() error {
+ return v.vm.DisplayConnect()
+}
+
+func (v *Parallels9DriverVm) DisplayDisconnect() {
+ v.vm.DisplayDisconnect()
+}
+
+func (v *Parallels9DriverVm) SendKeyScanCode(scancode uint32) error {
+ return v.vm.SendKeyScanCode(scancode, 0)
+}
View
@@ -0,0 +1,18 @@
+package common
+
+// A driver is able to talk to Parallels and perform certain
+// operations with it. Some of the operations on here may seem overly
+// specific, but they were built specifically in mind to handle features
+// of the Parallels builder for Packer, and to abstract differences in
+// versions out of the builder steps, so sometimes the methods are
+// extremely specific.
+type DriverVm interface {
+ // Connect to the VM console. Should be done before sending key events.
+ DisplayConnect() error
+
+ // Disconnect from the VM console
+ DisplayDisconnect()
+
+ // Send a key scan codes via the Parallels Virtualization SDK C API
+ SendKeyScanCode(uint32) error
+}
View
@@ -16,7 +16,6 @@ import (
// Produces:
// exportPath string - The path to the resulting export.
type StepExport struct {
- Format string
OutputDir string
}
@@ -31,7 +30,7 @@ func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction {
// Clear out the Packer-created forwarding rule
ui.Say("Preparing to export machine...")
- ui.Message(fmt.Sprintf(
+ /*ui.Message(fmt.Sprintf(
"Deleting forwarded port mapping for SSH (host port %d)",
state.Get("sshHostPort")))
command := []string{"modifyvm", vmName, "--natpf1", "delete", "packerssh"}
@@ -41,21 +40,19 @@ func (s *StepExport) Run(state multistep.StateBag) multistep.StepAction {
ui.Error(err.Error())
return multistep.ActionHalt
}
+ */
- // Export the VM to an OVF
- outputPath := filepath.Join(s.OutputDir, vmName+"."+s.Format)
+ outputPath := filepath.Join(s.OutputDir, vmName+".pvm")
- command = []string{
- "export",
+ command := []string{
+ "unregister",
vmName,
- "--output",
- outputPath,
}
- ui.Say("Exporting virtual machine...")
+ ui.Say("Unregister virtual machine...")
err := driver.Prlctl(command...)
if err != nil {
- err := fmt.Errorf("Error exporting virtual machine: %s", err)
+ err := fmt.Errorf("Error unregistering virtual machine: %s", err)
state.Put("error", err)
ui.Error(err.Error())
return multistep.ActionHalt
View
@@ -15,8 +15,9 @@ import (
// not exist, deleting it if it does exist and we're forcing, and cleaning
// it up when we're done with it.
type StepOutputDir struct {
- Force bool
- Path string
+ Force bool
+ Path string
+ success bool
}
func (s *StepOutputDir) Run(state multistep.StateBag) multistep.StepAction {
@@ -43,13 +44,18 @@ func (s *StepOutputDir) Run(state multistep.StateBag) multistep.StepAction {
f.Close()
os.Remove(f.Name())
+ s.success = true
return multistep.ActionContinue
}
func (s *StepOutputDir) Cleanup(state multistep.StateBag) {
_, cancelled := state.GetOk(multistep.StateCancelled)
_, halted := state.GetOk(multistep.StateHalted)
+ if !s.success {
+ return
+ }
+
if cancelled || halted {
ui := state.Get("ui").(packer.Ui)
View
@@ -284,24 +284,24 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
new(stepHTTPServer),
new(stepCreateVM),
//new(parallelscommon.StepUseDefaults),
- new(stepCreateDisk),
- new(stepAttachISO),
- new(stepAttachParallelsTools),
- new(parallelscommon.StepAttachFloppy),
+ //new(stepCreateDisk),
+ //new(stepAttachISO),
+ //new(stepAttachParallelsTools),
+ //new(parallelscommon.StepAttachFloppy),
// TODO: This has to be done in a different way for Parallels
//&parallelscommon.StepForwardSSH{
// GuestPort: b.config.SSHPort,
// HostPortMin: b.config.SSHHostPortMin,
// HostPortMax: b.config.SSHHostPortMax,
//},
- &parallelscommon.StepPrlctl{
- Commands: b.config.Prlctl,
- Tpl: b.config.tpl,
- },
- &parallelscommon.StepRun{
+ //&parallelscommon.StepPrlctl{
+ // Commands: b.config.Prlctl,
+ // Tpl: b.config.tpl,
+ //},
+ /*&parallelscommon.StepRun{
BootWait: b.config.BootWait,
Headless: b.config.Headless, // TODO: migth work on Enterprise Ed.
- },
+ },*/
//new(stepTypeBootCommand),
//&common.StepConnectSSH{
// SSHAddress: parallelscommon.SSHAddress,
@@ -313,15 +313,14 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
//},
//new(stepUploadParallelsTools),
//new(common.StepProvision),
- //&parallelscommon.StepShutdown{
- // Command: b.config.ShutdownCommand,
- // Timeout: b.config.ShutdownTimeout,
- //},
+ /*&parallelscommon.StepShutdown{
+ Command: b.config.ShutdownCommand,
+ Timeout: b.config.ShutdownTimeout,
+ },*/
//new(parallelscommon.StepRemoveDevices),
- //&parallelscommon.StepExport{
- // Format: b.config.Format,
- // OutputDir: b.config.OutputDir,
- //},
+ /*&parallelscommon.StepExport{
+ OutputDir: b.config.OutputDir,
+ },*/
}
// Setup the state bag
@@ -358,7 +357,8 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
return nil, errors.New("Build was halted.")
}
- return parallelscommon.NewArtifact(b.config.OutputDir)
+ return parallelscommon.NewArtifact("test-dir")
+ //return parallelscommon.NewArtifact(b.config.OutputDir)
}
func (b *Builder) Cancel() {
View
@@ -17,6 +17,7 @@ type stepCreateVM struct {
}
func (s *stepCreateVM) Run(state multistep.StateBag) multistep.StepAction {
+
config := state.Get("config").(*config)
driver := state.Get("driver").(parallelscommon.Driver)
ui := state.Get("ui").(packer.Ui)
@@ -31,44 +32,52 @@ func (s *stepCreateVM) Run(state multistep.StateBag) multistep.StepAction {
"--distribution", config.GuestOSDistribution,
"--dst", path,
}
- commands[1] = []string{"set", name, "--cpus", "1"}
- commands[2] = []string{"set", name, "--memsize", "512"}
+ //commands[1] = []string{"set", name, "--cpus", "1"}
+ //commands[2] = []string{"set", name, "--memsize", "512"}
ui.Say("Creating virtual machine...")
- for _, command := range commands {
- err := driver.Prlctl(command...)
- if err != nil {
- err := fmt.Errorf("Error creating VM: %s", err)
- state.Put("error", err)
- ui.Error(err.Error())
- return multistep.ActionHalt
- }
-
- // Set the VM name property on the first command
- if s.vmName == "" {
- s.vmName = name
- }
+ err := driver.Prlctl("create", name, "--ostype", config.GuestOSType, "--distribution", config.GuestOSDistribution, "--dst", path)
+ if err != nil {
+ ui.Error(fmt.Errorf("Error creating VM: %s", err).Error())
}
+ ui.Say("Done creating VM!")
+ /* for _, command := range commands {
+ err := driver.Prlctl(command...)
+ ui.Say(fmt.Sprintf("Doing: %s", command))
+ if err != nil {
+ err := fmt.Errorf("Error creating VM: %s", err)
+ state.Put("error", err)
+ ui.Error(err.Error())
+ return multistep.ActionHalt
+ }
+
+ // Set the VM name property on the first command
+ if s.vmName == "" {
+ s.vmName = name
+ }
+ }
+ */
// Set the final name in the state bag so others can use it
state.Put("vmName", s.vmName)
-
return multistep.ActionContinue
}
func (s *stepCreateVM) Cleanup(state multistep.StateBag) {
- if s.vmName == "" {
- return
- }
+ /*
+ if s.vmName == "" {
+ return
+ }
- driver := state.Get("driver").(parallelscommon.Driver)
- ui := state.Get("ui").(packer.Ui)
- config := state.Get("config").(*config)
+ driver := state.Get("driver").(parallelscommon.Driver)
+ ui := state.Get("ui").(packer.Ui)
+ config := state.Get("config").(*config)
- if config.DeleteVM {
- ui.Say("Deleting virtual machine...")
- if err := driver.Prlctl("delete", s.vmName); err != nil {
- ui.Error(fmt.Sprintf("Error deleting virtual machine: %s", err))
- }
- }
+ if config.DeleteVM {
+ ui.Say("Deleting virtual machine...")
+ if err := driver.Prlctl("delete", s.vmName); err != nil {
+ ui.Error(fmt.Sprintf("Error deleting virtual machine: %s", err))
+ }
+ }
+ */
}
Oops, something went wrong.

0 comments on commit 8a4818b

Please sign in to comment.