Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
fc2d695b
Commit
fc2d695b
authored
Aug 20, 2014
by
Mikhail Zholobov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/parallels: Added compatibility with Parallels Desktop 10
parent
10be7e27
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
55 additions
and
22 deletions
+55
-22
builder/parallels/common/driver.go
builder/parallels/common/driver.go
+26
-4
builder/parallels/common/driver_10.go
builder/parallels/common/driver_10.go
+6
-0
builder/parallels/common/driver_9.go
builder/parallels/common/driver_9.go
+23
-18
No files found.
builder/parallels/common/driver.go
View file @
fc2d695b
package
common
import
(
"fmt"
"log"
"os/exec"
"runtime"
"strings"
)
// A driver is able to talk to Parallels and perform certain
...
...
@@ -43,7 +46,9 @@ type Driver interface {
}
func
NewDriver
()
(
Driver
,
error
)
{
var
drivers
map
[
string
]
Driver
var
prlctlPath
string
var
supportedVersions
[]
string
if
runtime
.
GOOS
!=
"darwin"
{
return
nil
,
fmt
.
Errorf
(
...
...
@@ -59,10 +64,27 @@ func NewDriver() (Driver, error) {
}
log
.
Printf
(
"prlctl path: %s"
,
prlctlPath
)
driver
:=
&
Parallels9Driver
{
prlctlPath
}
if
err
:=
driver
.
Verify
();
err
!=
nil
{
return
nil
,
err
drivers
=
map
[
string
]
Driver
{
"10"
:
&
Parallels10Driver
{
Parallels9Driver
:
Parallels9Driver
{
PrlctlPath
:
prlctlPath
,
},
},
"9"
:
&
Parallels9Driver
{
PrlctlPath
:
prlctlPath
,
},
}
for
v
,
d
:=
range
drivers
{
version
,
_
:=
d
.
Version
()
if
strings
.
HasPrefix
(
version
,
v
)
{
return
d
,
nil
}
supportedVersions
=
append
(
supportedVersions
,
v
)
}
return
driver
,
nil
return
nil
,
fmt
.
Errorf
(
"Unable to initialize any driver. Supported Parallels Desktop versions: "
+
"%s
\n
"
,
strings
.
Join
(
supportedVersions
,
", "
))
}
builder/parallels/common/driver_10.go
0 → 100644
View file @
fc2d695b
package
common
// Parallels10Driver are inherited from Parallels9Driver.
type
Parallels10Driver
struct
{
Parallels9Driver
}
builder/parallels/common/driver_9.go
View file @
fc2d695b
...
...
@@ -13,7 +13,6 @@ import (
"github.com/going/toolkit/xmlpath"
)
// Driver supporting Parallels Desktop for Mac v. 9 & 10
type
Parallels9Driver
struct
{
// This is the path to the "prlctl" application.
PrlctlPath
string
...
...
@@ -72,6 +71,20 @@ func getConfigValueFromXpath(path, xpath string) (string, error) {
return
value
,
nil
}
// Finds an application bundle by identifier (for "darwin" platform only)
func
getAppPath
(
bundleId
string
)
(
string
,
error
)
{
cmd
:=
exec
.
Command
(
"mdfind"
,
"kMDItemCFBundleIdentifier =="
,
bundleId
)
out
,
err
:=
cmd
.
Output
()
if
err
!=
nil
{
return
""
,
err
}
if
string
(
out
)
==
""
{
return
""
,
fmt
.
Errorf
(
"Could not detect Parallels Desktop! Make sure it is properly installed."
)
}
return
string
(
out
),
nil
}
func
(
d
*
Parallels9Driver
)
IsRunning
(
name
string
)
(
bool
,
error
)
{
var
stdout
bytes
.
Buffer
...
...
@@ -136,32 +149,24 @@ func (d *Parallels9Driver) Prlctl(args ...string) error {
}
func
(
d
*
Parallels9Driver
)
Verify
()
error
{
version
,
_
:=
d
.
Version
()
if
!
(
strings
.
HasPrefix
(
version
,
"9."
)
||
strings
.
HasPrefix
(
version
,
"10."
))
{
return
fmt
.
Errorf
(
"The packer-parallels builder plugin only supports Parallels Desktop v. 9 & 10. You have: %s!
\n
"
,
version
)
}
return
nil
}
func
(
d
*
Parallels9Driver
)
Version
()
(
string
,
error
)
{
var
stdout
bytes
.
Buffer
cmd
:=
exec
.
Command
(
d
.
PrlctlPath
,
"--version"
)
cmd
.
Stdout
=
&
stdout
if
err
:=
cmd
.
Run
();
err
!=
nil
{
out
,
err
:=
exec
.
Command
(
d
.
PrlctlPath
,
"--version"
)
.
Output
()
if
err
!=
nil
{
return
""
,
err
}
versionOutput
:=
strings
.
TrimSpace
(
stdout
.
String
())
re
:=
regexp
.
MustCompile
(
"prlctl version ([0-9
\\
.]+)"
)
verMatch
:=
re
.
FindAllStringSubmatch
(
versionOutput
,
1
)
if
len
(
verMatch
)
!=
1
{
return
""
,
fmt
.
Errorf
(
"prlctl version not found!
\n
"
)
versionRe
:=
regexp
.
MustCompile
(
`prlctl version (\d+\.\d+.\d+)`
)
matches
:=
versionRe
.
FindStringSubmatch
(
string
(
out
))
if
matches
==
nil
{
return
""
,
fmt
.
Errorf
(
"Could not find Parallels Desktop version in output:
\n
%s"
,
string
(
out
))
}
version
:=
verMatch
[
0
]
[
1
]
log
.
Printf
(
"
prlctl version: %s
\n
"
,
version
)
version
:=
matches
[
1
]
log
.
Printf
(
"
Parallels Desktop version: %s
"
,
version
)
return
version
,
nil
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment