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
caca5032
Commit
caca5032
authored
Sep 05, 2014
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1426 from jasonberanek/vnc-fixes
vmware-iso/esxi: fix multiple issues with VNC address discovery
parents
cf731bf6
ebdfa2bc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
22 deletions
+52
-22
builder/vmware/iso/driver_esx5.go
builder/vmware/iso/driver_esx5.go
+41
-14
builder/vmware/iso/step_configure_vnc.go
builder/vmware/iso/step_configure_vnc.go
+11
-8
No files found.
builder/vmware/iso/driver_esx5.go
View file @
caca5032
...
...
@@ -16,7 +16,6 @@ import (
"os"
"path/filepath"
"strings"
"syscall"
"time"
)
...
...
@@ -148,29 +147,57 @@ func (d *ESX5Driver) HostIP() (string, error) {
return
host
,
err
}
func
(
d
*
ESX5Driver
)
VNCAddress
(
portMin
,
portMax
uint
)
(
string
,
uint
)
{
func
(
d
*
ESX5Driver
)
VNCAddress
(
portMin
,
portMax
uint
)
(
string
,
uint
,
error
)
{
var
vncPort
uint
// TODO(dougm) use esxcli network ip connection list
//Process ports ESXi is listening on to determine which are available
r
,
err
:=
d
.
esxcli
(
"network"
,
"ip"
,
"connection"
,
"list"
)
if
err
!=
nil
{
err
=
fmt
.
Errorf
(
"Could not retrieve network information for ESXi: %v"
,
err
)
return
""
,
0
,
err
}
listenPorts
:=
make
(
map
[
string
]
bool
)
for
record
,
err
:=
r
.
read
();
record
!=
nil
&&
err
==
nil
;
record
,
err
=
r
.
read
()
{
if
record
[
"State"
]
==
"LISTEN"
{
splitAddress
:=
strings
.
Split
(
record
[
"LocalAddress"
],
":"
)
log
.
Print
(
splitAddress
)
port
:=
splitAddress
[
len
(
splitAddress
)
-
1
]
log
.
Printf
(
"ESXi Listening on: %s"
,
port
)
listenPorts
[
port
]
=
true
}
}
for
port
:=
portMin
;
port
<=
portMax
;
port
++
{
if
_
,
ok
:=
listenPorts
[
fmt
.
Sprintf
(
"%d"
,
port
)];
ok
{
log
.
Printf
(
"Port %d in use"
,
port
)
continue
}
address
:=
fmt
.
Sprintf
(
"%s:%d"
,
d
.
Host
,
port
)
log
.
Printf
(
"Trying address: %s..."
,
address
)
l
,
err
:=
net
.
DialTimeout
(
"tcp"
,
address
,
1
*
time
.
Second
)
if
err
==
nil
{
log
.
Printf
(
"%s in use"
,
address
)
l
.
Close
()
}
else
if
e
,
ok
:=
err
.
(
*
net
.
OpError
);
ok
{
if
e
.
Err
==
syscall
.
ECONNREFUSED
{
// then port should be available for listening
vncPort
=
port
break
}
else
if
e
.
Timeout
()
{
log
.
Printf
(
"Timeout connecting to: %s (check firewall rules)"
,
address
)
if
err
!=
nil
{
if
e
,
ok
:=
err
.
(
*
net
.
OpError
);
ok
{
if
e
.
Timeout
()
{
log
.
Printf
(
"Timeout connecting to: %s (check firewall rules)"
,
address
)
}
else
{
vncPort
=
port
break
}
}
}
else
{
defer
l
.
Close
()
}
}
return
d
.
Host
,
vncPort
if
vncPort
==
0
{
err
:=
fmt
.
Errorf
(
"Unable to find available VNC port between %d and %d"
,
portMin
,
portMax
)
return
d
.
Host
,
vncPort
,
err
}
return
d
.
Host
,
vncPort
,
nil
}
func
(
d
*
ESX5Driver
)
SSHAddress
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
...
...
builder/vmware/iso/step_configure_vnc.go
View file @
caca5032
...
...
@@ -24,17 +24,22 @@ import (
type
stepConfigureVNC
struct
{}
type
VNCAddressFinder
interface
{
VNCAddress
(
uint
,
uint
)
(
string
,
uint
)
VNCAddress
(
uint
,
uint
)
(
string
,
uint
,
error
)
}
func
(
stepConfigureVNC
)
VNCAddress
(
portMin
,
portMax
uint
)
(
string
,
uint
)
{
func
(
stepConfigureVNC
)
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.
var
vncPort
uint
portRange
:=
int
(
portMax
-
portMin
)
for
{
vncPort
=
uint
(
rand
.
Intn
(
portRange
))
+
portMin
if
portRange
>
0
{
vncPort
=
uint
(
rand
.
Intn
(
portRange
))
+
portMin
}
else
{
vncPort
=
portMin
}
log
.
Printf
(
"Trying port: %d"
,
vncPort
)
l
,
err
:=
net
.
Listen
(
"tcp"
,
fmt
.
Sprintf
(
":%d"
,
vncPort
))
if
err
==
nil
{
...
...
@@ -42,7 +47,7 @@ func (stepConfigureVNC) VNCAddress(portMin, portMax uint) (string, uint) {
break
}
}
return
"127.0.0.1"
,
vncPort
return
"127.0.0.1"
,
vncPort
,
nil
}
func
(
s
*
stepConfigureVNC
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
...
...
@@ -74,10 +79,8 @@ func (s *stepConfigureVNC) Run(state multistep.StateBag) multistep.StepAction {
vncFinder
=
s
}
log
.
Printf
(
"Looking for available port between %d and %d"
,
config
.
VNCPortMin
,
config
.
VNCPortMax
)
vncIp
,
vncPort
:=
vncFinder
.
VNCAddress
(
config
.
VNCPortMin
,
config
.
VNCPortMax
)
if
vncPort
==
0
{
err
:=
fmt
.
Errorf
(
"Unable to find available VNC port between %d and %d"
,
config
.
VNCPortMin
,
config
.
VNCPortMax
)
vncIp
,
vncPort
,
err
:=
vncFinder
.
VNCAddress
(
config
.
VNCPortMin
,
config
.
VNCPortMax
)
if
err
!=
nil
{
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
...
...
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