本文整理汇总了Python中ncclient.manager.make_device_handler函数的典型用法代码示例。如果您正苦于以下问题:Python make_device_handler函数的具体用法?Python make_device_handler怎么用?Python make_device_handler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_device_handler函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_execute_rpc_str
def test_execute_rpc_str(self, mock_request, mock_session):
device_handler = manager.make_device_handler({'name': 'junos'})
session = ncclient.transport.SSHSession(device_handler)
obj = ExecuteRpc(session, device_handler, raise_mode=RaiseMode.ALL)
rpc = '<get-software-information/>'
obj.request(rpc)
self.assertEqual(True, isinstance(rpc, str))
示例2: _test_data
def _test_data(self, path):
with open(path, 'r') as f:
reply = f.read()
return NCElement(
reply,
manager.make_device_handler({'name': 'junos'}).transform_reply()
)
示例3: mock_manager
def mock_manager(*args, **kwargs):
if 'device_params' in kwargs:
# open connection
device_params = kwargs['device_params']
device_handler = make_device_handler(device_params)
session = SSHSession(device_handler)
return Manager(session, device_handler)
elif args:
# rpc request
rpc_request = args[0].tag
rpc_command = str(args[0].text)
rpc_command = rpc_command.strip()
rpc_command = rpc_command.replace(" ", "_")
if rpc_request in rpc_reply_dict:
xml = rpc_reply_dict[rpc_request]
elif 'dir' in rpc_reply_dict:
fname = os.path.join(rpc_reply_dict['dir'], 'rpc-reply', rpc_command, rpc_request + '.xml')
with open(fname, 'r') as f:
xml = f.read()
else:
_rpc_reply_dict['dir']
fname = os.path.join(os.path.dirname(__file__), 'rpc-reply', rpc_command, rpc_request + '.xml')
with open(fname, 'r') as f:
xml = f.read()
rpc_reply = NCElement(xml, dev._conn._device_handler.transform_reply())
return rpc_reply
示例4: test_ncelement_find
def test_ncelement_find(self):
device_params = {"name": "junos"}
device_handler = manager.make_device_handler(device_params)
transform_reply = device_handler.transform_reply()
result = NCElement(self.reply, transform_reply)
self.assertEqual(result.find(".//name").tag, "name")
self.assertEqual(result.find(".//name").text, "junos")
示例5: test_rpc_send
def test_rpc_send(self, mock_thread, mock_send):
device_handler = manager.make_device_handler({'name': 'junos'})
capabilities = Capabilities(device_handler.get_capabilities())
session = ncclient.transport.Session(capabilities)
obj = RPC(session, device_handler, raise_mode=RaiseMode.ALL, timeout=0)
reply = RPCReply(xml1)
obj._reply = reply
node = new_ele("commit")
sub_ele(node, "confirmed")
sub_ele(node, "confirm-timeout").text = "50"
sub_ele(node, "log").text = "message"
result = obj._request(node)
ele = new_ele("rpc",
{"message-id": obj._id},
**device_handler.get_xml_extra_prefix_kwargs())
ele.append(node)
node = to_xml(ele)
mock_send.assert_called_once_with(node)
self.assertEqual(
result.data_xml,
(NCElement(
reply,
device_handler.transform_reply())).data_xml)
self.assertEqual(obj.session, session)
self.assertEqual(reply, obj.reply)
示例6: _mock_manager
def _mock_manager(self, *args, **kwargs):
if kwargs:
device_params = kwargs['device_params']
device_handler = make_device_handler(device_params)
session = SSHSession(device_handler)
return Manager(session, device_handler)
elif args:
if args[0].tag == 'command':
if args[0].text == 'show cli directory':
return self._read_file('show-cli-directory.xml')
if args[0].text == 'show interface terse':
return self._read_file('show-interface-terse.json')
elif args[0].text == 'show configuration':
return self._read_file('show-configuration.xml')
elif args[0].text == 'show system alarms':
return self._read_file('show-system-alarms.xml')
elif args[0].text == 'show system uptime | display xml rpc':
return self._read_file('show-system-uptime-rpc.xml')
elif args[0].text == 'show configuration interfaces':
return self._read_file('show-configuration-interfaces.xml')
elif args[0].text == 'show interfaces terse asdf':
return self._read_file('show-interfaces-terse-asdf.xml')
else:
raise RpcError
else:
if args[0].attrib.get('format')=='json':
return self._read_file(args[0].tag + '.json')
return self._read_file(args[0].tag + '.xml')
示例7: mock_manager
def mock_manager(*args, **kwargs):
if 'device_params' in kwargs:
# open connection
device_params = kwargs['device_params']
device_handler = make_device_handler(device_params)
session = SSHSession(device_handler)
return Manager(session, device_handler)
elif args:
# rpc request
rpc_request = args[0].tag
if rpc_request == "command":
# CLI commands
rpc_request = "%s_%s" % (rpc_request, args[0].text.replace(" ", "_"))
if rpc_request in rpc_reply_dict:
# result for rpc request is in dict
reply = rpc_reply_dict[rpc_request]
if isinstance(reply, Exception):
raise reply
else:
xml = reply
else:
# get rpc result from file
fname = os.path.join(os.getcwd(), 'tests', 'rpc-reply', rpc_request + '.xml')
with open(fname, 'r') as f:
xml = f.read()
rpc_reply = NCElement(xml, dev._conn._device_handler.transform_reply())
return rpc_reply
示例8: test_execute_rpc
def test_execute_rpc(self, mock_request, mock_session):
device_handler = manager.make_device_handler({'name': 'junos'})
session = ncclient.transport.SSHSession(device_handler)
obj = ExecuteRpc(session, device_handler, raise_mode=RaiseMode.ALL)
rpc = new_ele('get-software-information')
obj.request(rpc)
mock_request.assert_called_once_with(rpc)
示例9: _mock_manager
def _mock_manager(self, *args, **kwargs):
if kwargs:
# if 'path' in kwargs and 'detail' in kwargs:
# return self._read_file('dir_list_detail.xml')
if 'path' in kwargs:
if kwargs['path'] == 'test/stat/decode_dir':
return self._read_file('file-list_dir.xml')
elif kwargs['path'] == 'test/stat/decode_file':
return self._read_file('file-list_file.xml')
elif kwargs['path'] == 'test/checksum':
return self._read_file('checksum.xml')
elif kwargs['path'] == 'test/stat/decode_symbolic_link':
return self._read_file('file-list_symlink.xml')
if 'directory' in kwargs:
if kwargs['directory'] == 'change/directory':
return self._read_file('set-cli-working-directory.xml')
if 'filename' in kwargs:
if kwargs['filename'] == 'test/cat.txt':
return self._read_file('file-show.xml')
device_params = kwargs['device_params']
device_handler = make_device_handler(device_params)
session = SSHSession(device_handler)
return Manager(session, device_handler)
elif args:
if args[0].tag == 'command':
if args[0].text == 'show cli directory':
return self._read_file('show-cli-directory.xml')
elif args[0].tag == 'get-system-storage':
return self._read_file('get-system-storage.xml')
elif args[0].tag == 'request-system-storage-cleanup':
return self._read_file('request-system-storage-cleanup.xml')
elif args[0].tag == 'file-archive':
return self._read_file('file-archive.xml')
示例10: test_halt
def test_halt(self, mock_request, mock_session):
device_handler = manager.make_device_handler({'name': 'junos'})
session = ncclient.transport.SSHSession(device_handler)
obj = Halt(session, device_handler, raise_mode=RaiseMode.ALL)
obj.request()
node = new_ele('request-halt')
call = mock_request.call_args_list[0][0][0]
self.assertEqual(call.tag, node.tag)
示例11: test_ncelement_reply_001
def test_ncelement_reply_001(self):
device_params = {"name": "junos"}
device_handler = manager.make_device_handler(device_params)
transform_reply = device_handler.transform_reply()
result = NCElement(self.reply, transform_reply)
self.assertEqual(result.xpath("//name")[0].text, "junos")
self.assertEqual(result.xpath("//name")[0].tag, "name")
self.assertEqual(result.xpath("//package-information")[0].tag, "package-information")
示例12: cscript_conf
def cscript_conf(reply):
try:
device_params = {'name': 'junos'}
device_handler = manager.make_device_handler(device_params)
transform_reply = device_handler.transform_reply()
return NCElement(reply, transform_reply)._NCElement__doc
except:
return None
示例13: test_parse_root
def test_parse_root(self):
device_params = {"name": "junos"}
device_handler = manager.make_device_handler(device_params)
transform_reply = device_handler.transform_reply()
result = NCElement(self.reply, transform_reply)
tag, attrib = parse_root(result.data_xml)
self.assertEqual(tag, "rpc-reply")
self.assertEqual(attrib, {"attrib1": "test"})
示例14: cscript_conf
def cscript_conf(reply):
try:
device_params = {"name": "junos"}
device_handler = manager.make_device_handler(device_params)
transform_reply = device_handler.transform_reply()
return NCElement(etree.tostring(reply), transform_reply)._NCElement__doc
except:
return None
示例15: test_validated_element_fail_3
def test_validated_element_fail_3(self):
device_params = {"name": "junos"}
device_handler = manager.make_device_handler(device_params)
transform_reply = device_handler.transform_reply()
result = NCElement(self.reply, transform_reply)
XMLError.message = "Element does not meet requirement"
result_xml = result.data_xml
self.assertRaises(XMLError, validated_element, result_xml, tags=["rpc"])