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
b52132c6
Commit
b52132c6
authored
Nov 18, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
post-processor/vsphere: cleanups
/cc @mheidenr - Some basic cleanups. :)
parent
7d9b48e7
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
42 deletions
+44
-42
post-processor/vsphere/post-processor.go
post-processor/vsphere/post-processor.go
+43
-42
post-processor/vsphere/post-processor_test.go
post-processor/vsphere/post-processor_test.go
+1
-0
No files found.
post-processor/vsphere/post-processor.go
View file @
b52132c6
...
...
@@ -16,17 +16,16 @@ var builtins = map[string]string{
type
Config
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
Insecure
bool
`mapstructure:"insecure"`
Datacenter
string
`mapstructure:"datacenter"`
Datastore
string
`mapstructure:"datastore"`
Host
string
`mapstructure:"host"`
VMNetwork
string
`mapstructure:"vm_network"`
Password
string
`mapstructure:"password"`
PathToResoucePool
string
`mapstructure:"path_to_resouce_pool"`
Username
string
`mapstructure:"username"`
VMFolder
string
`mapstructure:"vm_folder"`
VMName
string
`mapstructure:"vm_name"`
Insecure
bool
`mapstructure:"insecure"`
Datacenter
string
`mapstructure:"datacenter"`
Datastore
string
`mapstructure:"datastore"`
Host
string
`mapstructure:"host"`
VMNetwork
string
`mapstructure:"vm_network"`
Password
string
`mapstructure:"password"`
PathToResourcePool
string
`mapstructure:"path_to_resource_pool"`
Username
string
`mapstructure:"username"`
VMFolder
string
`mapstructure:"vm_folder"`
VMName
string
`mapstructure:"vm_name"`
}
type
PostProcessor
struct
{
...
...
@@ -48,29 +47,27 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
// Accumulate any errors
errs
:=
new
(
packer
.
MultiError
)
program
:=
"ovftool"
_
,
erro
:=
exec
.
LookPath
(
program
)
if
erro
!=
nil
{
if
_
,
err
:=
exec
.
LookPath
(
"ovftool"
);
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"
Error : %s not set"
,
erro
))
errs
,
fmt
.
Errorf
(
"
ovftool not found: %s"
,
err
))
}
validates
:=
map
[
string
]
*
string
{
"datacenter"
:
&
p
.
config
.
Datacenter
,
"datastore"
:
&
p
.
config
.
Datastore
,
"host"
:
&
p
.
config
.
Host
,
"vm_network"
:
&
p
.
config
.
VMNetwork
,
"password"
:
&
p
.
config
.
Password
,
"path_to_resou
ce_pool"
:
&
p
.
config
.
PathToResou
cePool
,
"username"
:
&
p
.
config
.
Username
,
"vm_folder"
:
&
p
.
config
.
VMFolder
,
"vm_name"
:
&
p
.
config
.
VMName
,
"datacenter"
:
&
p
.
config
.
Datacenter
,
"datastore"
:
&
p
.
config
.
Datastore
,
"host"
:
&
p
.
config
.
Host
,
"vm_network"
:
&
p
.
config
.
VMNetwork
,
"password"
:
&
p
.
config
.
Password
,
"path_to_resou
rce_pool"
:
&
p
.
config
.
PathToResour
cePool
,
"username"
:
&
p
.
config
.
Username
,
"vm_folder"
:
&
p
.
config
.
VMFolder
,
"vm_name"
:
&
p
.
config
.
VMName
,
}
for
n
:=
range
validates
{
if
*
validates
[
n
]
==
""
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"
Argument %s: not
set"
,
n
))
errs
,
fmt
.
Errorf
(
"
%s must be
set"
,
n
))
}
}
...
...
@@ -82,8 +79,7 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
}
func
(
p
*
PostProcessor
)
PostProcess
(
ui
packer
.
Ui
,
artifact
packer
.
Artifact
)
(
packer
.
Artifact
,
bool
,
error
)
{
_
,
ok
:=
builtins
[
artifact
.
BuilderId
()]
if
!
ok
{
if
_
,
ok
:=
builtins
[
artifact
.
BuilderId
()];
!
ok
{
return
nil
,
false
,
fmt
.
Errorf
(
"Unknown artifact type, can't build box: %s"
,
artifact
.
BuilderId
())
}
...
...
@@ -91,6 +87,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
for
_
,
path
:=
range
artifact
.
Files
()
{
if
strings
.
HasSuffix
(
path
,
".vmx"
)
{
vmx
=
path
break
}
}
...
...
@@ -98,24 +95,28 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
return
nil
,
false
,
fmt
.
Errorf
(
"VMX file not found"
)
}
ui
.
Message
(
fmt
.
Sprintf
(
"uploading %s to vSphere"
,
vmx
))
program
:=
"ovftool"
nossl
:=
fmt
.
Sprintf
(
"--noSSLVerify=%t"
,
p
.
config
.
Insecure
)
accepteulas
:=
"--acceptAllEulas"
name
:=
"--name="
+
p
.
config
.
VMName
datastore
:=
"--datastore="
+
p
.
config
.
Datastore
network
:=
"--network="
+
p
.
config
.
VMNetwork
vm_folder
:=
"--vmFolder="
+
p
.
config
.
VMFolder
url
:=
"vi://"
+
p
.
config
.
Username
+
":"
+
p
.
config
.
Password
+
"@"
+
p
.
config
.
Host
+
"/"
+
p
.
config
.
Datacenter
+
"/"
+
p
.
config
.
PathToResoucePool
cmd
:=
exec
.
Command
(
program
,
nossl
,
accepteulas
,
name
,
datastore
,
network
,
vm_folder
,
vmx
,
url
)
ui
.
Message
(
fmt
.
Sprintf
(
"Uploading %s to vSphere"
,
vmx
))
args
:=
[]
string
{
fmt
.
Sprintf
(
"--noSSLVerify=%t"
,
p
.
config
.
Insecure
),
"--acceptAllEulas"
,
fmt
.
Sprintf
(
"--name=%s"
,
p
.
config
.
VMName
),
fmt
.
Sprintf
(
"--datastore=%s"
,
p
.
config
.
Datastore
),
fmt
.
Sprintf
(
"--network=%s"
,
p
.
config
.
VMNetwork
),
fmt
.
Sprintf
(
"--vmFolder=%s"
,
p
.
config
.
VMFolder
),
fmt
.
Sprintf
(
"vi://%s:%s@%s/%s/%s"
,
p
.
config
.
Username
,
p
.
config
.
Password
,
p
.
config
.
Host
,
p
.
config
.
Datacenter
,
p
.
config
.
PathToResourcePool
),
}
var
out
bytes
.
Buffer
cmd
:=
exec
.
Command
(
"ovftool"
,
args
...
)
cmd
.
Stdout
=
&
out
err_run
:=
cmd
.
Run
()
if
err_run
!=
nil
{
return
nil
,
false
,
fmt
.
Errorf
(
"%s"
,
out
.
String
())
if
err
:=
cmd
.
Run
();
err
!=
nil
{
return
nil
,
false
,
fmt
.
Errorf
(
"Failed: %s
\n
Stdout: %s"
,
err
,
out
.
String
())
}
ui
.
Message
(
fmt
.
Sprintf
(
"%s"
,
out
.
String
()))
...
...
post-processor/vsphere/post-processor_test.go
0 → 100644
View file @
b52132c6
package
vsphere
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