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
16911d75
Commit
16911d75
authored
Dec 25, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware: move drivers out to common
parent
bee87940
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
106 additions
and
83 deletions
+106
-83
builder/vmware/common/driver.go
builder/vmware/common/driver.go
+80
-0
builder/vmware/common/driver_fusion5.go
builder/vmware/common/driver_fusion5.go
+3
-4
builder/vmware/common/driver_player5.go
builder/vmware/common/driver_player5.go
+3
-4
builder/vmware/common/driver_workstation9.go
builder/vmware/common/driver_workstation9.go
+3
-4
builder/vmware/common/driver_workstation9_unix.go
builder/vmware/common/driver_workstation9_unix.go
+1
-1
builder/vmware/common/driver_workstation9_windows.go
builder/vmware/common/driver_workstation9_windows.go
+1
-1
builder/vmware/iso/driver.go
builder/vmware/iso/driver.go
+12
-68
builder/vmware/iso/host_ip_vmnetnatconf.go
builder/vmware/iso/host_ip_vmnetnatconf.go
+3
-1
No files found.
builder/vmware/common/driver.go
View file @
16911d75
package
common
import
(
"bytes"
"fmt"
"log"
"os/exec"
"runtime"
"strings"
"github.com/mitchellh/multistep"
)
...
...
@@ -41,3 +48,76 @@ type Driver interface {
// return an error. Otherwise, this returns an error.
Verify
()
error
}
// NewDriver returns a new driver implementation for this operating
// system, or an error if the driver couldn't be initialized.
func
NewDriver
(
config
*
SSHConfig
)
(
Driver
,
error
)
{
drivers
:=
[]
Driver
{}
switch
runtime
.
GOOS
{
case
"darwin"
:
drivers
=
[]
Driver
{
&
Fusion5Driver
{
AppPath
:
"/Applications/VMware Fusion.app"
,
SSHConfig
:
config
,
},
}
case
"linux"
:
drivers
=
[]
Driver
{
&
Workstation9Driver
{
SSHConfig
:
config
,
},
&
Player5LinuxDriver
{
SSHConfig
:
config
,
},
}
case
"windows"
:
drivers
=
[]
Driver
{
&
Workstation9Driver
{
SSHConfig
:
config
,
},
}
default
:
return
nil
,
fmt
.
Errorf
(
"can't find driver for OS: %s"
,
runtime
.
GOOS
)
}
errs
:=
""
for
_
,
driver
:=
range
drivers
{
err
:=
driver
.
Verify
()
if
err
==
nil
{
return
driver
,
nil
}
errs
+=
"* "
+
err
.
Error
()
+
"
\n
"
}
return
nil
,
fmt
.
Errorf
(
"Unable to initialize any driver for this platform. The errors
\n
"
+
"from each driver are shown below. Please fix at least one driver
\n
"
+
"to continue:
\n
%s"
,
errs
)
}
func
runAndLog
(
cmd
*
exec
.
Cmd
)
(
string
,
string
,
error
)
{
var
stdout
,
stderr
bytes
.
Buffer
log
.
Printf
(
"Executing: %s %v"
,
cmd
.
Path
,
cmd
.
Args
[
1
:
])
cmd
.
Stdout
=
&
stdout
cmd
.
Stderr
=
&
stderr
err
:=
cmd
.
Run
()
stdoutString
:=
strings
.
TrimSpace
(
stdout
.
String
())
stderrString
:=
strings
.
TrimSpace
(
stderr
.
String
())
if
_
,
ok
:=
err
.
(
*
exec
.
ExitError
);
ok
{
err
=
fmt
.
Errorf
(
"VMware error: %s"
,
stderrString
)
}
log
.
Printf
(
"stdout: %s"
,
stdoutString
)
log
.
Printf
(
"stderr: %s"
,
stderrString
)
// Replace these for Windows, we only want to deal with Unix
// style line endings.
returnStdout
:=
strings
.
Replace
(
stdout
.
String
(),
"
\r\n
"
,
"
\n
"
,
-
1
)
returnStderr
:=
strings
.
Replace
(
stderr
.
String
(),
"
\r\n
"
,
"
\n
"
,
-
1
)
return
returnStdout
,
returnStderr
,
err
}
builder/vmware/
iso
/driver_fusion5.go
→
builder/vmware/
common
/driver_fusion5.go
View file @
16911d75
package
iso
package
common
import
(
"fmt"
...
...
@@ -9,7 +9,6 @@ import (
"strings"
"github.com/mitchellh/multistep"
vmwcommon
"github.com/mitchellh/packer/builder/vmware/common"
)
// Fusion5Driver is a driver that can run VMWare Fusion 5.
...
...
@@ -18,7 +17,7 @@ type Fusion5Driver struct {
AppPath
string
// SSHConfig are the SSH settings for the Fusion VM
SSHConfig
*
vmwcommon
.
SSHConfig
SSHConfig
*
SSHConfig
}
func
(
d
*
Fusion5Driver
)
CompactDisk
(
diskPath
string
)
error
{
...
...
@@ -66,7 +65,7 @@ func (d *Fusion5Driver) IsRunning(vmxPath string) (bool, error) {
}
func
(
d
*
Fusion5Driver
)
SSHAddress
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
return
vmwcommon
.
SSHAddressFunc
(
d
.
SSHConfig
)(
state
)
return
SSHAddressFunc
(
d
.
SSHConfig
)(
state
)
}
func
(
d
*
Fusion5Driver
)
Start
(
vmxPath
string
,
headless
bool
)
error
{
...
...
builder/vmware/
iso
/driver_player5.go
→
builder/vmware/
common
/driver_player5.go
View file @
16911d75
package
iso
package
common
import
(
"fmt"
...
...
@@ -8,7 +8,6 @@ import (
"strings"
"github.com/mitchellh/multistep"
vmwcommon
"github.com/mitchellh/packer/builder/vmware/common"
)
// Player5LinuxDriver is a driver that can run VMware Player 5 on Linux.
...
...
@@ -19,7 +18,7 @@ type Player5LinuxDriver struct {
VmrunPath
string
// SSHConfig are the SSH settings for the Fusion VM
SSHConfig
*
vmwcommon
.
SSHConfig
SSHConfig
*
SSHConfig
}
func
(
d
*
Player5LinuxDriver
)
CompactDisk
(
diskPath
string
)
error
{
...
...
@@ -93,7 +92,7 @@ func (d *Player5LinuxDriver) IsRunning(vmxPath string) (bool, error) {
}
func
(
d
*
Player5LinuxDriver
)
SSHAddress
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
return
vmwcommon
.
SSHAddressFunc
(
d
.
SSHConfig
)(
state
)
return
SSHAddressFunc
(
d
.
SSHConfig
)(
state
)
}
func
(
d
*
Player5LinuxDriver
)
Start
(
vmxPath
string
,
headless
bool
)
error
{
...
...
builder/vmware/
iso
/driver_workstation9.go
→
builder/vmware/
common
/driver_workstation9.go
View file @
16911d75
package
iso
package
common
import
(
"fmt"
...
...
@@ -9,7 +9,6 @@ import (
"strings"
"github.com/mitchellh/multistep"
vmwcommon
"github.com/mitchellh/packer/builder/vmware/common"
)
// Workstation9Driver is a driver that can run VMware Workstation 9
...
...
@@ -20,7 +19,7 @@ type Workstation9Driver struct {
VmrunPath
string
// SSHConfig are the SSH settings for the Fusion VM
SSHConfig
*
vmwcommon
.
SSHConfig
SSHConfig
*
SSHConfig
}
func
(
d
*
Workstation9Driver
)
CompactDisk
(
diskPath
string
)
error
{
...
...
@@ -68,7 +67,7 @@ func (d *Workstation9Driver) IsRunning(vmxPath string) (bool, error) {
}
func
(
d
*
Workstation9Driver
)
SSHAddress
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
return
vmwcommon
.
SSHAddressFunc
(
d
.
SSHConfig
)(
state
)
return
SSHAddressFunc
(
d
.
SSHConfig
)(
state
)
}
func
(
d
*
Workstation9Driver
)
Start
(
vmxPath
string
,
headless
bool
)
error
{
...
...
builder/vmware/
iso
/driver_workstation9_unix.go
→
builder/vmware/
common
/driver_workstation9_unix.go
View file @
16911d75
// +build !windows
package
iso
package
common
import
(
"errors"
...
...
builder/vmware/
iso
/driver_workstation9_windows.go
→
builder/vmware/
common
/driver_workstation9_windows.go
View file @
16911d75
// +build windows
package
iso
package
common
import
(
"log"
...
...
builder/vmware/iso/driver.go
View file @
16911d75
package
iso
import
(
"bytes"
"fmt"
"log"
"os/exec"
"runtime"
"strings"
vmwcommon
"github.com/mitchellh/packer/builder/vmware/common"
)
...
...
@@ -16,7 +11,10 @@ import (
func
NewDriver
(
config
*
config
)
(
vmwcommon
.
Driver
,
error
)
{
drivers
:=
[]
vmwcommon
.
Driver
{}
if
config
.
RemoteType
!=
""
{
if
config
.
RemoteType
==
""
{
return
vmwcommon
.
NewDriver
(
&
config
.
SSHConfig
)
}
drivers
=
[]
vmwcommon
.
Driver
{
&
ESX5Driver
{
Host
:
config
.
RemoteHost
,
...
...
@@ -26,34 +24,6 @@ func NewDriver(config *config) (vmwcommon.Driver, error) {
Datastore
:
config
.
RemoteDatastore
,
},
}
}
else
{
switch
runtime
.
GOOS
{
case
"darwin"
:
drivers
=
[]
vmwcommon
.
Driver
{
&
Fusion5Driver
{
AppPath
:
"/Applications/VMware Fusion.app"
,
SSHConfig
:
&
config
.
SSHConfig
,
},
}
case
"linux"
:
drivers
=
[]
vmwcommon
.
Driver
{
&
Workstation9Driver
{
SSHConfig
:
&
config
.
SSHConfig
,
},
&
Player5LinuxDriver
{
SSHConfig
:
&
config
.
SSHConfig
,
},
}
case
"windows"
:
drivers
=
[]
vmwcommon
.
Driver
{
&
Workstation9Driver
{
SSHConfig
:
&
config
.
SSHConfig
,
},
}
default
:
return
nil
,
fmt
.
Errorf
(
"can't find driver for OS: %s"
,
runtime
.
GOOS
)
}
}
errs
:=
""
for
_
,
driver
:=
range
drivers
{
...
...
@@ -69,29 +39,3 @@ func NewDriver(config *config) (vmwcommon.Driver, error) {
"from each driver are shown below. Please fix at least one driver
\n
"
+
"to continue:
\n
%s"
,
errs
)
}
func
runAndLog
(
cmd
*
exec
.
Cmd
)
(
string
,
string
,
error
)
{
var
stdout
,
stderr
bytes
.
Buffer
log
.
Printf
(
"Executing: %s %v"
,
cmd
.
Path
,
cmd
.
Args
[
1
:
])
cmd
.
Stdout
=
&
stdout
cmd
.
Stderr
=
&
stderr
err
:=
cmd
.
Run
()
stdoutString
:=
strings
.
TrimSpace
(
stdout
.
String
())
stderrString
:=
strings
.
TrimSpace
(
stderr
.
String
())
if
_
,
ok
:=
err
.
(
*
exec
.
ExitError
);
ok
{
err
=
fmt
.
Errorf
(
"VMware error: %s"
,
stderrString
)
}
log
.
Printf
(
"stdout: %s"
,
stdoutString
)
log
.
Printf
(
"stderr: %s"
,
stderrString
)
// Replace these for Windows, we only want to deal with Unix
// style line endings.
returnStdout
:=
strings
.
Replace
(
stdout
.
String
(),
"
\r\n
"
,
"
\n
"
,
-
1
)
returnStderr
:=
strings
.
Replace
(
stderr
.
String
(),
"
\r\n
"
,
"
\n
"
,
-
1
)
return
returnStdout
,
returnStderr
,
err
}
builder/vmware/iso/host_ip_vmnetnatconf.go
View file @
16911d75
...
...
@@ -8,6 +8,8 @@ import (
"os"
"regexp"
"strings"
vmwcommon
"github.com/mitchellh/packer/builder/vmware/common"
)
// VMnetNatConfIPFinder finds the IP address of the host machine by
...
...
@@ -16,7 +18,7 @@ import (
type
VMnetNatConfIPFinder
struct
{}
func
(
*
VMnetNatConfIPFinder
)
HostIP
()
(
string
,
error
)
{
driver
:=
&
Workstation9Driver
{}
driver
:=
&
vmwcommon
.
Workstation9Driver
{}
vmnetnat
:=
driver
.
VmnetnatConfPath
()
if
vmnetnat
==
""
{
...
...
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