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
f55e2d2c
Commit
f55e2d2c
authored
Jun 13, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/openstack: convert to helper/comm
parent
502076c9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
64 deletions
+34
-64
builder/openstack/builder.go
builder/openstack/builder.go
+14
-9
builder/openstack/run_config.go
builder/openstack/run_config.go
+7
-34
builder/openstack/run_config_test.go
builder/openstack/run_config_test.go
+13
-21
No files found.
builder/openstack/builder.go
View file @
f55e2d2c
...
...
@@ -5,10 +5,11 @@ package openstack
import
(
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/common"
"log"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/communicator"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
...
...
@@ -19,9 +20,10 @@ const BuilderId = "mitchellh.openstack"
type
Config
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
AccessConfig
`mapstructure:",squash"`
ImageConfig
`mapstructure:",squash"`
RunConfig
`mapstructure:",squash"`
AccessConfig
`mapstructure:",squash"`
ImageConfig
`mapstructure:",squash"`
RunConfig
`mapstructure:",squash"`
ctx
interpolate
.
Context
}
...
...
@@ -88,10 +90,13 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
FloatingIpPool
:
b
.
config
.
FloatingIpPool
,
FloatingIp
:
b
.
config
.
FloatingIp
,
},
&
common
.
StepConnectSSH
{
SSHAddress
:
SSHAddress
(
computeClient
,
b
.
config
.
SSHInterface
,
b
.
config
.
SSHPort
),
SSHConfig
:
SSHConfig
(
b
.
config
.
SSHUsername
),
SSHWaitTimeout
:
b
.
config
.
SSHTimeout
(),
&
communicator
.
StepConnect
{
Config
:
&
b
.
config
.
RunConfig
.
Comm
,
SSHAddress
:
SSHAddress
(
computeClient
,
b
.
config
.
SSHInterface
,
b
.
config
.
RunConfig
.
Comm
.
SSHPort
),
SSHConfig
:
SSHConfig
(
b
.
config
.
RunConfig
.
Comm
.
SSHUsername
),
},
&
common
.
StepProvision
{},
&
stepCreateImage
{},
...
...
builder/openstack/run_config.go
View file @
f55e2d2c
...
...
@@ -2,21 +2,19 @@ package openstack
import
(
"errors"
"fmt"
"time"
"github.com/mitchellh/packer/helper/communicator"
"github.com/mitchellh/packer/template/interpolate"
)
// RunConfig contains configuration for running an instance from a source
// image and details on how to access that launched image.
type
RunConfig
struct
{
Comm
communicator
.
Config
`mapstructure:",squash"`
SSHInterface
string
`mapstructure:"ssh_interface"`
SourceImage
string
`mapstructure:"source_image"`
Flavor
string
`mapstructure:"flavor"`
RawSSHTimeout
string
`mapstructure:"ssh_timeout"`
SSHUsername
string
`mapstructure:"ssh_username"`
SSHPort
int
`mapstructure:"ssh_port"`
SSHInterface
string
`mapstructure:"ssh_interface"`
AvailabilityZone
string
`mapstructure:"availability_zone"`
RackconnectWait
bool
`mapstructure:"rackconnect_wait"`
FloatingIpPool
string
`mapstructure:"floating_ip_pool"`
...
...
@@ -27,23 +25,12 @@ type RunConfig struct {
// Not really used, but here for BC
OpenstackProvider
string
`mapstructure:"openstack_provider"`
UseFloatingIp
bool
`mapstructure:"use_floating_ip"`
// Unexported fields that are calculated from others
sshTimeout
time
.
Duration
}
func
(
c
*
RunConfig
)
Prepare
(
ctx
*
interpolate
.
Context
)
[]
error
{
// Defaults
if
c
.
SSHUsername
==
""
{
c
.
SSHUsername
=
"root"
}
if
c
.
SSHPort
==
0
{
c
.
SSHPort
=
22
}
if
c
.
RawSSHTimeout
==
""
{
c
.
RawSSHTimeout
=
"5m"
if
c
.
Comm
.
SSHUsername
==
""
{
c
.
Comm
.
SSHUsername
=
"root"
}
if
c
.
UseFloatingIp
&&
c
.
FloatingIpPool
==
""
{
...
...
@@ -51,8 +38,7 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
}
// Validation
var
err
error
errs
:=
make
([]
error
,
0
)
errs
:=
c
.
Comm
.
Prepare
(
ctx
)
if
c
.
SourceImage
==
""
{
errs
=
append
(
errs
,
errors
.
New
(
"A source_image must be specified"
))
}
...
...
@@ -61,18 +47,5 @@ func (c *RunConfig) Prepare(ctx *interpolate.Context) []error {
errs
=
append
(
errs
,
errors
.
New
(
"A flavor must be specified"
))
}
if
c
.
SSHUsername
==
""
{
errs
=
append
(
errs
,
errors
.
New
(
"An ssh_username must be specified"
))
}
c
.
sshTimeout
,
err
=
time
.
ParseDuration
(
c
.
RawSSHTimeout
)
if
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Failed parsing ssh_timeout: %s"
,
err
))
}
return
errs
}
func
(
c
*
RunConfig
)
SSHTimeout
()
time
.
Duration
{
return
c
.
sshTimeout
}
builder/openstack/run_config_test.go
View file @
f55e2d2c
...
...
@@ -3,6 +3,8 @@ package openstack
import
(
"os"
"testing"
"github.com/mitchellh/packer/helper/communicator"
)
func
init
()
{
...
...
@@ -17,7 +19,10 @@ func testRunConfig() *RunConfig {
return
&
RunConfig
{
SourceImage
:
"abcd"
,
Flavor
:
"m1.small"
,
SSHUsername
:
"root"
,
Comm
:
communicator
.
Config
{
SSHUsername
:
"foo"
,
},
}
}
...
...
@@ -47,41 +52,28 @@ func TestRunConfigPrepare_SourceImage(t *testing.T) {
func
TestRunConfigPrepare_SSHPort
(
t
*
testing
.
T
)
{
c
:=
testRunConfig
()
c
.
SSHPort
=
0
if
err
:=
c
.
Prepare
(
nil
);
len
(
err
)
!=
0
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
c
.
SSHPort
!=
22
{
t
.
Fatalf
(
"invalid value: %d"
,
c
.
SSHPort
)
}
c
.
SSHPort
=
44
c
.
Comm
.
SSHPort
=
0
if
err
:=
c
.
Prepare
(
nil
);
len
(
err
)
!=
0
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
c
.
SSHPort
!=
44
{
t
.
Fatalf
(
"invalid value: %d"
,
c
.
SSHPort
)
if
c
.
Comm
.
SSHPort
!=
22
{
t
.
Fatalf
(
"invalid value: %d"
,
c
.
Comm
.
SSHPort
)
}
}
func
TestRunConfigPrepare_SSHTimeout
(
t
*
testing
.
T
)
{
c
:=
testRunConfig
()
c
.
RawSSHTimeout
=
""
c
.
Comm
.
SSHPort
=
44
if
err
:=
c
.
Prepare
(
nil
);
len
(
err
)
!=
0
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
c
.
RawSSHTimeout
=
"bad"
if
err
:=
c
.
Prepare
(
nil
);
len
(
err
)
!=
1
{
t
.
Fatalf
(
"err: %s"
,
err
)
if
c
.
Comm
.
SSHPort
!=
44
{
t
.
Fatalf
(
"invalid value: %d"
,
c
.
Comm
.
SSHPort
)
}
}
func
TestRunConfigPrepare_SSHUsername
(
t
*
testing
.
T
)
{
c
:=
testRunConfig
()
c
.
SSHUsername
=
""
c
.
Comm
.
SSHUsername
=
""
if
err
:=
c
.
Prepare
(
nil
);
len
(
err
)
!=
0
{
t
.
Fatalf
(
"err: %s"
,
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