mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
set _hosts on access if None (#31111)
set _hosts on access if None to bpyass srlz10n issues to fix #30903
This commit is contained in:
parent
101377768b
commit
cf3414d7d7
1 changed files with 11 additions and 7 deletions
|
@ -18,7 +18,6 @@ from __future__ import (absolute_import, division, print_function)
|
|||
__metaclass__ = type
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.utils.vars import combine_vars
|
||||
|
||||
|
||||
class Group:
|
||||
|
@ -31,7 +30,7 @@ class Group:
|
|||
self.depth = 0
|
||||
self.name = name
|
||||
self.hosts = []
|
||||
self._hosts = set()
|
||||
self._hosts = None
|
||||
self.vars = {}
|
||||
self.child_groups = []
|
||||
self.parent_groups = []
|
||||
|
@ -72,9 +71,8 @@ class Group:
|
|||
self.name = data.get('name')
|
||||
self.vars = data.get('vars', dict())
|
||||
self.depth = data.get('depth', 0)
|
||||
self.hosts = data.get('hosts', {})
|
||||
|
||||
self._hosts = set(self.hosts)
|
||||
self.hosts = data.get('hosts', [])
|
||||
self._hosts = None
|
||||
|
||||
parent_groups = data.get('parent_groups', [])
|
||||
for parent_data in parent_groups:
|
||||
|
@ -82,6 +80,12 @@ class Group:
|
|||
g.deserialize(parent_data)
|
||||
self.parent_groups.append(g)
|
||||
|
||||
@property
|
||||
def host_names(self):
|
||||
if self._hosts is None:
|
||||
self._hosts = set(self.hosts)
|
||||
return self._hosts
|
||||
|
||||
def get_name(self):
|
||||
return self.name
|
||||
|
||||
|
@ -119,7 +123,7 @@ class Group:
|
|||
raise AnsibleError("The group named '%s' has a recursive dependency loop." % self.name)
|
||||
|
||||
def add_host(self, host):
|
||||
if host.name not in self._hosts:
|
||||
if host.name not in self.host_names:
|
||||
self.hosts.append(host)
|
||||
self._hosts.add(host.name)
|
||||
host.add_group(self)
|
||||
|
@ -127,7 +131,7 @@ class Group:
|
|||
|
||||
def remove_host(self, host):
|
||||
|
||||
if host.name in self._hosts:
|
||||
if host.name in self.host_names:
|
||||
self.hosts.remove(host)
|
||||
self._hosts.remove(host.name)
|
||||
host.remove_group(self)
|
||||
|
|
Loading…
Reference in a new issue