From 28227c95a468b26a2bbd3d6d4338565f1cb84e34 Mon Sep 17 00:00:00 2001 From: Xu Yuandong Date: Mon, 9 Sep 2019 21:33:34 +0800 Subject: [PATCH] for capability/exchange/1.0 (#60630) * for capability/exchange/1.0 * for capability/exchange/1.0 * update for shippable * Update ce.py * Update ce.py --- .../module_utils/network/cloudengine/ce.py | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/lib/ansible/module_utils/network/cloudengine/ce.py b/lib/ansible/module_utils/network/cloudengine/ce.py index 168c7906831..43d689f0ed9 100644 --- a/lib/ansible/module_utils/network/cloudengine/ce.py +++ b/lib/ansible/module_utils/network/cloudengine/ce.py @@ -35,19 +35,24 @@ import traceback from ansible.module_utils.basic import env_fallback from ansible.module_utils.network.common.utils import to_list, ComplexList -from ansible.module_utils.connection import exec_command +from ansible.module_utils.connection import exec_command, ConnectionError from ansible.module_utils.six import iteritems from ansible.module_utils._text import to_native from ansible.module_utils.network.common.netconf import NetconfConnection try: - from ncclient.xml_ import to_xml + from ncclient.xml_ import to_xml, new_ele_ns HAS_NCCLIENT = True except ImportError: HAS_NCCLIENT = False +try: + from lxml import etree +except ImportError: + from xml.etree import ElementTree as etree + _DEVICE_CLI_CONNECTION = None _DEVICE_NC_CONNECTION = None @@ -343,6 +348,28 @@ def set_nc_config(module, xml_str): return to_string(to_xml(out)) +def get_nc_next(module, xml_str): + """ get_nc_next for exchange capability """ + + conn = get_nc_connection(module) + result = None + if xml_str is not None: + response = conn.get(xml_str, if_rpc_reply=True) + result = response.find('./*') + set_id = response.get('set-id') + fetch_node = new_ele_ns('get-next', 'http://www.huawei.com/netconf/capability/base/1.0', {'set-id': set_id}) + while True: + try: + next = conn.dispatch(etree.tostring(fetch_node)) + if next is not None: + result.extend(next) + except ConnectionError: + break + if result is not None: + return etree.tostring(result) + return result + + def get_nc_config(module, xml_str): """ get_config """