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
2ca48b4b
Commit
2ca48b4b
authored
Sep 01, 2013
by
Mark Peek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/openstack: don't hardcode "DFW" and make region required
parent
12e33f6c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
27 additions
and
4 deletions
+27
-4
builder/openstack/access_config.go
builder/openstack/access_config.go
+12
-3
builder/openstack/access_config_test.go
builder/openstack/access_config_test.go
+12
-0
builder/openstack/builder.go
builder/openstack/builder.go
+2
-1
builder/openstack/builder_test.go
builder/openstack/builder_test.go
+1
-0
No files found.
builder/openstack/access_config.go
View file @
2ca48b4b
...
...
@@ -9,9 +9,10 @@ import (
// AccessConfig is for common configuration related to openstack access
type
AccessConfig
struct
{
Username
string
`mapstructure:"username"`
Password
string
`mapstructure:"password"`
Provider
string
`mapstructure:"provider"`
Username
string
`mapstructure:"username"`
Password
string
`mapstructure:"password"`
Provider
string
`mapstructure:"provider"`
RawRegion
string
`mapstructure:"region"`
}
// Auth returns a valid Auth object for access to openstack services, or
...
...
@@ -40,6 +41,10 @@ func (c *AccessConfig) Auth() (gophercloud.AccessProvider, error) {
return
gophercloud
.
Authenticate
(
provider
,
authoptions
)
}
func
(
c
*
AccessConfig
)
Region
()
string
{
return
c
.
RawRegion
}
func
(
c
*
AccessConfig
)
Prepare
(
t
*
packer
.
ConfigTemplate
)
[]
error
{
if
t
==
nil
{
var
err
error
...
...
@@ -65,6 +70,10 @@ func (c *AccessConfig) Prepare(t *packer.ConfigTemplate) []error {
}
}
if
c
.
RawRegion
==
""
{
errs
=
append
(
errs
,
fmt
.
Errorf
(
"region must be specified"
))
}
if
len
(
errs
)
>
0
{
return
errs
}
...
...
builder/openstack/access_config_test.go
View file @
2ca48b4b
...
...
@@ -8,9 +8,21 @@ func testAccessConfig() *AccessConfig {
return
&
AccessConfig
{}
}
func
TestAccessConfigPrepare_NoRegion
(
t
*
testing
.
T
)
{
c
:=
testAccessConfig
()
if
err
:=
c
.
Prepare
(
nil
);
err
==
nil
{
t
.
Fatalf
(
"shouldn't have err: %s"
,
err
)
}
}
func
TestAccessConfigPrepare_Region
(
t
*
testing
.
T
)
{
dfw
:=
"DFW"
c
:=
testAccessConfig
()
c
.
RawRegion
=
dfw
if
err
:=
c
.
Prepare
(
nil
);
err
!=
nil
{
t
.
Fatalf
(
"shouldn't have err: %s"
,
err
)
}
if
dfw
!=
c
.
Region
()
{
t
.
Fatalf
(
"Regions do not match: %s %s"
,
dfw
,
c
.
Region
())
}
}
builder/openstack/builder.go
View file @
2ca48b4b
...
...
@@ -62,12 +62,13 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
}
api
:=
&
gophercloud
.
ApiCriteria
{
Name
:
"cloudServersOpenStack"
,
Region
:
"DFW"
,
Region
:
b
.
config
.
AccessConfig
.
Region
()
,
VersionId
:
"2"
,
UrlChoice
:
gophercloud
.
PublicURL
,
}
csp
,
err
:=
gophercloud
.
ServersApi
(
auth
,
*
api
)
if
err
!=
nil
{
log
.
Printf
(
"Region: %s"
,
b
.
config
.
AccessConfig
.
Region
())
return
nil
,
err
}
...
...
builder/openstack/builder_test.go
View file @
2ca48b4b
...
...
@@ -10,6 +10,7 @@ func testConfig() map[string]interface{} {
"username"
:
"foo"
,
"password"
:
"bar"
,
"provider"
:
"foo"
,
"region"
:
"DFW"
,
"image_name"
:
"foo"
,
"source_image"
:
"foo"
,
"flavor"
:
"foo"
,
...
...
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