本文整理汇总了Python中ncclient.manager.make_device_handler函数的典型用法代码示例。如果您正苦于以下问题:Python make_device_handler函数的具体用法?Python make_device_handler怎么用?Python make_device_handler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_device_handler函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))
开发者ID:ncclient,项目名称:ncclient,代码行数:7,代码来源:test_rpc.py
示例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()
)
开发者ID:zachmoody,项目名称:conf_time,代码行数:7,代码来源:tests.py
示例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
开发者ID:Juniper,项目名称:open-nti,代码行数:26,代码来源:pyez_mock.py
示例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")
开发者ID:toabctl,项目名称:ncclient,代码行数:7,代码来源:test_xml_.py
示例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)
开发者ID:GIC-de,项目名称:ncclient,代码行数:25,代码来源:test_rpc.py
示例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')
开发者ID:djadhav76,项目名称:py-junos-eznc,代码行数:30,代码来源:test_device.py
示例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
开发者ID:GIC-de,项目名称:Juniper-PyEZ-Unit-Testing,代码行数:27,代码来源:device.py
示例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)
开发者ID:ncclient,项目名称:ncclient,代码行数:7,代码来源:test_rpc.py
示例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')
开发者ID:Kostas83,项目名称:py-junos-eznc,代码行数:35,代码来源:test_fs.py
示例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)
开发者ID:ncclient,项目名称:ncclient,代码行数:8,代码来源:test_rpc.py
示例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")
开发者ID:toabctl,项目名称:ncclient,代码行数:8,代码来源:test_xml_.py
示例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
开发者ID:ARD92,项目名称:py-junos-eznc,代码行数:8,代码来源:jxml.py
示例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"})
开发者ID:toabctl,项目名称:ncclient,代码行数:8,代码来源:test_xml_.py
示例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
开发者ID:ngngeek,项目名称:py-junos-eznc,代码行数:8,代码来源:jxml.py
示例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"])
开发者ID:ncclient,项目名称:ncclient,代码行数:8,代码来源:test_xml_.py
示例16: test_validated_element_fail_2
def test_validated_element_fail_2(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
with self.assertRaises(XMLError):
validated_element(result_xml, tags=["rpc-reply", "rpc"], attrs=[["attrib1"], ["attrib2"]])
开发者ID:toabctl,项目名称:ncclient,代码行数:9,代码来源:test_xml_.py
示例17: _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)
if args:
return self._read_file(args[0].tag + '.xml')
开发者ID:ARD92,项目名称:py-junos-eznc,代码行数:9,代码来源:test_srx_cluster.py
示例18: test_commit_confirmed_at_time
def test_commit_confirmed_at_time(
self, mock_assert, mock_request, mock_session):
# mock_session.server_capabilities.return_value = [':candidate']
device_handler = manager.make_device_handler({'name': 'junos'})
session = ncclient.transport.SSHSession(device_handler)
obj = Commit(session, device_handler, raise_mode=RaiseMode.ALL)
self.assertRaises(NCClientError,
obj.request, at_time="1111-11-11 00:00:00", synchronize=True,
confirmed=True)
开发者ID:ncclient,项目名称:ncclient,代码行数:9,代码来源:test_rpc.py
示例19: test_rpc_capability_error
def test_rpc_capability_error(self, mock_thread, mock_send):
device_handler = manager.make_device_handler({'name': 'junos'})
capabilities = Capabilities(device_handler.get_capabilities())
session = ncclient.transport.Session(capabilities)
session._server_capabilities = [':running']
obj = RPC(session, device_handler, raise_mode=RaiseMode.ALL, timeout=0)
obj._assert(':running')
self.assertRaises(MissingCapabilityError,
obj._assert, ':candidate')
开发者ID:GIC-de,项目名称:ncclient,代码行数:9,代码来源:test_rpc.py
示例20: test_to_ele
def test_to_ele(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)
ele = to_ele((result.find(".//name")))
self.assertEqual(ele.tag, "name")
self.assertEqual(ele.text, "junos")
ele = to_ele(self.reply)
self.assertEqual(ele.tag, "rpc-reply")
开发者ID:toabctl,项目名称:ncclient,代码行数:10,代码来源:test_xml_.py
注:本文中的ncclient.manager.make_device_handler函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论