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
2c683c50
Commit
2c683c50
authored
Jun 12, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/openstack: prioritize ssh interfaces
parent
31abc93f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
33 deletions
+49
-33
builder/openstack/ssh.go
builder/openstack/ssh.go
+49
-33
No files found.
builder/openstack/ssh.go
View file @
2c683c50
...
...
@@ -21,6 +21,13 @@ func SSHAddress(
return
func
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
s
:=
state
.
Get
(
"server"
)
.
(
*
servers
.
Server
)
// If we have a specific interface, try that
if
sshinterface
!=
""
{
if
addr
:=
sshAddrFromPool
(
s
,
sshinterface
,
port
);
addr
!=
""
{
return
addr
,
nil
}
}
// If we have a floating IP, use that
ip
:=
state
.
Get
(
"access_ip"
)
.
(
*
floatingip
.
FloatingIP
)
if
ip
!=
nil
&&
ip
.
IP
!=
""
{
...
...
@@ -31,39 +38,9 @@ func SSHAddress(
return
fmt
.
Sprintf
(
"%s:%d"
,
s
.
AccessIPv4
,
port
),
nil
}
// Get all the addresses associated with this server. This
// was taken directly from Terraform.
for
pool
,
networkAddresses
:=
range
s
.
Addresses
{
// If we have an SSH interface specified, skip it if no match
if
sshinterface
!=
""
&&
pool
!=
sshinterface
{
log
.
Printf
(
"[INFO] Skipping pool %s, doesn't match requested %s"
,
pool
,
sshinterface
)
continue
}
elements
,
ok
:=
networkAddresses
.
([]
interface
{})
if
!
ok
{
log
.
Printf
(
"[ERROR] Unknown return type for address field: %#v"
,
networkAddresses
)
continue
}
for
_
,
element
:=
range
elements
{
var
addr
string
address
:=
element
.
(
map
[
string
]
interface
{})
if
address
[
"OS-EXT-IPS:type"
]
==
"floating"
{
addr
=
address
[
"addr"
]
.
(
string
)
}
else
{
if
address
[
"version"
]
.
(
float64
)
==
4
{
addr
=
address
[
"addr"
]
.
(
string
)
}
}
if
addr
!=
""
{
return
fmt
.
Sprintf
(
"%s:%d"
,
addr
,
port
),
nil
}
}
// Try to get it from the requested interface
if
addr
:=
sshAddrFromPool
(
s
,
sshinterface
,
port
);
addr
!=
""
{
return
addr
,
nil
}
s
,
err
:=
servers
.
Get
(
client
,
s
.
ID
)
.
Extract
()
...
...
@@ -98,3 +75,42 @@ func SSHConfig(username string) func(multistep.StateBag) (*ssh.ClientConfig, err
},
nil
}
}
func
sshAddrFromPool
(
s
*
servers
.
Server
,
desired
string
,
port
int
)
string
{
// Get all the addresses associated with this server. This
// was taken directly from Terraform.
for
pool
,
networkAddresses
:=
range
s
.
Addresses
{
// If we have an SSH interface specified, skip it if no match
if
desired
!=
""
&&
pool
!=
desired
{
log
.
Printf
(
"[INFO] Skipping pool %s, doesn't match requested %s"
,
pool
,
desired
)
continue
}
elements
,
ok
:=
networkAddresses
.
([]
interface
{})
if
!
ok
{
log
.
Printf
(
"[ERROR] Unknown return type for address field: %#v"
,
networkAddresses
)
continue
}
for
_
,
element
:=
range
elements
{
var
addr
string
address
:=
element
.
(
map
[
string
]
interface
{})
if
address
[
"OS-EXT-IPS:type"
]
==
"floating"
{
addr
=
address
[
"addr"
]
.
(
string
)
}
else
{
if
address
[
"version"
]
.
(
float64
)
==
4
{
addr
=
address
[
"addr"
]
.
(
string
)
}
}
if
addr
!=
""
{
return
fmt
.
Sprintf
(
"%s:%d"
,
addr
,
port
)
}
}
}
return
""
}
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