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
93223510
Commit
93223510
authored
Nov 18, 2013
by
jctanner
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4936 from stoned/group-get_hosts-perf2
Improve Group.get_hosts() performance.
parents
ff24d5a1
b00bf021
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
3 deletions
+22
-3
lib/ansible/inventory/group.py
+22
-3
No files found.
lib/ansible/inventory/group.py
View file @
93223510
...
...
@@ -18,7 +18,7 @@
class
Group
(
object
):
''' a group of ansible hosts '''
__slots__
=
[
'name'
,
'hosts'
,
'vars'
,
'child_groups'
,
'parent_groups'
,
'depth'
]
__slots__
=
[
'name'
,
'hosts'
,
'vars'
,
'child_groups'
,
'parent_groups'
,
'depth'
,
'_hosts_cache'
]
def
__init__
(
self
,
name
=
None
):
...
...
@@ -28,6 +28,7 @@ class Group(object):
self
.
vars
=
{}
self
.
child_groups
=
[]
self
.
parent_groups
=
[]
self
.
clear_hosts_cache
()
if
self
.
name
is
None
:
raise
Exception
(
"group name is required"
)
...
...
@@ -41,26 +42,44 @@ class Group(object):
self
.
child_groups
.
append
(
group
)
group
.
depth
=
max
([
self
.
depth
+
1
,
group
.
depth
])
group
.
parent_groups
.
append
(
self
)
self
.
clear_hosts_cache
()
def
add_host
(
self
,
host
):
self
.
hosts
.
append
(
host
)
host
.
add_group
(
self
)
self
.
clear_hosts_cache
()
def
set_variable
(
self
,
key
,
value
):
self
.
vars
[
key
]
=
value
def
clear_hosts_cache
(
self
):
self
.
_hosts_cache
=
None
for
g
in
self
.
parent_groups
:
g
.
clear_hosts_cache
()
def
get_hosts
(
self
):
if
self
.
_hosts_cache
is
None
:
self
.
_hosts_cache
=
self
.
_get_hosts
()
return
self
.
_hosts_cache
def
_get_hosts
(
self
):
hosts
=
[]
seen
=
{}
for
kid
in
self
.
child_groups
:
kid_hosts
=
kid
.
get_hosts
()
for
kk
in
kid_hosts
:
if
kk
not
in
hosts
:
if
kk
not
in
seen
:
seen
[
kk
]
=
1
hosts
.
append
(
kk
)
for
mine
in
self
.
hosts
:
if
mine
not
in
hosts
:
if
mine
not
in
seen
:
seen
[
mine
]
=
1
hosts
.
append
(
mine
)
return
hosts
...
...
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