From 57f12ac9e36e2625eb0e75d6b5fd17a1e7264b22 Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Sun, 22 Jul 2012 11:40:02 -0400 Subject: [PATCH] Using __slots__ in more places, in particular, hosts and groups, where we are apt to create a fair amount of objects. --- lib/ansible/inventory/__init__.py | 3 +++ lib/ansible/inventory/group.py | 2 ++ lib/ansible/inventory/host.py | 2 ++ lib/ansible/inventory/yaml.py | 2 ++ 4 files changed, 9 insertions(+) diff --git a/lib/ansible/inventory/__init__.py b/lib/ansible/inventory/__init__.py index 60a3523aba..7c2212c5a0 100644 --- a/lib/ansible/inventory/__init__.py +++ b/lib/ansible/inventory/__init__.py @@ -35,6 +35,9 @@ class Inventory(object): Host inventory for ansible. """ + __slots__ = [ 'host_list', 'groups', '_restriction', '_is_script', + 'parser' ] + def __init__(self, host_list=C.DEFAULT_HOST_LIST): # the host file file, or script path, or list of hosts diff --git a/lib/ansible/inventory/group.py b/lib/ansible/inventory/group.py index a51de0c89c..9552f244c7 100644 --- a/lib/ansible/inventory/group.py +++ b/lib/ansible/inventory/group.py @@ -18,6 +18,8 @@ class Group(object): ''' a group of ansible hosts ''' + __slots__ = [ 'name', 'hosts', 'vars', 'child_groups', 'parent_groups' ] + def __init__(self, name=None): self.name = name diff --git a/lib/ansible/inventory/host.py b/lib/ansible/inventory/host.py index 0c43471801..c96a5cb0ce 100644 --- a/lib/ansible/inventory/host.py +++ b/lib/ansible/inventory/host.py @@ -21,6 +21,8 @@ import ansible.constants as C class Host(object): ''' a single ansible host ''' + __slots__ = [ 'name', 'vars', 'groups' ] + def __init__(self, name=None, port=None): self.name = name diff --git a/lib/ansible/inventory/yaml.py b/lib/ansible/inventory/yaml.py index afeaa40139..f17aa72313 100644 --- a/lib/ansible/inventory/yaml.py +++ b/lib/ansible/inventory/yaml.py @@ -25,6 +25,8 @@ import sys class InventoryParserYaml(object): ''' Host inventory parser for ansible ''' + __slots__ = [ '_hosts', 'groups' ] + def __init__(self, filename=C.DEFAULT_HOST_LIST): sys.stderr.write("WARNING: YAML inventory files are deprecated in 0.6 and will be removed in 0.7, to migrate" +