Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Can create a vm with Parallels but noting more.
- Loading branch information
1 parent
7f2d30c
commit c61f750
Showing
58 changed files
with
4,136 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,14 @@ | |||
language: go | |||
|
|||
go: | |||
- 1.2 | |||
- tip | |||
|
|||
install: make deps | |||
script: | |||
- go test ./... | |||
- go test -race ./... | |||
|
|||
matrix: | |||
allow_failures: | |||
- go: tip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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() | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1 @@ | |||
package main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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) | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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())) | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -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 | |||
} |
Oops, something went wrong.