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
73d6da75
Commit
73d6da75
authored
Oct 24, 2014
by
Harald Laabs
Committed by
Abhijit Menon-Sen
Aug 19, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make get_group run in O(n*log(n)) instead of O(n^2) by using a cache
parent
1b810e31
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
4 deletions
+8
-4
lib/ansible/inventory/__init__.py
+8
-4
No files found.
lib/ansible/inventory/__init__.py
View file @
73d6da75
...
@@ -67,6 +67,7 @@ class Inventory(object):
...
@@ -67,6 +67,7 @@ class Inventory(object):
self
.
_groups_list
=
{}
self
.
_groups_list
=
{}
self
.
_pattern_cache
=
{}
self
.
_pattern_cache
=
{}
self
.
_vars_plugins
=
[]
self
.
_vars_plugins
=
[]
self
.
_groups_cache
=
{}
# to be set by calling set_playbook_basedir by playbook code
# to be set by calling set_playbook_basedir by playbook code
self
.
_playbook_basedir
=
None
self
.
_playbook_basedir
=
None
...
@@ -394,6 +395,7 @@ class Inventory(object):
...
@@ -394,6 +395,7 @@ class Inventory(object):
if
a
.
name
not
in
groups
:
if
a
.
name
not
in
groups
:
groups
[
a
.
name
]
=
[
h
.
name
for
h
in
a
.
get_hosts
()]
groups
[
a
.
name
]
=
[
h
.
name
for
h
in
a
.
get_hosts
()]
self
.
_groups_list
=
groups
self
.
_groups_list
=
groups
self
.
_groups_cache
=
{}
return
self
.
_groups_list
return
self
.
_groups_list
def
get_groups
(
self
):
def
get_groups
(
self
):
...
@@ -422,10 +424,11 @@ class Inventory(object):
...
@@ -422,10 +424,11 @@ class Inventory(object):
return
matching_host
return
matching_host
def
get_group
(
self
,
groupname
):
def
get_group
(
self
,
groupname
):
for
group
in
self
.
groups
:
if
not
self
.
_groups_cache
:
if
group
.
name
==
groupname
:
for
group
in
self
.
groups
:
return
group
self
.
_groups_cache
[
group
.
name
]
=
group
return
None
return
self
.
_groups_cache
.
get
(
groupname
)
def
get_group_variables
(
self
,
groupname
,
update_cached
=
False
,
vault_password
=
None
):
def
get_group_variables
(
self
,
groupname
,
update_cached
=
False
,
vault_password
=
None
):
if
groupname
not
in
self
.
_vars_per_group
or
update_cached
:
if
groupname
not
in
self
.
_vars_per_group
or
update_cached
:
...
@@ -499,6 +502,7 @@ class Inventory(object):
...
@@ -499,6 +502,7 @@ class Inventory(object):
if
group
.
name
not
in
self
.
groups_list
():
if
group
.
name
not
in
self
.
groups_list
():
self
.
groups
.
append
(
group
)
self
.
groups
.
append
(
group
)
self
.
_groups_list
=
None
# invalidate internal cache
self
.
_groups_list
=
None
# invalidate internal cache
self
.
_groups_cache
=
{}
else
:
else
:
raise
AnsibleError
(
"group already in inventory:
%
s"
%
group
.
name
)
raise
AnsibleError
(
"group already in inventory:
%
s"
%
group
.
name
)
...
...
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