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
3b29fa5e
Commit
3b29fa5e
authored
May 27, 2015
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/openstack: convert interpolation
parent
31bdb485
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
24 additions
and
100 deletions
+24
-100
builder/openstack/access_config.go
builder/openstack/access_config.go
+3
-31
builder/openstack/builder.go
builder/openstack/builder.go
+14
-16
builder/openstack/image_config.go
builder/openstack/image_config.go
+3
-23
builder/openstack/run_config.go
builder/openstack/run_config.go
+3
-29
builder/openstack/step_create_image.go
builder/openstack/step_create_image.go
+1
-1
No files found.
builder/openstack/access_config.go
View file @
3b29fa5e
...
...
@@ -3,14 +3,14 @@ package openstack
import
(
"crypto/tls"
"fmt"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"net/http"
"net/url"
"os"
"strings"
"github.com/mitchellh/gophercloud-fork-40444fb"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/template/interpolate"
)
// AccessConfig is for common configuration related to openstack access
...
...
@@ -86,36 +86,8 @@ func (c *AccessConfig) Region() string {
return
common
.
ChooseString
(
c
.
RawRegion
,
os
.
Getenv
(
"SDK_REGION"
),
os
.
Getenv
(
"OS_REGION_NAME"
))
}
func
(
c
*
AccessConfig
)
Prepare
(
t
*
packer
.
ConfigTemplate
)
[]
error
{
if
t
==
nil
{
var
err
error
t
,
err
=
packer
.
NewConfigTemplate
()
if
err
!=
nil
{
return
[]
error
{
err
}
}
}
templates
:=
map
[
string
]
*
string
{
"username"
:
&
c
.
Username
,
"password"
:
&
c
.
Password
,
"api_key"
:
&
c
.
ApiKey
,
"provider"
:
&
c
.
Provider
,
"project"
:
&
c
.
Project
,
"tenant_id"
:
&
c
.
TenantId
,
"region"
:
&
c
.
RawRegion
,
"proxy_url"
:
&
c
.
ProxyUrl
,
}
func
(
c
*
AccessConfig
)
Prepare
(
ctx
*
interpolate
.
Context
)
[]
error
{
errs
:=
make
([]
error
,
0
)
for
n
,
ptr
:=
range
templates
{
var
err
error
*
ptr
,
err
=
t
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
n
,
err
))
}
}
if
strings
.
HasPrefix
(
c
.
Provider
,
"rackspace"
)
{
if
c
.
Region
()
==
""
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"region must be specified when using rackspace"
))
...
...
builder/openstack/builder.go
View file @
3b29fa5e
...
...
@@ -7,46 +7,44 @@ import (
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"log"
"github.com/mitchellh/gophercloud-fork-40444fb"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
)
// The unique ID for this builder
const
BuilderId
=
"mitchellh.openstack"
type
c
onfig
struct
{
type
C
onfig
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
AccessConfig
`mapstructure:",squash"`
ImageConfig
`mapstructure:",squash"`
RunConfig
`mapstructure:",squash"`
tpl
*
packer
.
ConfigTemplate
ctx
interpolate
.
Context
}
type
Builder
struct
{
config
c
onfig
config
C
onfig
runner
multistep
.
Runner
}
func
(
b
*
Builder
)
Prepare
(
raws
...
interface
{})
([]
string
,
error
)
{
md
,
err
:=
common
.
DecodeConfig
(
&
b
.
config
,
raws
...
)
if
err
!=
nil
{
return
nil
,
err
}
b
.
config
.
tpl
,
err
=
packer
.
NewConfigTemplate
()
err
:=
config
.
Decode
(
&
b
.
config
,
&
config
.
DecodeOpts
{
Interpolate
:
true
,
},
raws
...
)
if
err
!=
nil
{
return
nil
,
err
}
b
.
config
.
tpl
.
UserVars
=
b
.
config
.
PackerUserVars
// Accumulate any errors
errs
:=
common
.
CheckUnusedConfig
(
md
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
AccessConfig
.
Prepare
(
b
.
config
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
ImageConfig
.
Prepare
(
b
.
config
.
tpl
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
RunConfig
.
Prepare
(
b
.
config
.
tpl
)
...
)
var
errs
*
packer
.
MultiError
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
AccessConfig
.
Prepare
(
&
b
.
config
.
ctx
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
ImageConfig
.
Prepare
(
&
b
.
config
.
ctx
)
...
)
errs
=
packer
.
MultiErrorAppend
(
errs
,
b
.
config
.
RunConfig
.
Prepare
(
&
b
.
config
.
ctx
)
...
)
if
errs
!=
nil
&&
len
(
errs
.
Errors
)
>
0
{
return
nil
,
errs
...
...
@@ -96,7 +94,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
Networks
:
b
.
config
.
Networks
,
},
&
StepWaitForRackConnect
{
Wait
:
b
.
config
.
RackconnectWait
,
Wait
:
b
.
config
.
RackconnectWait
,
},
&
StepAllocateIp
{
FloatingIpPool
:
b
.
config
.
FloatingIpPool
,
...
...
builder/openstack/image_config.go
View file @
3b29fa5e
...
...
@@ -2,7 +2,8 @@ package openstack
import
(
"fmt"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
)
// ImageConfig is for common configuration related to creating Images.
...
...
@@ -10,29 +11,8 @@ type ImageConfig struct {
ImageName
string
`mapstructure:"image_name"`
}
func
(
c
*
ImageConfig
)
Prepare
(
t
*
packer
.
ConfigTemplate
)
[]
error
{
if
t
==
nil
{
var
err
error
t
,
err
=
packer
.
NewConfigTemplate
()
if
err
!=
nil
{
return
[]
error
{
err
}
}
}
templates
:=
map
[
string
]
*
string
{
"image_name"
:
&
c
.
ImageName
,
}
func
(
c
*
ImageConfig
)
Prepare
(
ctx
*
interpolate
.
Context
)
[]
error
{
errs
:=
make
([]
error
,
0
)
for
n
,
ptr
:=
range
templates
{
var
err
error
*
ptr
,
err
=
t
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
n
,
err
))
}
}
if
c
.
ImageName
==
""
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"An image_name must be specified"
))
}
...
...
builder/openstack/run_config.go
View file @
3b29fa5e
...
...
@@ -3,8 +3,9 @@ package openstack
import
(
"errors"
"fmt"
"github.com/mitchellh/packer/packer"
"time"
"github.com/mitchellh/packer/template/interpolate"
)
// RunConfig contains configuration for running an instance from a source
...
...
@@ -28,15 +29,7 @@ type RunConfig struct {
sshTimeout
time
.
Duration
}
func
(
c
*
RunConfig
)
Prepare
(
t
*
packer
.
ConfigTemplate
)
[]
error
{
if
t
==
nil
{
var
err
error
t
,
err
=
packer
.
NewConfigTemplate
()
if
err
!=
nil
{
return
[]
error
{
err
}
}
}
func
(
c
*
RunConfig
)
Prepare
(
ctx
*
interpolate
.
Context
)
[]
error
{
// Defaults
if
c
.
SSHUsername
==
""
{
c
.
SSHUsername
=
"root"
...
...
@@ -69,25 +62,6 @@ func (c *RunConfig) Prepare(t *packer.ConfigTemplate) []error {
errs
=
append
(
errs
,
errors
.
New
(
"An ssh_username must be specified"
))
}
templates
:=
map
[
string
]
*
string
{
"flavor"
:
&
c
.
Flavor
,
"ssh_timeout"
:
&
c
.
RawSSHTimeout
,
"ssh_username"
:
&
c
.
SSHUsername
,
"ssh_interface"
:
&
c
.
SSHInterface
,
"source_image"
:
&
c
.
SourceImage
,
"openstack_provider"
:
&
c
.
OpenstackProvider
,
"floating_ip_pool"
:
&
c
.
FloatingIpPool
,
"floating_ip"
:
&
c
.
FloatingIp
,
}
for
n
,
ptr
:=
range
templates
{
var
err
error
*
ptr
,
err
=
t
.
Process
(
*
ptr
,
nil
)
if
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Error processing %s: %s"
,
n
,
err
))
}
}
c
.
sshTimeout
,
err
=
time
.
ParseDuration
(
c
.
RawSSHTimeout
)
if
err
!=
nil
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"Failed parsing ssh_timeout: %s"
,
err
))
...
...
builder/openstack/step_create_image.go
View file @
3b29fa5e
...
...
@@ -14,7 +14,7 @@ type stepCreateImage struct{}
func
(
s
*
stepCreateImage
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
csp
:=
state
.
Get
(
"csp"
)
.
(
gophercloud
.
CloudServersProvider
)
config
:=
state
.
Get
(
"config"
)
.
(
c
onfig
)
config
:=
state
.
Get
(
"config"
)
.
(
C
onfig
)
server
:=
state
.
Get
(
"server"
)
.
(
*
gophercloud
.
Server
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
...
...
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