Misc code cleanup, mostly whitespace preferences, removing unused imports, plus a few fixes here and there.

This commit is contained in:
Michael DeHaan
2012-07-15 12:29:53 -04:00
parent 4b73931351
commit 1754de3335
15 changed files with 117 additions and 131 deletions

View File

@@ -15,16 +15,11 @@
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#############################################
# from ansible import errors
class Group(object):
"""
Group of ansible hosts
"""
''' a group of ansible hosts '''
def __init__(self, name=None):
self.name = name
self.hosts = []
self.vars = {}
@@ -34,19 +29,23 @@ class Group(object):
raise Exception("group name is required")
def add_child_group(self, group):
if self == group:
raise Exception("can't add group to itself")
self.child_groups.append(group)
group.parent_groups.append(self)
def add_host(self, host):
self.hosts.append(host)
host.add_group(self)
def set_variable(self, key, value):
self.vars[key] = value
def get_hosts(self):
hosts = []
for kid in self.child_groups:
hosts.extend(kid.get_hosts())
@@ -54,6 +53,7 @@ class Group(object):
return hosts
def get_variables(self):
vars = {}
# FIXME: verify this variable override order is what we want
for ancestor in self.get_ancestors():
@@ -62,6 +62,7 @@ class Group(object):
return vars
def _get_ancestors(self):
results = {}
for g in self.parent_groups:
results[g.name] = g
@@ -69,8 +70,6 @@ class Group(object):
return results
def get_ancestors(self):
return self._get_ancestors().values()