How to use the ncclient.manager function in ncclient

To help you get started, we’ve selected a few ncclient examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ncclient / ncclient / test / unit / test_xml_.py View on Github external
def test_ncelement_reply_003(self):
        """test parse rpc_reply and find"""
        # read in reply1 contents
        with open(file_path, 'r') as f:
            reply = f.read()
        device_params = {'name': 'junos'}
        device_handler = manager.make_device_handler(device_params)
        transform_reply = device_handler.transform_reply()
        result = NCElement(reply, transform_reply)
        # find
        assert_equal(result.findtext(".//host-name"), "R1")
        assert_equal(result.find(".//host-name").tag, "host-name")
github ncclient / ncclient / test / unit / transport / test_parser.py View on Github external
def test_filter_xml_sax_on(self, mock_uuid4, mock_select, mock_session, mock_recv,
                              mock_close, mock_send, mock_send_ready, mock_connected):
        mock_send.return_value = True
        mock_send_ready.return_value = -1
        mock_uuid4.return_value = type('dummy', (), {'urn': "urn:uuid:e0a7abe3-fffa-11e5-b78e-b8e85604f858"})
        device_handler = manager.make_device_handler({'name': 'junos', 'use_filter': True})
        rpc = ''
        mock_recv.side_effect = self._read_file('get-software-information.xml')
        session = SSHSession(device_handler)
        session._connected = True
        session._channel = paramiko.Channel("c100")
        session.parser = session._device_handler.get_xml_parser(session)
        obj = ExecuteRpc(session, device_handler, raise_mode=RaiseMode.ALL)
        obj._filter_xml = ''
        session.run()
        resp = obj.request(rpc)._NCElement__doc[0]
        self.assertEqual(len(resp.xpath('multi-routing-engine-item/re-name')), 2)
        # as filter_xml is not having software-information, response wont contain it
        self.assertEqual(len(resp.xpath('multi-routing-engine-item/software-information')), 0)
github HPENetworking / scriptsonly / CMW7 Generic / get_netconf_all_HPN.py View on Github external
def connect(host, username, password):
    # Set-up connection to device
    with manager.connect(host=host,
                        port=830,
                        username=username,
                        password=password,
                        hostkey_verify=False,
                        allow_agent=False,
                        look_for_keys=False
                        ) as netconf_manager:

        data = netconf_manager.get()
    return data
github ncclient / ncclient / examples / nc05.py View on Github external
def demo(host, user, name):
    snippet = """
      
          
        %s
      """ % name

    with manager.connect(host=host, port=22, username=user) as m:
        assert(":validate" in m.server_capabilities)
        m.edit_config(target='running', config=snippet,
                      test_option='test-then-set')
github BRCDcomm / pynos / pynos / device.py View on Github external
None

        Returns:
            bool: True if reconnect succeeds, False if not.

        Raises:
            None
        """
        if self._auth_method is "userpass":
            self._mgr = manager.connect(host=self._conn[0],
                                        port=self._conn[1],
                                        username=self._auth[0],
                                        password=self._auth[1],
                                        hostkey_verify=self._hostkey_verify)
        elif self._auth_method is "key":
            self._mgr = manager.connect(host=self._conn[0],
                                        port=self._conn[1],
                                        username=self._auth[0],
                                        key_filename=self._auth_key,
                                        hostkey_verify=self._hostkey_verify)
        else:
            raise ValueError("auth_method incorrect value.")
        self._mgr.timeout = 600

        return True
github openstack / neutron / quantum / plugins / cisco / nexus / cisco_nexus_network_driver.py View on Github external
def nxos_connect(self, nexus_host, nexus_ssh_port, nexus_user,
                     nexus_password):
        """
        Makes the SSH connection to the Nexus Switch
        """
        man = manager.connect(host=nexus_host, port=nexus_ssh_port,
                              username=nexus_user, password=nexus_password)
        return man
github ncclient / ncclient / examples / juniper / unknown-rpc.py View on Github external
def connect(host, port, user, password):
    conn = manager.connect(host=host,
                           port=port,
                           username=user,
                           password=password,
                           timeout=60,
                           device_params={'name': 'junos'},
                           hostkey_verify=False)

    result = conn.get_software_information('brief', test='me')
    logging.info(result)

    result = conn.get_chassis_inventory('extensive')
    logging.info(result)
github rshoemak / DevNet2556 / get_hostname.py View on Github external
def main():
    """
    Main method that retrieves the hostname from config via NETCONF.
    """
    with manager.connect(host=HOST, port=PORT, username=USER,
                         password=PASS, hostkey_verify=False,
                         device_params={'name': 'default'},
                         allow_agent=False, look_for_keys=False) as m:

        # XML filter to issue with the get operation
        hostname_filter = """
                        
                        """

        result = m.get_config('running', hostname_filter)
        xml_doc = DOM.parseString(result.xml)
        hostname_obj = xml_doc.getElementsByTagName("hostname")
        hostname = hostname_obj[0].firstChild.nodeValue
github Uninett / nav / python / nav / portadmin / netconfhandler.py View on Github external
def _connection(self):
        profile = self.netbox.readwrite_connection_profile
        return manager.connect(
            host=self.netbox.ip,
            port=profile.port,
            username=profile.username,
            password=profile.password,
            unknown_host_cb=host_key_callback,
            device_params={'name': 'junos'},
        )
github frenetic-lang / pyretic / pyretic / vendor / ryu / ryu / lib / of_config / capable_switch.py View on Github external
def __init__(self, connect_method='connect_ssh', *args, **kwargs):
        super(OFCapableSwitch, self).__init__()
        self._connect_method = connect_method
        self._connect_args = args
        self._connect_kwargs = kwargs
        self.version = None
        self.namespace = None

        connect = getattr(ncclient.manager, self._connect_method)
        self.netconf = connect(*self._connect_args, **self._connect_kwargs)