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
8a8ac430
Commit
8a8ac430
authored
Nov 07, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware: upload the ISO to the ESXi machine
parent
859a6f06
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
130 additions
and
38 deletions
+130
-38
builder/vmware/builder.go
builder/vmware/builder.go
+4
-0
builder/vmware/driver_esx5.go
builder/vmware/driver_esx5.go
+19
-27
builder/vmware/driver_esx5_test.go
builder/vmware/driver_esx5_test.go
+13
-0
builder/vmware/output_dir.go
builder/vmware/output_dir.go
+32
-0
builder/vmware/remote_driver.go
builder/vmware/remote_driver.go
+16
-0
builder/vmware/step_remote_upload.go
builder/vmware/step_remote_upload.go
+42
-0
builder/vmware/step_run.go
builder/vmware/step_run.go
+4
-11
No files found.
builder/vmware/builder.go
View file @
8a8ac430
...
@@ -395,6 +395,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
...
@@ -395,6 +395,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&
common
.
StepCreateFloppy
{
&
common
.
StepCreateFloppy
{
Files
:
b
.
config
.
FloppyFiles
,
Files
:
b
.
config
.
FloppyFiles
,
},
},
&
stepRemoteUpload
{
Key
:
"iso_path"
,
Message
:
"Uploading ISO to remote machine..."
,
},
&
stepCreateDisk
{},
&
stepCreateDisk
{},
&
stepCreateVMX
{},
&
stepCreateVMX
{},
&
stepHTTPServer
{},
&
stepHTTPServer
{},
...
...
builder/vmware/driver_esx5.go
View file @
8a8ac430
...
@@ -67,6 +67,25 @@ func (d *ESX5Driver) Unregister(vmxPathLocal string) error {
...
@@ -67,6 +67,25 @@ func (d *ESX5Driver) Unregister(vmxPathLocal string) error {
return
d
.
sh
(
"vim-cmd"
,
"vmsvc/unregister"
,
d
.
datastorePath
(
vmxPathLocal
))
return
d
.
sh
(
"vim-cmd"
,
"vmsvc/unregister"
,
d
.
datastorePath
(
vmxPathLocal
))
}
}
func
(
d
*
ESX5Driver
)
UploadISO
(
localPath
string
)
(
string
,
error
)
{
cacheRoot
,
_
:=
filepath
.
Abs
(
"."
)
targetFile
,
err
:=
filepath
.
Rel
(
cacheRoot
,
localPath
)
if
err
!=
nil
{
return
""
,
err
}
if
err
:=
d
.
MkdirAll
(
filepath
.
Dir
(
targetFile
));
err
!=
nil
{
return
""
,
err
}
finalPath
:=
d
.
datastorePath
(
targetFile
)
if
err
:=
d
.
upload
(
finalPath
,
localPath
);
err
!=
nil
{
return
""
,
err
}
return
finalPath
,
nil
}
func
(
d
*
ESX5Driver
)
ToolsIsoPath
(
string
)
string
{
func
(
d
*
ESX5Driver
)
ToolsIsoPath
(
string
)
string
{
return
""
return
""
}
}
...
@@ -180,33 +199,6 @@ func (d *ESX5Driver) SSHAddress(state multistep.StateBag) (string, error) {
...
@@ -180,33 +199,6 @@ func (d *ESX5Driver) SSHAddress(state multistep.StateBag) (string, error) {
return
address
,
nil
return
address
,
nil
}
}
/*
func (d *ESX5Driver) Download(*common.DownloadConfig, multistep.StateBag) (string, error, bool) {
config := state.Get("config").(*config)
cacheRoot, _ := filepath.Abs(".")
targetFile, err := filepath.Rel(cacheRoot, dconfig.TargetPath)
if err != nil {
return "", err, false
}
if err := d.MkdirAll(filepath.Dir(targetFile)); err != nil {
return "", err, false
}
path := d.datastorePath(targetFile)
if d.verifyChecksum(config.ISOChecksumType, config.ISOChecksum, path) {
log.Println("Initial checksum matched, no download needed.")
return path, nil, true
}
// TODO(dougm) progress and handle interrupt
err = d.sh("wget", dconfig.Url, "-O", path)
return path, err, true
}
*/
func
(
d
*
ESX5Driver
)
DirExists
(
path
string
)
(
bool
,
error
)
{
func
(
d
*
ESX5Driver
)
DirExists
(
path
string
)
(
bool
,
error
)
{
err
:=
d
.
sh
(
"test"
,
"-e"
,
d
.
datastorePath
(
path
))
err
:=
d
.
sh
(
"test"
,
"-e"
,
d
.
datastorePath
(
path
))
return
err
==
nil
,
err
return
err
==
nil
,
err
...
...
builder/vmware/driver_esx5_test.go
0 → 100644
View file @
8a8ac430
package
vmware
import
(
"testing"
)
func
TestESX5Driver_implDriver
(
t
*
testing
.
T
)
{
var
_
Driver
=
new
(
ESX5Driver
)
}
func
TestESX5Driver_implRemoteDriver
(
t
*
testing
.
T
)
{
var
_
RemoteDriver
=
new
(
ESX5Driver
)
}
builder/vmware/output_dir.go
0 → 100644
View file @
8a8ac430
package
vmware
import
(
"os"
)
// OutputDir is an interface type that abstracts the creation and handling
// of the output directory for VMware-based products. The abstraction is made
// so that the output directory can be properly made on remote (ESXi) based
// VMware products as well as local.
type
OutputDir
interface
{
DirExists
(
string
)
(
bool
,
error
)
MkdirAll
(
string
)
error
RemoveAll
(
string
)
error
}
// localOutputDir is an OutputDir implementation where the directory
// is on the local machine.
type
localOutputDir
struct
{}
func
(
localOutputDir
)
DirExists
(
path
string
)
(
bool
,
error
)
{
_
,
err
:=
os
.
Stat
(
path
)
return
err
==
nil
,
err
}
func
(
localOutputDir
)
MkdirAll
(
path
string
)
error
{
return
os
.
MkdirAll
(
path
,
0755
)
}
func
(
localOutputDir
)
RemoveAll
(
path
string
)
error
{
return
os
.
RemoveAll
(
path
)
}
builder/vmware/remote_driver.go
0 → 100644
View file @
8a8ac430
package
vmware
type
RemoteDriver
interface
{
Driver
// UploadISO uploads a local ISO to the remote side and returns the
// new path that should be used in the VMX along with an error if it
// exists.
UploadISO
(
string
)
(
string
,
error
)
// Adds a VM to inventory specified by the path to the VMX given.
Register
(
string
)
error
// Removes a VM from inventory specified by the path to the VMX given.
Unregister
(
string
)
error
}
builder/vmware/step_remote_upload.go
0 → 100644
View file @
8a8ac430
package
vmware
import
(
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"log"
)
// stepRemoteUpload uploads some thing from the state bag to a remote driver
// (if it can) and stores that new remote path into the state bag.
type
stepRemoteUpload
struct
{
Key
string
Message
string
}
func
(
s
*
stepRemoteUpload
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
remote
,
ok
:=
driver
.
(
RemoteDriver
)
if
!
ok
{
return
multistep
.
ActionContinue
}
ui
.
Say
(
s
.
Message
)
path
:=
state
.
Get
(
s
.
Key
)
.
(
string
)
log
.
Printf
(
"Remote uploading: %s"
,
path
)
newPath
,
err
:=
remote
.
UploadISO
(
path
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error uploading file: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
state
.
Put
(
s
.
Key
,
newPath
)
return
multistep
.
ActionContinue
}
func
(
s
*
stepRemoteUpload
)
Cleanup
(
state
multistep
.
StateBag
)
{
}
builder/vmware/step_run.go
View file @
8a8ac430
...
@@ -22,13 +22,6 @@ type stepRun struct {
...
@@ -22,13 +22,6 @@ type stepRun struct {
vmxPath
string
vmxPath
string
}
}
type
Inventory
interface
{
// Adds a VM to inventory specified by the path to the VMX given.
Register
(
string
)
error
// Removes a VM from inventory specified by the path to the VMX given.
Unregister
(
string
)
error
}
func
(
s
*
stepRun
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
func
(
s
*
stepRun
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
...
@@ -49,8 +42,8 @@ func (s *stepRun) Run(state multistep.StateBag) multistep.StepAction {
...
@@ -49,8 +42,8 @@ func (s *stepRun) Run(state multistep.StateBag) multistep.StepAction {
"%s:%d"
,
vncIp
,
vncPort
))
"%s:%d"
,
vncIp
,
vncPort
))
}
}
if
inv
,
ok
:=
driver
.
(
Inventory
);
ok
{
if
remoteDriver
,
ok
:=
driver
.
(
RemoteDriver
);
ok
{
if
err
:=
inv
.
Register
(
vmxPath
);
err
!=
nil
{
if
err
:=
remoteDriver
.
Register
(
vmxPath
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error registering VM: %s"
,
err
)
err
:=
fmt
.
Errorf
(
"Error registering VM: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
ui
.
Error
(
err
.
Error
())
...
@@ -98,9 +91,9 @@ func (s *stepRun) Cleanup(state multistep.StateBag) {
...
@@ -98,9 +91,9 @@ func (s *stepRun) Cleanup(state multistep.StateBag) {
}
}
}
}
if
inv
,
ok
:=
driver
.
(
Inventory
);
ok
{
if
remoteDriver
,
ok
:=
driver
.
(
RemoteDriver
);
ok
{
ui
.
Say
(
"Unregistering virtual machine..."
)
ui
.
Say
(
"Unregistering virtual machine..."
)
if
err
:=
inv
.
Unregister
(
s
.
vmxPath
);
err
!=
nil
{
if
err
:=
remoteDriver
.
Unregister
(
s
.
vmxPath
);
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error unregistering VM: %s"
,
err
))
ui
.
Error
(
fmt
.
Sprintf
(
"Error unregistering VM: %s"
,
err
))
}
}
}
}
...
...
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