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
7d9b48e7
Commit
7d9b48e7
authored
Nov 18, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fmt
parent
6232d064
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
106 additions
and
106 deletions
+106
-106
post-processor/vsphere/post-processor.go
post-processor/vsphere/post-processor.go
+106
-106
No files found.
post-processor/vsphere/post-processor.go
View file @
7d9b48e7
package
vsphere
package
vsphere
import
(
import
(
"bytes"
"bytes"
"fmt"
"fmt"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/packer"
"os/exec"
"os/exec"
"strings"
"strings"
)
)
var
builtins
=
map
[
string
]
string
{
var
builtins
=
map
[
string
]
string
{
"mitchellh.vmware"
:
"vmware"
,
"mitchellh.vmware"
:
"vmware"
,
}
}
type
Config
struct
{
type
Config
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
common
.
PackerConfig
`mapstructure:",squash"`
Insecure
bool
`mapstructure:"insecure"`
Insecure
bool
`mapstructure:"insecure"`
Datacenter
string
`mapstructure:"datacenter"`
Datacenter
string
`mapstructure:"datacenter"`
Datastore
string
`mapstructure:"datastore"`
Datastore
string
`mapstructure:"datastore"`
Host
string
`mapstructure:"host"`
Host
string
`mapstructure:"host"`
VMNetwork
string
`mapstructure:"vm_network"`
VMNetwork
string
`mapstructure:"vm_network"`
Password
string
`mapstructure:"password"`
Password
string
`mapstructure:"password"`
PathToResoucePool
string
`mapstructure:"path_to_resouce_pool"`
PathToResoucePool
string
`mapstructure:"path_to_resouce_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"`
}
}
type
PostProcessor
struct
{
type
PostProcessor
struct
{
config
Config
config
Config
}
}
func
(
p
*
PostProcessor
)
Configure
(
raws
...
interface
{})
error
{
func
(
p
*
PostProcessor
)
Configure
(
raws
...
interface
{})
error
{
_
,
err
:=
common
.
DecodeConfig
(
&
p
.
config
,
raws
...
)
_
,
err
:=
common
.
DecodeConfig
(
&
p
.
config
,
raws
...
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
tpl
,
err
:=
packer
.
NewConfigTemplate
()
tpl
,
err
:=
packer
.
NewConfigTemplate
()
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
tpl
.
UserVars
=
p
.
config
.
PackerUserVars
tpl
.
UserVars
=
p
.
config
.
PackerUserVars
// Accumulate any errors
// Accumulate any errors
errs
:=
new
(
packer
.
MultiError
)
errs
:=
new
(
packer
.
MultiError
)
program
:=
"ovftool"
program
:=
"ovftool"
_
,
erro
:=
exec
.
LookPath
(
program
)
_
,
erro
:=
exec
.
LookPath
(
program
)
if
erro
!=
nil
{
if
erro
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Error : %s not set"
,
erro
))
errs
,
fmt
.
Errorf
(
"Error : %s not set"
,
erro
))
}
}
validates
:=
map
[
string
]
*
string
{
validates
:=
map
[
string
]
*
string
{
"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
,
"path_to_resouce_pool"
:
&
p
.
config
.
PathToResoucePool
,
"path_to_resouce_pool"
:
&
p
.
config
.
PathToResoucePool
,
"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
validates
{
for
n
:=
range
validates
{
if
*
validates
[
n
]
==
""
{
if
*
validates
[
n
]
==
""
{
errs
=
packer
.
MultiErrorAppend
(
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Argument %s: not set"
,
n
))
errs
,
fmt
.
Errorf
(
"Argument %s: not set"
,
n
))
}
}
}
}
if
len
(
errs
.
Errors
)
>
0
{
if
len
(
errs
.
Errors
)
>
0
{
return
errs
return
errs
}
}
return
nil
return
nil
}
}
func
(
p
*
PostProcessor
)
PostProcess
(
ui
packer
.
Ui
,
artifact
packer
.
Artifact
)
(
packer
.
Artifact
,
bool
,
error
)
{
func
(
p
*
PostProcessor
)
PostProcess
(
ui
packer
.
Ui
,
artifact
packer
.
Artifact
)
(
packer
.
Artifact
,
bool
,
error
)
{
_
,
ok
:=
builtins
[
artifact
.
BuilderId
()]
_
,
ok
:=
builtins
[
artifact
.
BuilderId
()]
if
!
ok
{
if
!
ok
{
return
nil
,
false
,
fmt
.
Errorf
(
"Unknown artifact type, can't build box: %s"
,
artifact
.
BuilderId
())
return
nil
,
false
,
fmt
.
Errorf
(
"Unknown artifact type, can't build box: %s"
,
artifact
.
BuilderId
())
}
}
vmx
:=
""
vmx
:=
""
for
_
,
path
:=
range
artifact
.
Files
()
{
for
_
,
path
:=
range
artifact
.
Files
()
{
if
strings
.
HasSuffix
(
path
,
".vmx"
)
{
if
strings
.
HasSuffix
(
path
,
".vmx"
)
{
vmx
=
path
vmx
=
path
}
}
}
}
if
vmx
==
""
{
if
vmx
==
""
{
return
nil
,
false
,
fmt
.
Errorf
(
"VMX file not found"
)
return
nil
,
false
,
fmt
.
Errorf
(
"VMX file not found"
)
}
}
ui
.
Message
(
fmt
.
Sprintf
(
"uploading %s to vSphere"
,
vmx
))
ui
.
Message
(
fmt
.
Sprintf
(
"uploading %s to vSphere"
,
vmx
))
program
:=
"ovftool"
program
:=
"ovftool"
nossl
:=
fmt
.
Sprintf
(
"--noSSLVerify=%t"
,
p
.
config
.
Insecure
)
nossl
:=
fmt
.
Sprintf
(
"--noSSLVerify=%t"
,
p
.
config
.
Insecure
)
accepteulas
:=
"--acceptAllEulas"
accepteulas
:=
"--acceptAllEulas"
name
:=
"--name="
+
p
.
config
.
VMName
name
:=
"--name="
+
p
.
config
.
VMName
datastore
:=
"--datastore="
+
p
.
config
.
Datastore
datastore
:=
"--datastore="
+
p
.
config
.
Datastore
network
:=
"--network="
+
p
.
config
.
VMNetwork
network
:=
"--network="
+
p
.
config
.
VMNetwork
vm_folder
:=
"--vmFolder="
+
p
.
config
.
VMFolder
vm_folder
:=
"--vmFolder="
+
p
.
config
.
VMFolder
url
:=
"vi://"
+
p
.
config
.
Username
+
":"
+
p
.
config
.
Password
+
"@"
+
p
.
config
.
Host
+
"/"
+
p
.
config
.
Datacenter
+
"/"
+
p
.
config
.
PathToResoucePool
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
)
cmd
:=
exec
.
Command
(
program
,
nossl
,
accepteulas
,
name
,
datastore
,
network
,
vm_folder
,
vmx
,
url
)
var
out
bytes
.
Buffer
var
out
bytes
.
Buffer
cmd
.
Stdout
=
&
out
cmd
.
Stdout
=
&
out
err_run
:=
cmd
.
Run
()
err_run
:=
cmd
.
Run
()
if
err_run
!=
nil
{
if
err_run
!=
nil
{
return
nil
,
false
,
fmt
.
Errorf
(
"%s"
,
out
.
String
())
return
nil
,
false
,
fmt
.
Errorf
(
"%s"
,
out
.
String
())
}
}
ui
.
Message
(
fmt
.
Sprintf
(
"%s"
,
out
.
String
()))
ui
.
Message
(
fmt
.
Sprintf
(
"%s"
,
out
.
String
()))
return
artifact
,
false
,
nil
return
artifact
,
false
,
nil
}
}
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