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
a21997db
Commit
a21997db
authored
Aug 03, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/amazon/common: refresh instance while connecting to SSH [GH-243]
parent
8a3ee293
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
8 deletions
+35
-8
builder/amazon/common/instance.go
builder/amazon/common/instance.go
+19
-2
builder/amazon/common/ssh.go
builder/amazon/common/ssh.go
+16
-6
No files found.
builder/amazon/common/instance.go
View file @
a21997db
...
@@ -9,15 +9,30 @@ import (
...
@@ -9,15 +9,30 @@ import (
"time"
"time"
)
)
// StateRefreshFunc is a function type used for StateChangeConf that is
// responsible for refreshing the item being watched for a state change.
//
// It returns three results. `result` is any object that will be returned
// as the final object after waiting for state change. This allows you to
// return the final updated object, for example an EC2 instance after refreshing
// it.
//
// `state` is the latest state of that object. And `err` is any error that
// may have happened while refreshing the state.
type
StateRefreshFunc
func
()
(
result
interface
{},
state
string
,
err
error
)
// StateChangeConf is the configuration struct used for `WaitForState`.
type
StateChangeConf
struct
{
type
StateChangeConf
struct
{
Conn
*
ec2
.
EC2
Conn
*
ec2
.
EC2
Pending
[]
string
Pending
[]
string
Refresh
func
()
(
interface
{},
string
,
error
)
Refresh
StateRefreshFunc
StepState
map
[
string
]
interface
{}
StepState
map
[
string
]
interface
{}
Target
string
Target
string
}
}
func
InstanceStateRefreshFunc
(
conn
*
ec2
.
EC2
,
i
*
ec2
.
Instance
)
func
()
(
interface
{},
string
,
error
)
{
// InstanceStateRefreshFunc returns a StateRefreshFunc that is used to watch
// an EC2 instance.
func
InstanceStateRefreshFunc
(
conn
*
ec2
.
EC2
,
i
*
ec2
.
Instance
)
StateRefreshFunc
{
return
func
()
(
interface
{},
string
,
error
)
{
return
func
()
(
interface
{},
string
,
error
)
{
resp
,
err
:=
conn
.
Instances
([]
string
{
i
.
InstanceId
},
ec2
.
NewFilter
())
resp
,
err
:=
conn
.
Instances
([]
string
{
i
.
InstanceId
},
ec2
.
NewFilter
())
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -29,6 +44,8 @@ func InstanceStateRefreshFunc(conn *ec2.EC2, i *ec2.Instance) func() (interface{
...
@@ -29,6 +44,8 @@ func InstanceStateRefreshFunc(conn *ec2.EC2, i *ec2.Instance) func() (interface{
}
}
}
}
// WaitForState watches an object and waits for it to achieve a certain
// state.
func
WaitForState
(
conf
*
StateChangeConf
)
(
i
interface
{},
err
error
)
{
func
WaitForState
(
conf
*
StateChangeConf
)
(
i
interface
{},
err
error
)
{
log
.
Printf
(
"Waiting for state to become: %s"
,
conf
.
Target
)
log
.
Printf
(
"Waiting for state to become: %s"
,
conf
.
Target
)
...
...
builder/amazon/common/ssh.go
View file @
a21997db
...
@@ -10,14 +10,24 @@ import (
...
@@ -10,14 +10,24 @@ import (
// SSHAddress returns a function that can be given to the SSH communicator
// SSHAddress returns a function that can be given to the SSH communicator
// for determining the SSH address based on the instance DNS name.
// for determining the SSH address based on the instance DNS name.
func
SSHAddress
(
port
int
)
func
(
map
[
string
]
interface
{})
(
string
,
error
)
{
func
SSHAddress
(
e
*
ec2
.
EC2
,
port
int
)
func
(
map
[
string
]
interface
{})
(
string
,
error
)
{
return
func
(
state
map
[
string
]
interface
{})
(
string
,
error
)
{
return
func
(
state
map
[
string
]
interface
{})
(
string
,
error
)
{
var
host
string
var
host
string
instance
:=
state
[
"instance"
]
.
(
*
ec2
.
Instance
)
i
:=
state
[
"instance"
]
.
(
*
ec2
.
Instance
)
if
instance
.
DNSName
!=
""
{
r
,
err
:=
e
.
Instances
([]
string
{
i
.
InstanceId
},
ec2
.
NewFilter
())
host
=
instance
.
DNSName
if
err
!=
nil
{
}
else
if
instance
.
VpcId
==
""
{
return
""
,
err
host
=
instance
.
PrivateIpAddress
}
if
len
(
r
.
Reservations
)
==
0
||
len
(
r
.
Reservations
[
0
]
.
Instances
)
==
0
{
return
""
,
fmt
.
Errorf
(
"instance not found: %s"
,
i
.
InstanceId
)
}
i
=
&
r
.
Reservations
[
0
]
.
Instances
[
0
]
if
i
.
DNSName
!=
""
{
host
=
i
.
DNSName
}
else
if
i
.
VpcId
==
""
{
host
=
i
.
PrivateIpAddress
}
else
{
}
else
{
return
""
,
errors
.
New
(
"couldn't determine IP address for instance"
)
return
""
,
errors
.
New
(
"couldn't determine IP address for instance"
)
}
}
...
...
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