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
669f3018
Commit
669f3018
authored
Jun 13, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/digitalocean: use helper/comm
parent
e5579281
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
31 additions
and
99 deletions
+31
-99
builder/digitalocean/builder.go
builder/digitalocean/builder.go
+5
-5
builder/digitalocean/builder_test.go
builder/digitalocean/builder_test.go
+7
-47
builder/digitalocean/config.go
builder/digitalocean/config.go
+14
-42
builder/digitalocean/ssh.go
builder/digitalocean/ssh.go
+2
-2
builder/digitalocean/step_droplet_info.go
builder/digitalocean/step_droplet_info.go
+1
-1
builder/digitalocean/step_power_off.go
builder/digitalocean/step_power_off.go
+1
-1
builder/digitalocean/step_snapshot.go
builder/digitalocean/step_snapshot.go
+1
-1
No files found.
builder/digitalocean/builder.go
View file @
669f3018
...
...
@@ -6,11 +6,11 @@ package digitalocean
import
(
"fmt"
"log"
"time"
"github.com/digitalocean/godo"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/communicator"
"github.com/mitchellh/packer/packer"
"golang.org/x/oauth2"
)
...
...
@@ -53,10 +53,10 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
},
new
(
stepCreateDroplet
),
new
(
stepDropletInfo
),
&
common
.
StepConnectSSH
{
&
communicator
.
StepConnect
{
Config
:
&
b
.
config
.
Comm
,
SSHAddress
:
sshAddress
,
SSHConfig
:
sshConfig
,
SSHWaitTimeout
:
5
*
time
.
Minute
,
},
new
(
common
.
StepProvision
),
new
(
stepShutdown
),
...
...
builder/digitalocean/builder_test.go
View file @
669f3018
...
...
@@ -3,6 +3,7 @@ package digitalocean
import
(
"strconv"
"testing"
"time"
"github.com/mitchellh/packer/packer"
)
...
...
@@ -163,8 +164,8 @@ func TestBuilderPrepare_SSHUsername(t *testing.T) {
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
if
b
.
config
.
SSHUsername
!=
"root"
{
t
.
Errorf
(
"invalid: %s"
,
b
.
config
.
SSHUsername
)
if
b
.
config
.
Comm
.
SSHUsername
!=
"root"
{
t
.
Errorf
(
"invalid: %s"
,
b
.
config
.
Comm
.
SSHUsername
)
}
// Test set
...
...
@@ -178,52 +179,11 @@ func TestBuilderPrepare_SSHUsername(t *testing.T) {
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
if
b
.
config
.
SSHUsername
!=
"foo"
{
t
.
Errorf
(
"invalid: %s"
,
b
.
config
.
SSHUsername
)
if
b
.
config
.
Comm
.
SSHUsername
!=
"foo"
{
t
.
Errorf
(
"invalid: %s"
,
b
.
config
.
Comm
.
SSHUsername
)
}
}
func
TestBuilderPrepare_SSHTimeout
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
// Test default
warnings
,
err
:=
b
.
Prepare
(
config
)
if
len
(
warnings
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warnings
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
if
b
.
config
.
RawSSHTimeout
!=
"1m"
{
t
.
Errorf
(
"invalid: %s"
,
b
.
config
.
RawSSHTimeout
)
}
// Test set
config
[
"ssh_timeout"
]
=
"30s"
b
=
Builder
{}
warnings
,
err
=
b
.
Prepare
(
config
)
if
len
(
warnings
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warnings
)
}
if
err
!=
nil
{
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
// Test bad
config
[
"ssh_timeout"
]
=
"tubes"
b
=
Builder
{}
warnings
,
err
=
b
.
Prepare
(
config
)
if
len
(
warnings
)
>
0
{
t
.
Fatalf
(
"bad: %#v"
,
warnings
)
}
if
err
==
nil
{
t
.
Fatal
(
"should have error"
)
}
}
func
TestBuilderPrepare_StateTimeout
(
t
*
testing
.
T
)
{
var
b
Builder
config
:=
testConfig
()
...
...
@@ -237,8 +197,8 @@ func TestBuilderPrepare_StateTimeout(t *testing.T) {
t
.
Fatalf
(
"should not have error: %s"
,
err
)
}
if
b
.
config
.
RawStateTimeout
!=
"6m"
{
t
.
Errorf
(
"invalid: %s"
,
b
.
config
.
Raw
StateTimeout
)
if
b
.
config
.
StateTimeout
!=
6
*
time
.
Minute
{
t
.
Errorf
(
"invalid: %s"
,
b
.
config
.
StateTimeout
)
}
// Test set
...
...
builder/digitalocean/config.go
View file @
669f3018
...
...
@@ -9,6 +9,7 @@ import (
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/common/uuid"
"github.com/mitchellh/packer/helper/communicator"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
...
...
@@ -16,6 +17,7 @@ import (
type
Config
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
Comm
communicator
.
Config
`mapstructure:",squash"`
APIToken
string
`mapstructure:"api_token"`
...
...
@@ -25,18 +27,9 @@ type Config struct {
PrivateNetworking
bool
`mapstructure:"private_networking"`
SnapshotName
string
`mapstructure:"snapshot_name"`
StateTimeout
time
.
Duration
`mapstructure:"state_timeout"`
DropletName
string
`mapstructure:"droplet_name"`
UserData
string
`mapstructure:"user_data"`
SSHUsername
string
`mapstructure:"ssh_username"`
SSHPort
uint
`mapstructure:"ssh_port"`
RawSSHTimeout
string
`mapstructure:"ssh_timeout"`
RawStateTimeout
string
`mapstructure:"state_timeout"`
// These are unexported since they're set by other fields
// being set.
sshTimeout
time
.
Duration
stateTimeout
time
.
Duration
ctx
*
interpolate
.
Context
}
...
...
@@ -79,29 +72,22 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
c
.
DropletName
=
fmt
.
Sprintf
(
"packer-%s"
,
uuid
.
TimeOrderedUUID
())
}
if
c
.
SSHUsername
==
""
{
if
c
.
Comm
.
SSHUsername
==
""
{
// Default to "root". You can override this if your
// SourceImage has a different user account then the DO default
c
.
SSHUsername
=
"root"
}
if
c
.
SSHPort
==
0
{
// Default to port 22 per DO default
c
.
SSHPort
=
22
c
.
Comm
.
SSHUsername
=
"root"
}
if
c
.
RawSSHTimeout
==
""
{
// Default to 1 minute timeouts
c
.
RawSSHTimeout
=
"1m"
}
if
c
.
RawStateTimeout
==
""
{
if
c
.
StateTimeout
==
0
{
// Default to 6 minute timeouts waiting for
// desired state. i.e waiting for droplet to become active
c
.
RawStateTimeout
=
"6m"
c
.
StateTimeout
=
6
*
time
.
Minute
}
var
errs
*
packer
.
MultiError
if
es
:=
c
.
Comm
.
Prepare
(
c
.
ctx
);
len
(
es
)
>
0
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
es
...
)
}
if
c
.
APIToken
==
""
{
// Required configurations that will display errors if not set
errs
=
packer
.
MultiErrorAppend
(
...
...
@@ -123,20 +109,6 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
errs
,
errors
.
New
(
"image is required"
))
}
sshTimeout
,
err
:=
time
.
ParseDuration
(
c
.
RawSSHTimeout
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Failed parsing ssh_timeout: %s"
,
err
))
}
c
.
sshTimeout
=
sshTimeout
stateTimeout
,
err
:=
time
.
ParseDuration
(
c
.
RawStateTimeout
)
if
err
!=
nil
{
errs
=
packer
.
MultiErrorAppend
(
errs
,
fmt
.
Errorf
(
"Failed parsing state_timeout: %s"
,
err
))
}
c
.
stateTimeout
=
stateTimeout
if
errs
!=
nil
&&
len
(
errs
.
Errors
)
>
0
{
return
nil
,
nil
,
errs
}
...
...
builder/digitalocean/ssh.go
View file @
669f3018
...
...
@@ -9,7 +9,7 @@ import (
func
sshAddress
(
state
multistep
.
StateBag
)
(
string
,
error
)
{
config
:=
state
.
Get
(
"config"
)
.
(
Config
)
ipAddress
:=
state
.
Get
(
"droplet_ip"
)
.
(
string
)
return
fmt
.
Sprintf
(
"%s:%d"
,
ipAddress
,
config
.
SSHPort
),
nil
return
fmt
.
Sprintf
(
"%s:%d"
,
ipAddress
,
config
.
Comm
.
SSHPort
),
nil
}
func
sshConfig
(
state
multistep
.
StateBag
)
(
*
ssh
.
ClientConfig
,
error
)
{
...
...
@@ -22,7 +22,7 @@ func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) {
}
return
&
ssh
.
ClientConfig
{
User
:
config
.
SSHUsername
,
User
:
config
.
Comm
.
SSHUsername
,
Auth
:
[]
ssh
.
AuthMethod
{
ssh
.
PublicKeys
(
signer
),
},
...
...
builder/digitalocean/step_droplet_info.go
View file @
669f3018
...
...
@@ -18,7 +18,7 @@ func (s *stepDropletInfo) Run(state multistep.StateBag) multistep.StepAction {
ui
.
Say
(
"Waiting for droplet to become active..."
)
err
:=
waitForDropletState
(
"active"
,
dropletId
,
client
,
c
.
s
tateTimeout
)
err
:=
waitForDropletState
(
"active"
,
dropletId
,
client
,
c
.
S
tateTimeout
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for droplet to become active: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
...
...
builder/digitalocean/step_power_off.go
View file @
669f3018
...
...
@@ -42,7 +42,7 @@ func (s *stepPowerOff) Run(state multistep.StateBag) multistep.StepAction {
}
log
.
Println
(
"Waiting for poweroff event to complete..."
)
err
=
waitForDropletState
(
"off"
,
dropletId
,
client
,
c
.
s
tateTimeout
)
err
=
waitForDropletState
(
"off"
,
dropletId
,
client
,
c
.
S
tateTimeout
)
if
err
!=
nil
{
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
...
...
builder/digitalocean/step_snapshot.go
View file @
669f3018
...
...
@@ -41,7 +41,7 @@ func (s *stepSnapshot) Run(state multistep.StateBag) multistep.StepAction {
// With the pending state over, verify that we're in the active state
ui
.
Say
(
"Waiting for snapshot to complete..."
)
err
=
waitForDropletState
(
"active"
,
dropletId
,
client
,
c
.
s
tateTimeout
)
err
=
waitForDropletState
(
"active"
,
dropletId
,
client
,
c
.
S
tateTimeout
)
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error waiting for snapshot to complete: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
...
...
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