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
fa410f5a
Commit
fa410f5a
authored
Dec 11, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
post-processor/vsphere: template process in prepare phase
parent
53bb8a70
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
56 deletions
+35
-56
post-processor/vsphere/post-processor.go
post-processor/vsphere/post-processor.go
+35
-56
No files found.
post-processor/vsphere/post-processor.go
View file @
fa410f5a
...
@@ -16,18 +16,17 @@ var builtins = map[string]string{
...
@@ -16,18 +16,17 @@ var builtins = map[string]string{
type
Config
struct
{
type
Config
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
common
.
PackerConfig
`mapstructure:",squash"`
Insecure
bool
`mapstructure:"insecure"`
Insecure
bool
`mapstructure:"insecure"`
Cluster
string
`mapstructure:"cluster"`
Cluster
string
`mapstructure:"cluster"`
Datacenter
string
`mapstructure:"datacenter"`
Datacenter
string
`mapstructure:"datacenter"`
Datastore
string
`mapstructure:"datastore"`
Datastore
string
`mapstructure:"datastore"`
Debug
bool
`mapstructure:"debug"`
Host
string
`mapstructure:"host"`
Host
string
`mapstructure:"host"`
Password
string
`mapstructure:"password"`
Password
string
`mapstructure:"password"`
ResourcePool
string
`mapstructure:"resource_pool"`
ResourcePool
string
`mapstructure:"resource_pool"`
Username
string
`mapstructure:"username"`
Username
string
`mapstructure:"username"`
VMFolder
string
`mapstructure:"vm_folder"`
VMFolder
string
`mapstructure:"vm_folder"`
VMName
string
`mapstructure:"vm_name"`
VMName
string
`mapstructure:"vm_name"`
VMNetwork
string
`mapstructure:"vm_network"`
VMNetwork
string
`mapstructure:"vm_network"`
tpl
*
packer
.
ConfigTemplate
tpl
*
packer
.
ConfigTemplate
}
}
...
@@ -56,23 +55,29 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
...
@@ -56,23 +55,29 @@ func (p *PostProcessor) Configure(raws ...interface{}) error {
errs
,
fmt
.
Errorf
(
"ovftool not found: %s"
,
err
))
errs
,
fmt
.
Errorf
(
"ovftool not found: %s"
,
err
))
}
}
valid
ates
:=
map
[
string
]
*
string
{
templ
ates
:=
map
[
string
]
*
string
{
"cluster"
:
&
p
.
config
.
Cluster
,
"cluster"
:
&
p
.
config
.
Cluster
,
"datacenter"
:
&
p
.
config
.
Datacenter
,
"datacenter"
:
&
p
.
config
.
Datacenter
,
"datastore"
:
&
p
.
config
.
Datastore
,
"datastore"
:
&
p
.
config
.
Datastore
,
"host"
:
&
p
.
config
.
Host
,
"host"
:
&
p
.
config
.
Host
,
"vm_network"
:
&
p
.
config
.
VMNetwork
,
"vm_network"
:
&
p
.
config
.
VMNetwork
,
"password"
:
&
p
.
config
.
Password
,
"password"
:
&
p
.
config
.
Password
,
"resource_pool"
:
&
p
.
config
.
ResourcePool
,
"resource_pool"
:
&
p
.
config
.
ResourcePool
,
"username"
:
&
p
.
config
.
Username
,
"username"
:
&
p
.
config
.
Username
,
"vm_folder"
:
&
p
.
config
.
VMFolder
,
"vm_folder"
:
&
p
.
config
.
VMFolder
,
"vm_name"
:
&
p
.
config
.
VMName
,
"vm_name"
:
&
p
.
config
.
VMName
,
}
}
for
n
:=
range
valid
ates
{
for
key
,
ptr
:=
range
templ
ates
{
if
*
validates
[
n
]
==
""
{
if
*
ptr
==
""
{
errs
=
packer
.
MultiErrorAppend
(
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"%s must be set"
,
n
))
errs
,
fmt
.
Errorf
(
"%s must be set"
,
key
))
}
*
ptr
,
err
=
p
.
config
.
tpl
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
key
,
err
))
}
}
}
}
...
@@ -100,50 +105,24 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
...
@@ -100,50 +105,24 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
return
nil
,
false
,
fmt
.
Errorf
(
"VMX file not found"
)
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
{
args
:=
[]
string
{
fmt
.
Sprintf
(
"--noSSLVerify=%t"
,
p
.
config
.
Insecure
),
fmt
.
Sprintf
(
"--noSSLVerify=%t"
,
p
.
config
.
Insecure
),
"--acceptAllEulas"
,
"--acceptAllEulas"
,
fmt
.
Sprintf
(
"--name=%s"
,
vm_n
ame
),
fmt
.
Sprintf
(
"--name=%s"
,
p
.
config
.
VMN
ame
),
fmt
.
Sprintf
(
"--datastore=%s"
,
d
atastore
),
fmt
.
Sprintf
(
"--datastore=%s"
,
p
.
config
.
D
atastore
),
fmt
.
Sprintf
(
"--network=%s"
,
p
.
config
.
VMNetwork
),
fmt
.
Sprintf
(
"--network=%s"
,
p
.
config
.
VMNetwork
),
fmt
.
Sprintf
(
"--vmFolder=%s"
,
p
.
config
.
VMFolder
),
fmt
.
Sprintf
(
"--vmFolder=%s"
,
p
.
config
.
VMFolder
),
fmt
.
Sprintf
(
"%s"
,
vmx
),
fmt
.
Sprintf
(
"%s"
,
vmx
),
fmt
.
Sprintf
(
"vi://%s:%s@%s/%s/host/%s/Resources/%s"
,
fmt
.
Sprintf
(
"vi://%s:%s@%s/%s/host/%s/Resources/%s"
,
u
sername
,
p
.
config
.
U
sername
,
password
,
p
.
config
.
P
assword
,
p
.
config
.
Host
,
p
.
config
.
Host
,
p
.
config
.
Datacenter
,
p
.
config
.
Datacenter
,
p
.
config
.
Cluster
,
p
.
config
.
Cluster
,
p
.
config
.
ResourcePool
),
p
.
config
.
ResourcePool
),
}
}
if
p
.
config
.
Debug
{
ui
.
Message
(
fmt
.
Sprintf
(
"Uploading %s to vSphere"
,
vmx
))
ui
.
Message
(
fmt
.
Sprintf
(
"DEBUG: %s"
,
args
))
}
var
out
bytes
.
Buffer
var
out
bytes
.
Buffer
cmd
:=
exec
.
Command
(
"ovftool"
,
args
...
)
cmd
:=
exec
.
Command
(
"ovftool"
,
args
...
)
cmd
.
Stdout
=
&
out
cmd
.
Stdout
=
&
out
...
...
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