Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
f706eba4
Commit
f706eba4
authored
Aug 01, 2014
by
Luke Sneeringer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Envirionment variable support in GCE inventory plugin.
parent
3e45791d
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
15 deletions
+33
-15
plugins/inventory/gce.py
+33
-15
No files found.
plugins/inventory/gce.py
View file @
f706eba4
...
@@ -107,27 +107,38 @@ class GceInventory(object):
...
@@ -107,27 +107,38 @@ class GceInventory(object):
sys
.
exit
(
0
)
sys
.
exit
(
0
)
# Otherwise, assume user wants all instances grouped
# Otherwise, assume user wants all instances grouped
print
self
.
json_format_dict
(
self
.
group_instances
(
))
print
(
self
.
json_format_dict
(
self
.
group_instances
()
))
sys
.
exit
(
0
)
sys
.
exit
(
0
)
def
get_gce_driver
(
self
):
def
get_gce_driver
(
self
):
'''Determine GCE authorization settings and return libcloud driver.'''
"""Determine the GCE authorization settings and return a
libcloud driver.
"""
gce_ini_default_path
=
os
.
path
.
join
(
gce_ini_default_path
=
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"gce.ini"
)
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"gce.ini"
)
gce_ini_path
=
os
.
environ
.
get
(
'GCE_INI_PATH'
,
gce_ini_default_path
)
gce_ini_path
=
os
.
environ
.
get
(
'GCE_INI_PATH'
,
gce_ini_default_path
)
config
=
ConfigParser
.
SafeConfigParser
()
# Create a ConfigParser.
# This provides empty defaults to each key, so that environment
# variable configuration (as opposed to INI configuration) is able
# to work.
config
=
ConfigParser
.
SafeConfigParser
(
defaults
=
{
'gce_service_account_email_address'
:
''
,
'gce_service_account_pem_file_path'
:
''
,
'gce_project_id'
:
''
,
'libcloud_secrets'
:
''
,
})
if
'gce'
not
in
config
.
sections
():
config
.
add_section
(
'gce'
)
config
.
read
(
gce_ini_path
)
config
.
read
(
gce_ini_path
)
# the GCE params in 'secrets.py' will override these
# Attempt to get GCE params from a configuration file, if one
# exists.
secrets_path
=
config
.
get
(
'gce'
,
'libcloud_secrets'
)
secrets_path
=
config
.
get
(
'gce'
,
'libcloud_secrets'
)
secrets_found
=
False
secrets_found
=
False
try
:
try
:
import
secrets
import
secrets
args
=
getattr
(
secrets
,
'GCE_PARAMS'
,
(
))
args
=
list
(
getattr
(
secrets
,
'GCE_PARAMS'
,
[]
))
kwargs
=
getattr
(
secrets
,
'GCE_KEYWORD_PARAMS'
,
{})
kwargs
=
getattr
(
secrets
,
'GCE_KEYWORD_PARAMS'
,
{})
secrets_found
=
True
secrets_found
=
True
except
:
except
:
...
@@ -142,24 +153,31 @@ class GceInventory(object):
...
@@ -142,24 +153,31 @@ class GceInventory(object):
sys
.
path
.
append
(
os
.
path
.
dirname
(
secrets_path
))
sys
.
path
.
append
(
os
.
path
.
dirname
(
secrets_path
))
try
:
try
:
import
secrets
import
secrets
args
=
getattr
(
secrets
,
'GCE_PARAMS'
,
(
))
args
=
list
(
getattr
(
secrets
,
'GCE_PARAMS'
,
[]
))
kwargs
=
getattr
(
secrets
,
'GCE_KEYWORD_PARAMS'
,
{})
kwargs
=
getattr
(
secrets
,
'GCE_KEYWORD_PARAMS'
,
{})
secrets_found
=
True
secrets_found
=
True
except
:
except
:
pass
pass
if
not
secrets_found
:
if
not
secrets_found
:
args
=
(
args
=
[
config
.
get
(
'gce'
,
'gce_service_account_email_address'
),
config
.
get
(
'gce'
,
'gce_service_account_email_address'
),
config
.
get
(
'gce'
,
'gce_service_account_pem_file_path'
)
config
.
get
(
'gce'
,
'gce_service_account_pem_file_path'
)
)
]
kwargs
=
{
'project'
:
config
.
get
(
'gce'
,
'gce_project_id'
)}
kwargs
=
{
'project'
:
config
.
get
(
'gce'
,
'gce_project_id'
)}
# If the appropriate environment variables are set, they override
# other configuration; process those into our args and kwargs.
args
[
0
]
=
os
.
environ
.
get
(
'GCE_EMAIL'
,
args
[
0
])
args
[
1
]
=
os
.
environ
.
get
(
'GCE_PEM_FILE_PATH'
,
args
[
1
])
kwargs
[
'project'
]
=
os
.
environ
.
get
(
'GCE_PROJECT'
,
kwargs
[
'project'
])
# Retrieve and return the GCE driver.
gce
=
get_driver
(
Provider
.
GCE
)(
*
args
,
**
kwargs
)
gce
=
get_driver
(
Provider
.
GCE
)(
*
args
,
**
kwargs
)
gce
.
connection
.
user_agent_append
(
"
%
s/
%
s"
%
(
gce
.
connection
.
user_agent_append
(
USER_AGENT_PRODUCT
,
USER_AGENT_VERSION
))
'
%
s/
%
s'
%
(
USER_AGENT_PRODUCT
,
USER_AGENT_VERSION
),
)
return
gce
return
gce
def
parse_cli_args
(
self
):
def
parse_cli_args
(
self
):
''' Command line argument processing '''
''' Command line argument processing '''
...
...
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