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
bef63846
Commit
bef63846
authored
Dec 31, 2013
by
Devin Carlen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for standard OpenStack environment variables
parent
1a57e389
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
26 deletions
+23
-26
builder/openstack/access_config.go
builder/openstack/access_config.go
+14
-26
common/config.go
common/config.go
+9
-0
No files found.
builder/openstack/access_config.go
View file @
bef63846
...
...
@@ -2,6 +2,7 @@ package openstack
import
(
"fmt"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/packer"
"github.com/rackspace/gophercloud"
"net/http"
...
...
@@ -22,39 +23,26 @@ type AccessConfig struct {
// Auth returns a valid Auth object for access to openstack services, or
// an error if the authentication couldn't be resolved.
func
(
c
*
AccessConfig
)
Auth
()
(
gophercloud
.
AccessProvider
,
error
)
{
username
:=
c
.
Username
password
:=
c
.
Password
project
:=
c
.
Project
provider
:=
c
.
Provider
proxy
:=
c
.
ProxyUrl
if
username
==
""
{
username
=
os
.
Getenv
(
"SDK_USERNAME"
)
}
if
password
==
""
{
password
=
os
.
Getenv
(
"SDK_PASSWORD"
)
}
if
project
==
""
{
project
=
os
.
Getenv
(
"SDK_PROJECT"
)
}
if
provider
==
""
{
provider
=
os
.
Getenv
(
"SDK_PROVIDER"
)
}
c
.
Username
=
common
.
CoalesceVals
(
c
.
Username
,
os
.
Getenv
(
"SDK_USERNAME"
),
os
.
Getenv
(
"OS_USERNAME"
))
c
.
Password
=
common
.
CoalesceVals
(
c
.
Password
,
os
.
Getenv
(
"SDK_PASSWORD"
),
os
.
Getenv
(
"OS_PASSWORD"
))
c
.
Project
=
common
.
CoalesceVals
(
c
.
Project
,
os
.
Getenv
(
"SDK_PROJECT"
),
os
.
Getenv
(
"OS_TENANT_NAME"
))
c
.
Provider
=
common
.
CoalesceVals
(
c
.
Provider
,
os
.
Getenv
(
"SDK_PROVIDER"
),
os
.
Getenv
(
"OS_AUTH_URL"
))
c
.
RawRegion
=
common
.
CoalesceVals
(
c
.
RawRegion
,
os
.
Getenv
(
"SDK_REGION"
),
os
.
Getenv
(
"OS_REGION_NAME"
))
authoptions
:=
gophercloud
.
AuthOptions
{
Username
:
u
sername
,
Password
:
p
assword
,
Username
:
c
.
U
sername
,
Password
:
c
.
P
assword
,
AllowReauth
:
true
,
}
if
p
roject
!=
""
{
authoptions
.
TenantName
=
p
roject
if
c
.
P
roject
!=
""
{
authoptions
.
TenantName
=
c
.
P
roject
}
// For corporate networks it may be the case where we want our API calls
// to be sent through a separate HTTP proxy than external traffic.
if
proxy
!=
""
{
url
,
err
:=
url
.
Parse
(
proxy
)
if
c
.
ProxyUrl
!=
""
{
url
,
err
:=
url
.
Parse
(
c
.
ProxyUrl
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -64,11 +52,11 @@ func (c *AccessConfig) Auth() (gophercloud.AccessProvider, error) {
http
.
DefaultTransport
=
&
http
.
Transport
{
Proxy
:
http
.
ProxyURL
(
url
)}
}
return
gophercloud
.
Authenticate
(
p
rovider
,
authoptions
)
return
gophercloud
.
Authenticate
(
c
.
P
rovider
,
authoptions
)
}
func
(
c
*
AccessConfig
)
Region
()
string
{
return
c
.
RawRegion
return
c
ommon
.
CoalesceVals
(
c
.
RawRegion
,
os
.
Getenv
(
"SDK_REGION"
),
os
.
Getenv
(
"OS_REGION_NAME"
))
}
func
(
c
*
AccessConfig
)
Prepare
(
t
*
packer
.
ConfigTemplate
)
[]
error
{
...
...
common/config.go
View file @
bef63846
...
...
@@ -194,3 +194,12 @@ func decodeConfigHook(raws []interface{}) (mapstructure.DecodeHookFunc, error) {
return
v
,
nil
},
nil
}
func
CoalesceVals
(
vals
...
string
)
string
{
for
_
,
el
:=
range
vals
{
if
el
!=
""
{
return
el
}
}
return
""
}
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