Skip to content

Commit

Permalink
Can create a vm with Parallels but noting more.
Browse files Browse the repository at this point in the history
  • Loading branch information
rickard-von-essen committed Jan 18, 2014
1 parent 7f2d30c commit c61f750
Show file tree
Hide file tree
Showing 58 changed files with 4,136 additions and 3 deletions.
14 changes: 14 additions & 0 deletions .travis.yml
@@ -0,0 +1,14 @@
language: go

go:
- 1.2
- tip

install: make deps
script:
- go test ./...
- go test -race ./...

matrix:
allow_failures:
- go: tip
32 changes: 32 additions & 0 deletions Makefile
@@ -0,0 +1,32 @@
NO_COLOR=\033[0m
OK_COLOR=\033[32;01m
ERROR_COLOR=\033[31;01m
WARN_COLOR=\033[33;01m
DEPS = $(go list -f '{{range .TestImports}}{{.}} {{end}}' ./...)

all: deps
@mkdir -p bin/
@echo "$(OK_COLOR)==> Building$(NO_COLOR)"
@bash --norc -i ./scripts/devcompile.sh

deps:
@echo "$(OK_COLOR)==> Installing dependencies$(NO_COLOR)"
@go get -d -v ./...
@echo $(DEPS) | xargs -n1 go get -d

updatedeps:
@echo "$(OK_COLOR)==> Updating all dependencies$(NO_COLOR)"
@go get -d -v -u ./...
@echo $(DEPS) | xargs -n1 go get -d -u

clean:
@rm -rf bin/ local/ pkg/ src/ website/.sass-cache website/build

format:
go fmt ./...

test: deps
@echo "$(OK_COLOR)==> Testing Packer...$(NO_COLOR)"
go test ./...

.PHONY: all clean deps format test updatedeps
24 changes: 21 additions & 3 deletions README.md
Expand Up @@ -2,13 +2,31 @@


This is a custom builder plugin for [Packer](http://www.packer.io/) using [Parallels](http://www.parallels.com/). This is a custom builder plugin for [Packer](http://www.packer.io/) using [Parallels](http://www.parallels.com/).


**Current status: NOT USEFUL (yet)!** **Current status: Alpha - BROKEN!**

## Status
This is currently under development. Don't expect it to work. The only reason to run this plugin is if you wont to contribute to its development.


## Documentation ## Documentation
TODO TODO


## Building / Installing ## Building / Installing
TODO Install packer and add the following to ```~/.packerconfig```

```
{
"builders": {
"parallels-iso": "builder-parallels-iso"
}
}
```

```
cd $GOPATH/src && git clone https://github.com/rickard-von-essen/packer-parallels
cd packer-parallels
go get -u github.com/mitchellh/gox
make
```


## Issues ## Issues
If you find any bugs please open a issue at [github](https://github.com/rickard-von-essen/packer-parallels/issues). If you find any bugs please open a issue at [github](https://github.com/rickard-von-essen/packer-parallels/issues).
Expand All @@ -18,4 +36,4 @@ If you have any improvments open a pull request at [github](https://github.com/r


## License ## License


This code is distributed under the MIT license see _LICENSE_. This code is distributed under the MIT license, see _LICENSE_.
15 changes: 15 additions & 0 deletions builder-parallels-iso/main.go
@@ -0,0 +1,15 @@
package main

import (
"github.com/mitchellh/packer/packer/plugin"
"github.com/rickard-von-essen/packer-parallels/iso"
)

func main() {
server, err := plugin.Server()
if err != nil {
panic(err)
}
server.RegisterBuilder(new(iso.Builder))
server.Serve()
}
1 change: 1 addition & 0 deletions builder-parallels-iso/main_test.go
@@ -0,0 +1 @@
package main
60 changes: 60 additions & 0 deletions common/artifact.go
@@ -0,0 +1,60 @@
package common

import (
"fmt"
"github.com/mitchellh/packer/packer"
"os"
"path/filepath"
)

// This is the common builder ID to all of these artifacts.
const BuilderId = "rickard-von-essen.parallels"

// Artifact is the result of running the parallels builder, namely a set
// of files associated with the resulting machine.
type artifact struct {
dir string
f []string
}

// NewArtifact returns a Parallels artifact containing the files
// in the given directory.
func NewArtifact(dir string) (packer.Artifact, error) {
files := make([]string, 0, 5)
visit := func(path string, info os.FileInfo, err error) error {
if !info.IsDir() {
files = append(files, path)
}

return err
}

if err := filepath.Walk(dir, visit); err != nil {
return nil, err
}

return &artifact{
dir: dir,
f: files,
}, nil
}

func (*artifact) BuilderId() string {
return BuilderId
}

func (a *artifact) Files() []string {
return a.f
}

func (*artifact) Id() string {
return "VM"
}

func (a *artifact) String() string {
return fmt.Sprintf("VM files in directory: %s", a.dir)
}

func (a *artifact) Destroy() error {
return os.RemoveAll(a.dir)
}
43 changes: 43 additions & 0 deletions common/artifact_test.go
@@ -0,0 +1,43 @@
package common

import (
"io/ioutil"
"os"
"path/filepath"
"testing"

"github.com/mitchellh/packer/packer"
)

func TestArtifact_impl(t *testing.T) {
var _ packer.Artifact = new(artifact)
}

func TestNewArtifact(t *testing.T) {
td, err := ioutil.TempDir("", "packer")
if err != nil {
t.Fatalf("err: %s", err)
}
defer os.RemoveAll(td)

err = ioutil.WriteFile(filepath.Join(td, "a"), []byte("foo"), 0644)
if err != nil {
t.Fatalf("err: %s", err)
}

if err := os.Mkdir(filepath.Join(td, "b"), 0755); err != nil {
t.Fatalf("err: %s", err)
}

a, err := NewArtifact(td)
if err != nil {
t.Fatalf("err: %s", err)
}

if a.BuilderId() != BuilderId {
t.Fatalf("bad: %#v", a.BuilderId())
}
if len(a.Files()) != 1 {
t.Fatalf("should length 1: %d", len(a.Files()))
}
}
15 changes: 15 additions & 0 deletions common/config_test.go
@@ -0,0 +1,15 @@
package common

import (
"github.com/mitchellh/packer/packer"
"testing"
)

func testConfigTemplate(t *testing.T) *packer.ConfigTemplate {
result, err := packer.NewConfigTemplate()
if err != nil {
t.Fatalf("err: %s", err)
}

return result
}
67 changes: 67 additions & 0 deletions common/driver.go
@@ -0,0 +1,67 @@
package common

import (
"log"
//"os"
"os/exec"
//"path/filepath"
//"runtime"
//"strings"
)

// 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 Driver interface {
// Create a SATA controller.
CreateSATAController(vm string, controller string) error

// Delete a VM by name
Delete(string) error

// Import a VM
Import(string, string) error

// Checks if the VM with the given name is running.
IsRunning(string) (bool, error)

// Stop stops a running machine, forcefully.
Stop(string) error

// Use default settings from Parallels
UseDefaults(string) error

// Prlctl executes the given Prlctl command
Prlctl(...string) error

// Verify checks to make sure that this driver should function
// properly. If there is any indication the driver can't function,
// this will return an error.
Verify() error

// Version reads the version of Parallels that is installed.
Version() (string, error)
}

func NewDriver() (Driver, error) {
var prlctlPath string

if prlctlPath == "" {
var err error
prlctlPath, err = exec.LookPath("prlctl")
if err != nil {
return nil, err
}
}

log.Printf("prlctl path: %s", prlctlPath)
driver := &Parallels9Driver{prlctlPath}
if err := driver.Verify(); err != nil {
return nil, err
}

return driver, nil
}

0 comments on commit c61f750

Please sign in to comment.