Use a custom id generator over uuid4

>>> timeit.timeit("uuid.uuid4()", setup="import uuid")
9.518647909164429
>>> timeit.timeit("get_unique_id()", setup="from __main__ import get_unique_id")
0.40436601638793945

This will mainly be beneficial when a very large inventory is being
used, however it may also help with some very large playbooks.
pull/21270/head
James Cammarata 8 years ago
parent 84135ef7ad
commit 4cbe610263

@ -19,10 +19,8 @@
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import uuid
from ansible.inventory.group import Group
from ansible.utils.vars import combine_vars
from ansible.utils.vars import combine_vars, get_unique_id
__all__ = ['Host']
@ -92,7 +90,7 @@ class Host:
self._gathered_facts = False
self._uuid = None
if gen_uuid:
self._uuid = uuid.uuid4()
self._uuid = get_unique_id()
self.implicit = False
def __repr__(self):

@ -21,7 +21,6 @@ __metaclass__ = type
import itertools
import operator
import uuid
from copy import copy as shallowcopy
from functools import partial
@ -34,7 +33,7 @@ from ansible.module_utils._text import to_text
from ansible.playbook.attribute import Attribute, FieldAttribute
from ansible.parsing.dataloader import DataLoader
from ansible.constants import mk_boolean as boolean
from ansible.utils.vars import combine_vars, isidentifier
from ansible.utils.vars import combine_vars, isidentifier, get_unique_id
try:
from __main__ import display
@ -184,7 +183,7 @@ class Base(with_metaclass(BaseMeta, object)):
self._finalized = False
# every object gets a random uuid:
self._uuid = uuid.uuid4()
self._uuid = get_unique_id()
# we create a copy of the attributes here due to the fact that
# it was intialized as a class param in the meta class, so we

Loading…
Cancel
Save