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
5167c65f
Commit
5167c65f
authored
Jun 15, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'b-openstack-privage'
parents
fc62afaa
2c683c50
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
25 deletions
+49
-25
builder/openstack/ssh.go
builder/openstack/ssh.go
+49
-25
No files found.
builder/openstack/ssh.go
View file @
5167c65f
...
...
@@ -20,6 +20,13 @@ func CommHost(
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
!=
""
{
...
...
@@ -30,32 +37,10 @@ func CommHost(
return
s
.
AccessIPv4
,
nil
}
// Get all the addresses associated with this server. This
// was taken directly from Terraform.
for
_
,
networkAddresses
:=
range
s
.
Addresses
{
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
!=
""
{
// 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
()
if
err
!=
nil
{
...
...
@@ -89,3 +74,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