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
7f38cea9
Commit
7f38cea9
authored
Dec 26, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware/vmx: shutdown
parent
ac8354ad
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
115 additions
and
70 deletions
+115
-70
builder/vmware/common/shutdown_config.go
builder/vmware/common/shutdown_config.go
+42
-0
builder/vmware/common/shutdown_config_test.go
builder/vmware/common/shutdown_config_test.go
+45
-0
builder/vmware/iso/builder.go
builder/vmware/iso/builder.go
+10
-23
builder/vmware/iso/builder_test.go
builder/vmware/iso/builder_test.go
+0
-41
builder/vmware/vmx/builder.go
builder/vmware/vmx/builder.go
+4
-0
builder/vmware/vmx/config.go
builder/vmware/vmx/config.go
+12
-5
builder/vmware/vmx/config_test.go
builder/vmware/vmx/config_test.go
+2
-1
No files found.
builder/vmware/common/shutdown_config.go
0 → 100644
View file @
7f38cea9
package
common
import
(
"fmt"
"github.com/mitchellh/packer/packer"
"time"
)
type
ShutdownConfig
struct
{
ShutdownCommand
string
`mapstructure:"shutdown_command"`
RawShutdownTimeout
string
`mapstructure:"shutdown_timeout"`
ShutdownTimeout
time
.
Duration
``
}
func
(
c
*
ShutdownConfig
)
Prepare
(
t
*
packer
.
ConfigTemplate
)
[]
error
{
if
c
.
RawShutdownTimeout
==
""
{
c
.
RawShutdownTimeout
=
"5m"
}
templates
:=
map
[
string
]
*
string
{
"shutdown_command"
:
&
c
.
ShutdownCommand
,
"shutdown_timeout"
:
&
c
.
RawShutdownTimeout
,
}
errs
:=
make
([]
error
,
0
)
for
n
,
ptr
:=
range
templates
{
var
err
error
*
ptr
,
err
=
t
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
n
,
err
))
}
}
var
err
error
c
.
ShutdownTimeout
,
err
=
time
.
ParseDuration
(
c
.
RawShutdownTimeout
)
if
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Failed parsing shutdown_timeout: %s"
,
err
))
}
return
errs
}
builder/vmware/common/shutdown_config_test.go
0 → 100644
View file @
7f38cea9
package
common
import
(
"testing"
"time"
)
func
testShutdownConfig
()
*
ShutdownConfig
{
return
&
ShutdownConfig
{}
}
func
TestShutdownConfigPrepare_ShutdownCommand
(
t
*
testing
.
T
)
{
var
c
*
ShutdownConfig
var
errs
[]
error
c
=
testShutdownConfig
()
errs
=
c
.
Prepare
(
testConfigTemplate
(
t
))
if
len
(
errs
)
>
0
{
t
.
Fatalf
(
"err: %#v"
,
errs
)
}
}
func
TestShutdownConfigPrepare_ShutdownTimeout
(
t
*
testing
.
T
)
{
var
c
*
ShutdownConfig
var
errs
[]
error
// Test with a bad value
c
=
testShutdownConfig
()
c
.
RawShutdownTimeout
=
"this is not good"
errs
=
c
.
Prepare
(
testConfigTemplate
(
t
))
if
len
(
errs
)
==
0
{
t
.
Fatalf
(
"should have error"
)
}
// Test with a good one
c
=
testShutdownConfig
()
c
.
RawShutdownTimeout
=
"5s"
errs
=
c
.
Prepare
(
testConfigTemplate
(
t
))
if
len
(
errs
)
>
0
{
t
.
Fatalf
(
"err: %#v"
,
errs
)
}
if
c
.
ShutdownTimeout
!=
5
*
time
.
Second
{
t
.
Fatalf
(
"bad: %s"
,
c
.
ShutdownTimeout
)
}
}
builder/vmware/iso/builder.go
View file @
7f38cea9
...
...
@@ -24,11 +24,12 @@ type Builder struct {
}
type
config
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
vmwcommon
.
OutputConfig
`mapstructure:",squash"`
vmwcommon
.
RunConfig
`mapstructure:",squash"`
vmwcommon
.
SSHConfig
`mapstructure:",squash"`
vmwcommon
.
VMXConfig
`mapstructure:",squash"`
common
.
PackerConfig
`mapstructure:",squash"`
vmwcommon
.
OutputConfig
`mapstructure:",squash"`
vmwcommon
.
RunConfig
`mapstructure:",squash"`
vmwcommon
.
ShutdownConfig
`mapstructure:",squash"`
vmwcommon
.
SSHConfig
`mapstructure:",squash"`
vmwcommon
.
VMXConfig
`mapstructure:",squash"`
DiskName
string
`mapstructure:"vmdk_name"`
DiskSize
uint
`mapstructure:"disk_size"`
...
...
@@ -44,7 +45,6 @@ type config struct {
HTTPPortMax
uint
`mapstructure:"http_port_max"`
BootCommand
[]
string
`mapstructure:"boot_command"`
SkipCompaction
bool
`mapstructure:"skip_compaction"`
ShutdownCommand
string
`mapstructure:"shutdown_command"`
ToolsUploadFlavor
string
`mapstructure:"tools_upload_flavor"`
ToolsUploadPath
string
`mapstructure:"tools_upload_path"`
VMXTemplatePath
string
`mapstructure:"vmx_template_path"`
...
...
@@ -58,11 +58,9 @@ type config struct {
RemoteUser
string
`mapstructure:"remote_username"`
RemotePassword
string
`mapstructure:"remote_password"`
RawSingleISOUrl
string
`mapstructure:"iso_url"`
RawShutdownTimeout
string
`mapstructure:"shutdown_timeout"`
RawSingleISOUrl
string
`mapstructure:"iso_url"`
shutdownTimeout
time
.
Duration
``
tpl
*
packer
.
ConfigTemplate
tpl
*
packer
.
ConfigTemplate
}
func
(
b
*
Builder
)
Prepare
(
raws
...
interface
{})
([]
string
,
error
)
{
...
...
@@ -82,6 +80,7 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
OutputConfig
.
Prepare
(
b
.
config
.
tpl
,
&
b
.
config
.
PackerConfig
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
RunConfig
.
Prepare
(
b
.
config
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
ShutdownConfig
.
Prepare
(
b
.
config
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
SSHConfig
.
Prepare
(
b
.
config
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
VMXConfig
.
Prepare
(
b
.
config
.
tpl
)
...
)
warnings
:=
make
([]
string
,
0
)
...
...
@@ -155,10 +154,8 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
"iso_checksum"
:
&
b
.
config
.
ISOChecksum
,
"iso_checksum_type"
:
&
b
.
config
.
ISOChecksumType
,
"iso_url"
:
&
b
.
config
.
RawSingleISOUrl
,
"shutdown_command"
:
&
b
.
config
.
ShutdownCommand
,
"tools_upload_flavor"
:
&
b
.
config
.
ToolsUploadFlavor
,
"vm_name"
:
&
b
.
config
.
VMName
,
"shutdown_timeout"
:
&
b
.
config
.
RawShutdownTimeout
,
"vmx_template_path"
:
&
b
.
config
.
VMXTemplatePath
,
"remote_type"
:
&
b
.
config
.
RemoteType
,
"remote_host"
:
&
b
.
config
.
RemoteHost
,
...
...
@@ -244,16 +241,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
}
if
b
.
config
.
RawShutdownTimeout
==
""
{
b
.
config
.
RawShutdownTimeout
=
"5m"
}
b
.
config
.
shutdownTimeout
,
err
=
time
.
ParseDuration
(
b
.
config
.
RawShutdownTimeout
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Failed parsing shutdown_timeout: %s"
,
err
))
}
if
_
,
err
:=
template
.
New
(
"path"
)
.
Parse
(
b
.
config
.
ToolsUploadPath
);
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"tools_upload_path invalid: %s"
,
err
))
...
...
@@ -366,7 +353,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
&
common
.
StepProvision
{},
&
vmwcommon
.
StepShutdown
{
Command
:
b
.
config
.
ShutdownCommand
,
Timeout
:
b
.
config
.
s
hutdownTimeout
,
Timeout
:
b
.
config
.
S
hutdownTimeout
,
},
&
vmwcommon
.
StepCleanFiles
{},
&
vmwcommon
.
StepCleanVMX
{},
...
...
builder/vmware/iso/builder_test.go
View file @
7f38cea9
...
...
@@ -349,47 +349,6 @@ func TestBuilderPrepare_OutputDir(t *testing.T) {
}
}
func
TestBuilderPrepare_ShutdownCommand
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
delete
(
config
,
"shutdown_command"
)
warns
,
err
:=
b
.
Prepare
(
config
)
if
err
!=
nil
{
t
.
Fatalf
(
"bad: %s"
,
err
)
}
if
len
(
warns
)
!=
1
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
}
func
TestBuilderPrepare_ShutdownTimeout
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
// Test with a bad value
config
[
"shutdown_timeout"
]
=
"this is not good"
warns
,
err
:=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
// Test with a good one
config
[
"shutdown_timeout"
]
=
"5s"
b
=
Builder
{}
warns
,
err
=
b
.
Prepare
(
config
)
if
len
(
warns
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warns
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
}
func
TestBuilderPrepare_ToolsUploadPath
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
...
...
builder/vmware/vmx/builder.go
View file @
7f38cea9
...
...
@@ -76,6 +76,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
NoPty
:
b
.
config
.
SSHSkipRequestPty
,
},
&
common
.
StepProvision
{},
&
vmwcommon
.
StepShutdown
{
Command
:
b
.
config
.
ShutdownCommand
,
Timeout
:
b
.
config
.
ShutdownTimeout
,
},
}
// Run the steps.
...
...
builder/vmware/vmx/config.go
View file @
7f38cea9
...
...
@@ -11,11 +11,12 @@ import (
// Config is the configuration structure for the builder.
type
Config
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
vmwcommon
.
OutputConfig
`mapstructure:",squash"`
vmwcommon
.
RunConfig
`mapstructure:",squash"`
vmwcommon
.
SSHConfig
`mapstructure:",squash"`
vmwcommon
.
VMXConfig
`mapstructure:",squash"`
common
.
PackerConfig
`mapstructure:",squash"`
vmwcommon
.
OutputConfig
`mapstructure:",squash"`
vmwcommon
.
RunConfig
`mapstructure:",squash"`
vmwcommon
.
ShutdownConfig
`mapstructure:",squash"`
vmwcommon
.
SSHConfig
`mapstructure:",squash"`
vmwcommon
.
VMXConfig
`mapstructure:",squash"`
SourcePath
string
`mapstructure:"source_path"`
VMName
string
`mapstructure:"vm_name"`
...
...
@@ -45,6 +46,7 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
errs
:=
common
.
CheckUnusedConfig
(
md
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
OutputConfig
.
Prepare
(
c
.
tpl
,
&
c
.
PackerConfig
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
RunConfig
.
Prepare
(
c
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
ShutdownConfig
.
Prepare
(
c
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
SSHConfig
.
Prepare
(
c
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
c
.
VMXConfig
.
Prepare
(
c
.
tpl
)
...
)
...
...
@@ -73,6 +75,11 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
// Warnings
var
warnings
[]
string
if
c
.
ShutdownCommand
==
""
{
warnings
=
append
(
warnings
,
"A shutdown_command was not specified. Without a shutdown command, Packer
\n
"
+
"will forcibly halt the virtual machine, which may result in data loss."
)
}
// Check for any errors.
if
errs
!=
nil
&&
len
(
errs
.
Errors
)
>
0
{
...
...
builder/vmware/vmx/config_test.go
View file @
7f38cea9
...
...
@@ -8,7 +8,8 @@ import (
func
testConfig
(
t
*
testing
.
T
)
map
[
string
]
interface
{}
{
return
map
[
string
]
interface
{}{
"ssh_username"
:
"foo"
,
"ssh_username"
:
"foo"
,
"shutdown_command"
:
"foo"
,
}
}
...
...
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