Limit config fetch on junos_l3_interfaces (#61219)

This commit adds a filter in junos_l3_interfaces so it limits the amount
of configuration fetched from the remote device.
This commit is contained in:
Daniel Mellado 2019-08-29 06:16:15 +02:00 committed by Ganesh Nalawade
parent a54b78c67a
commit 0746ae8b37

View file

@ -14,8 +14,15 @@ __metaclass__ = type
from copy import deepcopy from copy import deepcopy
from ansible.module_utils._text import to_bytes
from ansible.module_utils.network.common import utils from ansible.module_utils.network.common import utils
from ansible.module_utils.network.junos.argspec.l3_interfaces.l3_interfaces import L3_interfacesArgs from ansible.module_utils.network.junos.argspec.l3_interfaces.l3_interfaces import L3_interfacesArgs
from ansible.module_utils.six import string_types
try:
from lxml import etree
HAS_LXML = True
except ImportError:
HAS_LXML = False
class L3_interfacesFacts(object): class L3_interfacesFacts(object):
@ -44,9 +51,21 @@ class L3_interfacesFacts(object):
:rtype: dictionary :rtype: dictionary
:returns: facts :returns: facts
""" """
if not HAS_LXML:
self._module.fail_json(msg='lxml is not installed.')
if not data: if not data:
data = connection.get_configuration() config_filter = """
resources = data.xpath('//configuration/interfaces/node()') <configuration>
<interfaces/>
</configuration>
"""
data = connection.get_configuration(filter=config_filter)
if isinstance(data, string_types):
data = etree.fromstring(to_bytes(data, errors='surrogate_then_replace'))
resources = data.xpath('configuration/interfaces/interface')
objs = [] objs = []
if resources: if resources: