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
804489f7
Commit
804489f7
authored
Oct 28, 2014
by
Tom Berger
Committed by
Abhijit Menon-Sen
Aug 11, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache the results for the RackSpace dynamic inventory.
parent
f904acbd
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
2 deletions
+27
-2
contrib/inventory/rax.py
+27
-2
No files found.
contrib/inventory/rax.py
View file @
804489f7
...
@@ -167,6 +167,10 @@ except ImportError:
...
@@ -167,6 +167,10 @@ except ImportError:
print
(
'pyrax is required for this module'
)
print
(
'pyrax is required for this module'
)
sys
.
exit
(
1
)
sys
.
exit
(
1
)
from
tempfile
import
gettempdir
from
time
import
time
NON_CALLABLES
=
(
basestring
,
bool
,
dict
,
int
,
list
,
type
(
None
))
NON_CALLABLES
=
(
basestring
,
bool
,
dict
,
int
,
list
,
type
(
None
))
...
@@ -214,7 +218,7 @@ def host(regions, hostname):
...
@@ -214,7 +218,7 @@ def host(regions, hostname):
print
(
json
.
dumps
(
hostvars
,
sort_keys
=
True
,
indent
=
4
))
print
(
json
.
dumps
(
hostvars
,
sort_keys
=
True
,
indent
=
4
))
def
_list
(
regions
):
def
_list
_into_cache
(
regions
):
groups
=
collections
.
defaultdict
(
list
)
groups
=
collections
.
defaultdict
(
list
)
hostvars
=
collections
.
defaultdict
(
dict
)
hostvars
=
collections
.
defaultdict
(
dict
)
images
=
{}
images
=
{}
...
@@ -334,6 +338,24 @@ def _list(regions):
...
@@ -334,6 +338,24 @@ def _list(regions):
if
hostvars
:
if
hostvars
:
groups
[
'_meta'
]
=
{
'hostvars'
:
hostvars
}
groups
[
'_meta'
]
=
{
'hostvars'
:
hostvars
}
with
open
(
get_cache_file_path
(),
'w'
)
as
cache_file
:
json
.
dump
(
groups
,
cache_file
)
def
get_cache_file_path
():
return
os
.
path
.
join
(
gettempdir
(),
'ansible-rax.cache'
)
def
_list
(
regions
,
refresh_cache
=
True
):
if
(
not
os
.
path
.
exists
(
get_cache_file_path
())
or
refresh_cache
or
(
time
()
-
os
.
stat
(
get_cache_file_path
())[
-
1
])
>
600
):
# Cache file doesn't exist or older than 10m or refresh cache requested
_list_into_cache
(
regions
)
with
open
(
get_cache_file_path
(),
'r'
)
as
cache_file
:
groups
=
json
.
load
(
cache_file
)
print
(
json
.
dumps
(
groups
,
sort_keys
=
True
,
indent
=
4
))
print
(
json
.
dumps
(
groups
,
sort_keys
=
True
,
indent
=
4
))
...
@@ -344,6 +366,9 @@ def parse_args():
...
@@ -344,6 +366,9 @@ def parse_args():
group
.
add_argument
(
'--list'
,
action
=
'store_true'
,
group
.
add_argument
(
'--list'
,
action
=
'store_true'
,
help
=
'List active servers'
)
help
=
'List active servers'
)
group
.
add_argument
(
'--host'
,
help
=
'List details about the specific host'
)
group
.
add_argument
(
'--host'
,
help
=
'List details about the specific host'
)
parser
.
add_argument
(
'--refresh-cache'
,
action
=
'store_true'
,
default
=
False
,
help
=
(
'Force refresh of cache, making API requests to'
'RackSpace (default: False - use cache files)'
))
return
parser
.
parse_args
()
return
parser
.
parse_args
()
...
@@ -410,7 +435,7 @@ def main():
...
@@ -410,7 +435,7 @@ def main():
args
=
parse_args
()
args
=
parse_args
()
regions
=
setup
()
regions
=
setup
()
if
args
.
list
:
if
args
.
list
:
_list
(
regions
)
_list
(
regions
,
refresh_cache
=
args
.
refresh_cache
)
elif
args
.
host
:
elif
args
.
host
:
host
(
regions
,
args
.
host
)
host
(
regions
,
args
.
host
)
sys
.
exit
(
0
)
sys
.
exit
(
0
)
...
...
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