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
1a45b966
Commit
1a45b966
authored
Sep 05, 2014
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/vmware: add VNC to vmx
parent
b72605c2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
31 deletions
+40
-31
builder/vmware/common/run_config.go
builder/vmware/common/run_config.go
+16
-0
builder/vmware/common/step_configure_vnc.go
builder/vmware/common/step_configure_vnc.go
+16
-15
builder/vmware/iso/builder.go
builder/vmware/iso/builder.go
+4
-16
builder/vmware/vmx/builder.go
builder/vmware/vmx/builder.go
+4
-0
No files found.
builder/vmware/common/run_config.go
View file @
1a45b966
...
...
@@ -16,6 +16,9 @@ type RunConfig struct {
HTTPPortMin
uint
`mapstructure:"http_port_min"`
HTTPPortMax
uint
`mapstructure:"http_port_max"`
VNCPortMin
uint
`mapstructure:"vnc_port_min"`
VNCPortMax
uint
`mapstructure:"vnc_port_max"`
BootWait
time
.
Duration
``
}
...
...
@@ -32,6 +35,14 @@ func (c *RunConfig) Prepare(t *packer.ConfigTemplate) []error {
c
.
HTTPPortMax
=
9000
}
if
c
.
VNCPortMin
==
0
{
c
.
VNCPortMin
=
5900
}
if
c
.
VNCPortMax
==
0
{
c
.
VNCPortMax
=
6000
}
templates
:=
map
[
string
]
*
string
{
"boot_wait"
:
&
c
.
RawBootWait
,
"http_directory"
:
&
c
.
HTTPDir
,
...
...
@@ -59,5 +70,10 @@ func (c *RunConfig) Prepare(t *packer.ConfigTemplate) []error {
errors
.
New
(
"http_port_min must be less than http_port_max"
))
}
if
c
.
VNCPortMin
>
c
.
VNCPortMax
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"vnc_port_min must be less than vnc_port_max"
))
}
return
errs
}
builder/vmware/
iso
/step_configure_vnc.go
→
builder/vmware/
common
/step_configure_vnc.go
View file @
1a45b966
package
iso
package
common
import
(
"fmt"
"github.com/mitchellh/multistep"
vmwcommon
"github.com/mitchellh/packer/builder/vmware/common"
"github.com/mitchellh/packer/packer"
"io/ioutil"
"log"
"math/rand"
"net"
"os"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
)
// This step configures the VM to enable the VNC server.
//
// Uses:
// config *config
// ui packer.Ui
// vmx_path string
//
// Produces:
// vnc_port uint - The port that VNC is configured to listen on.
type
stepConfigureVNC
struct
{}
type
StepConfigureVNC
struct
{
VNCPortMin
uint
VNCPortMax
uint
}
type
VNCAddressFinder
interface
{
VNCAddress
(
uint
,
uint
)
(
string
,
uint
,
error
)
}
func
(
s
tepConfigureVNC
)
VNCAddress
(
portMin
,
portMax
uint
)
(
string
,
uint
,
error
)
{
func
(
S
tepConfigureVNC
)
VNCAddress
(
portMin
,
portMax
uint
)
(
string
,
uint
,
error
)
{
// Find an open VNC port. Note that this can still fail later on
// because we have to release the port at some point. But this does its
// best.
...
...
@@ -50,9 +52,8 @@ func (stepConfigureVNC) VNCAddress(portMin, portMax uint) (string, uint, error)
return
"127.0.0.1"
,
vncPort
,
nil
}
func
(
s
*
stepConfigureVNC
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
config
)
driver
:=
state
.
Get
(
"driver"
)
.
(
vmwcommon
.
Driver
)
func
(
s
*
StepConfigureVNC
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
driver
:=
state
.
Get
(
"driver"
)
.
(
Driver
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
vmxPath
:=
state
.
Get
(
"vmx_path"
)
.
(
string
)
...
...
@@ -78,8 +79,8 @@ func (s *stepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction {
}
else
{
vncFinder
=
s
}
log
.
Printf
(
"Looking for available port between %d and %d"
,
config
.
VNCPortMin
,
config
.
VNCPortMax
)
vncIp
,
vncPort
,
err
:=
vncFinder
.
VNCAddress
(
config
.
VNCPortMin
,
config
.
VNCPortMax
)
log
.
Printf
(
"Looking for available port between %d and %d"
,
s
.
VNCPortMin
,
s
.
VNCPortMax
)
vncIp
,
vncPort
,
err
:=
vncFinder
.
VNCAddress
(
s
.
VNCPortMin
,
s
.
VNCPortMax
)
if
err
!=
nil
{
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
...
...
@@ -88,11 +89,11 @@ func (s *stepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction {
log
.
Printf
(
"Found available VNC port: %d"
,
vncPort
)
vmxData
:=
vmwcommon
.
ParseVMX
(
string
(
vmxBytes
))
vmxData
:=
ParseVMX
(
string
(
vmxBytes
))
vmxData
[
"remotedisplay.vnc.enabled"
]
=
"TRUE"
vmxData
[
"remotedisplay.vnc.port"
]
=
fmt
.
Sprintf
(
"%d"
,
vncPort
)
if
err
:=
vmwcommon
.
WriteVMX
(
vmxPath
,
vmxData
);
err
!=
nil
{
if
err
:=
WriteVMX
(
vmxPath
,
vmxData
);
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error writing VMX data: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
...
...
@@ -105,5 +106,5 @@ func (s *stepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction {
return
multistep
.
ActionContinue
}
func
(
s
tepConfigureVNC
)
Cleanup
(
multistep
.
StateBag
)
{
func
(
S
tepConfigureVNC
)
Cleanup
(
multistep
.
StateBag
)
{
}
builder/vmware/iso/builder.go
View file @
1a45b966
...
...
@@ -44,8 +44,6 @@ type config struct {
BootCommand
[]
string
`mapstructure:"boot_command"`
SkipCompaction
bool
`mapstructure:"skip_compaction"`
VMXTemplatePath
string
`mapstructure:"vmx_template_path"`
VNCPortMin
uint
`mapstructure:"vnc_port_min"`
VNCPortMax
uint
`mapstructure:"vnc_port_max"`
RemoteType
string
`mapstructure:"remote_type"`
RemoteDatastore
string
`mapstructure:"remote_datastore"`
...
...
@@ -112,14 +110,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
b
.
config
.
VMName
=
fmt
.
Sprintf
(
"packer-%s"
,
b
.
config
.
PackerBuildName
)
}
if
b
.
config
.
VNCPortMin
==
0
{
b
.
config
.
VNCPortMin
=
5900
}
if
b
.
config
.
VNCPortMax
==
0
{
b
.
config
.
VNCPortMax
=
6000
}
if
b
.
config
.
RemoteUser
==
""
{
b
.
config
.
RemoteUser
=
"root"
}
...
...
@@ -230,11 +220,6 @@ func (b *Builder) Prepare(raws ...interface{}) ([]string, error) {
}
if
b
.
config
.
VNCPortMin
>
b
.
config
.
VNCPortMax
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"vnc_port_min must be less than vnc_port_max"
))
}
// Remote configuration validation
if
b
.
config
.
RemoteType
!=
""
{
if
b
.
config
.
RemoteHost
==
""
{
...
...
@@ -328,7 +313,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
HTTPPortMin
:
b
.
config
.
HTTPPortMin
,
HTTPPortMax
:
b
.
config
.
HTTPPortMax
,
},
&
stepConfigureVNC
{},
&
vmwcommon
.
StepConfigureVNC
{
VNCPortMin
:
b
.
config
.
VNCPortMin
,
VNCPortMax
:
b
.
config
.
VNCPortMax
,
},
&
StepRegister
{},
&
vmwcommon
.
StepRun
{
BootWait
:
b
.
config
.
BootWait
,
...
...
builder/vmware/vmx/builder.go
View file @
1a45b966
...
...
@@ -67,6 +67,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
HTTPPortMin
:
b
.
config
.
HTTPPortMin
,
HTTPPortMax
:
b
.
config
.
HTTPPortMax
,
},
&
vmwcommon
.
StepConfigureVNC
{
VNCPortMin
:
b
.
config
.
VNCPortMin
,
VNCPortMax
:
b
.
config
.
VNCPortMax
,
},
&
StepCloneVMX
{
OutputDir
:
b
.
config
.
OutputDir
,
Path
:
b
.
config
.
SourcePath
,
...
...
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