Junos fixes (#22423)

* Fixes for junos_config errors

* Check transport settings for core Junos

* Don't pop from the same list you iterate over

* use of persistent connections are now explicitly enabled in junos

* modules must now explicitly enable persistent connections
* adds rpc support to junos_command

fixes #22166
This commit is contained in:
Peter Sprygada 2017-03-11 10:26:42 -06:00 committed by GitHub
commit 1825406e1e
7 changed files with 207 additions and 86 deletions

View file

@ -26,50 +26,50 @@
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
from contextlib import contextmanager
from ncclient.xml_ import new_ele, sub_ele, to_xml, to_ele
from xml.etree.ElementTree import Element, SubElement
from xml.etree.ElementTree import tostring, fromstring
from ansible.module_utils.connection import exec_command
def send_request(module, obj, check_rc=True):
request = to_xml(obj)
request = tostring(obj)
rc, out, err = exec_command(module, request)
if rc != 0:
if check_rc:
module.fail_json(msg=str(err))
return to_ele(err)
return to_ele(out)
return fromstring(out)
return fromstring(out)
def children(root, iterable):
for item in iterable:
try:
ele = sub_ele(ele, item)
ele = SubElement(ele, item)
except NameError:
ele = sub_ele(root, item)
ele = SubElement(root, item)
def lock(module, target='candidate'):
obj = new_ele('lock')
obj = Element('lock')
children(obj, ('target', target))
return send_request(module, obj)
def unlock(module, target='candidate'):
obj = new_ele('unlock')
obj = Element('unlock')
children(obj, ('target', target))
return send_request(module, obj)
def commit(module):
return send_request(module, new_ele('commit'))
return send_request(module, Element('commit'))
def discard_changes(module):
return send_request(module, new_ele('discard-changes'))
return send_request(module, Element('discard-changes'))
def validate(module):
obj = new_ele('validate')
obj = Element('validate')
children(obj, ('source', 'candidate'))
return send_request(module, obj)
def get_config(module, source='running', filter=None):
obj = new_ele('get-config')
obj = Element('get-config')
children(obj, ('source', source))
children(obj, ('filter', filter))
return send_request(module, obj)