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
09a2f23e
Commit
09a2f23e
authored
Jul 25, 2013
by
Dan Slimmon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made Linode inventory module much faster.
Listing no longer makes an API request for every node.
parent
d1effecb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
6 deletions
+13
-6
plugins/inventory/linode.py
+13
-6
No files found.
plugins/inventory/linode.py
View file @
09a2f23e
...
...
@@ -98,6 +98,8 @@ class LinodeInventory(object):
self
.
inventory
=
{}
# Index of label to Linode ID
self
.
index
=
{}
# Local cache of Datacenter objects populated by populate_datacenter_cache()
self
.
_datacenter_cache
=
None
# Read settings and parse CLI arguments
self
.
read_settings
()
...
...
@@ -162,7 +164,7 @@ class LinodeInventory(object):
def
get_nodes
(
self
):
"""Makes an Linode API call to get the list of nodes."""
try
:
for
node
in
Linode
.
search
():
for
node
in
Linode
.
search
(
status
=
Linode
.
STATUS_RUNNING
):
self
.
add_node
(
node
)
except
api
.
linode_api
.
ApiError
,
e
:
print
"Looks like Linode's API is down:"
...
...
@@ -180,9 +182,18 @@ class LinodeInventory(object):
print
e
sys
.
exit
(
1
)
def
populate_datacenter_cache
(
self
):
"""Creates self._datacenter_cache, containing all Datacenters indexed by ID."""
self
.
_datacenter_cache
=
{}
dcs
=
Datacenter
.
search
()
for
dc
in
dcs
:
self
.
_datacenter_cache
[
dc
.
api_id
]
=
dc
def
get_datacenter_city
(
self
,
node
):
"""Returns a the lowercase city name of the node's data center."""
location
=
node
.
datacenter
.
location
if
self
.
_datacenter_cache
is
None
:
self
.
populate_datacenter_cache
()
location
=
self
.
_datacenter_cache
[
node
.
datacenter_id
]
.
location
location
=
location
.
lower
()
location
=
location
.
split
(
","
)[
0
]
return
location
...
...
@@ -190,10 +201,6 @@ class LinodeInventory(object):
def
add_node
(
self
,
node
):
"""Adds an node to the inventory and index."""
# Only want running nodes
if
not
node
.
is_up
():
return
dest
=
node
.
label
# Add to index
...
...
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