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
489e10d6
Commit
489e10d6
authored
Dec 11, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #672 from mheidenr/master
post-processor/vsphere: post-processor for vSphere not working
parents
6a141ba5
9df6b8f0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
18 deletions
+50
-18
post-processor/vsphere/post-processor.go
post-processor/vsphere/post-processor.go
+50
-18
No files found.
post-processor/vsphere/post-processor.go
View file @
489e10d6
...
...
@@ -17,15 +17,19 @@ type Config struct {
common
.
PackerConfig
`mapstructure:",squash"`
Insecure
bool
`mapstructure:"insecure"`
Cluster
string
`mapstructure:"cluster"`
Datacenter
string
`mapstructure:"datacenter"`
Datastore
string
`mapstructure:"datastore"`
Debug
bool
`mapstructure:"debug"`
Host
string
`mapstructure:"host"`
Password
string
`mapstructure:"password"`
PathToResourcePool
string
`mapstructure:"path_to_
resource_pool"`
ResourcePool
string
`mapstructure:"
resource_pool"`
Username
string
`mapstructure:"username"`
VMFolder
string
`mapstructure:"vm_folder"`
VMName
string
`mapstructure:"vm_name"`
VMNetwork
string
`mapstructure:"vm_network"`
tpl
*
packer
.
ConfigTemplate
}
type
PostProcessor
struct
{
...
...
@@ -38,11 +42,11 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
return
err
}
tpl
,
err
:
=
packer
.
NewConfigTemplate
()
p
.
config
.
tpl
,
err
=
packer
.
NewConfigTemplate
()
if
err
!=
nil
{
return
err
}
tpl
.
UserVars
=
p
.
config
.
PackerUserVars
p
.
config
.
tpl
.
UserVars
=
p
.
config
.
PackerUserVars
// Accumulate any errors
errs
:=
new
(
packer
.
MultiError
)
...
...
@@ -53,15 +57,16 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
}
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_resource_pool"
:
&
p
.
config
.
PathToResourcePool
,
"username"
:
&
p
.
config
.
Username
,
"vm_folder"
:
&
p
.
config
.
VMFolder
,
"vm_name"
:
&
p
.
config
.
VMName
,
"cluster"
:
&
p
.
config
.
Cluster
,
"datacenter"
:
&
p
.
config
.
Datacenter
,
"datastore"
:
&
p
.
config
.
Datastore
,
"host"
:
&
p
.
config
.
Host
,
"vm_network"
:
&
p
.
config
.
VMNetwork
,
"password"
:
&
p
.
config
.
Password
,
"resource_pool"
:
&
p
.
config
.
ResourcePool
,
"username"
:
&
p
.
config
.
Username
,
"vm_folder"
:
&
p
.
config
.
VMFolder
,
"vm_name"
:
&
p
.
config
.
VMName
,
}
for
n
:=
range
validates
{
...
...
@@ -95,21 +100,48 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
return
nil
,
false
,
fmt
.
Errorf
(
"VMX file not found"
)
}
// Get user variables from template
vm_name
,
err
:=
p
.
config
.
tpl
.
Process
(
p
.
config
.
VMName
,
p
.
config
.
PackerUserVars
)
if
err
!=
nil
{
return
nil
,
false
,
fmt
.
Errorf
(
"Failed: %s"
,
err
)
}
username
,
err
:=
p
.
config
.
tpl
.
Process
(
p
.
config
.
Username
,
p
.
config
.
PackerUserVars
)
if
err
!=
nil
{
return
nil
,
false
,
fmt
.
Errorf
(
"Failed: %s"
,
err
)
}
password
,
err
:=
p
.
config
.
tpl
.
Process
(
p
.
config
.
Password
,
p
.
config
.
PackerUserVars
)
if
err
!=
nil
{
return
nil
,
false
,
fmt
.
Errorf
(
"Failed: %s"
,
err
)
}
datastore
,
err
:=
p
.
config
.
tpl
.
Process
(
p
.
config
.
Datastore
,
p
.
config
.
PackerUserVars
)
if
err
!=
nil
{
return
nil
,
false
,
fmt
.
Errorf
(
"Failed: %s"
,
err
)
}
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
.
VMN
ame
),
fmt
.
Sprintf
(
"--datastore=%s"
,
p
.
config
.
D
atastore
),
fmt
.
Sprintf
(
"--name=%s"
,
vm_n
ame
),
fmt
.
Sprintf
(
"--datastore=%s"
,
d
atastore
),
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
,
fmt
.
Sprintf
(
"%s"
,
vmx
),
fmt
.
Sprintf
(
"vi://%s:%s@%s/%s/host/%s/Resources/%s"
,
username
,
password
,
p
.
config
.
Host
,
p
.
config
.
Datacenter
,
p
.
config
.
PathToResourcePool
),
p
.
config
.
Cluster
,
p
.
config
.
ResourcePool
),
}
if
p
.
config
.
Debug
{
ui
.
Message
(
fmt
.
Sprintf
(
"DEBUG: %s"
,
args
))
}
var
out
bytes
.
Buffer
...
...
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