1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Visit all network class not just direct sub classes.

Fix for https://github.com/ansible/ansible/issues/15446
This commit is contained in:
Yannig Perre 2016-04-16 19:19:33 +02:00 committed by Toshio Kuratomi
parent c0e1269f53
commit eb18767f91

View file

@ -1949,9 +1949,23 @@ class Network(Facts):
def __new__(cls, *arguments, **keyword):
subclass = cls
for sc in Network.__subclasses__():
if sc.platform == platform.system():
subclass = sc
# Retrieve direct subclasses
to_visit = Network.__subclasses__()
# Then visit all subclasses
while to_visit:
for sc in to_visit:
# Check if current class is the good one
if sc.platform == platform.system():
subclass = sc
to_visit = []
break
# The current class is now visited, so remove it from list
to_visit.remove(sc)
# Appending all subclasses to visit and keep a reference of available class
for ssc in sc.__subclasses__():
to_visit.append(ssc)
# Now, return corresponding subclass
return super(cls, subclass).__new__(subclass, *arguments, **keyword)
def populate(self):