How to use the ncclient.manager.connect 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_manager.py View on Github external
def test_connect_ssh_with_hostkey_ed25519(self, mock_ssh):
        hostkey = 'AAAAC3NzaC1lZDI1NTE5AAAAIIiHpGSf8fla6tCwLpwshvMGmUK+B/0v5CsRu+5v4uT7'
        manager.connect(host='host', hostkey=hostkey)
        mock_ssh.assert_called_once_with(host='host', hostkey=hostkey)
github DevNetSandbox / sbx_nxos / learning_labs / yang / 01-yang / get_capabilities.py View on Github external
def main():
    """
    Main method that prints netconf capabilities of remote device.
    """
    for device in DEVICES:
        with manager.connect(host=device, port=PORT, username=USER,
                             password=PASS, hostkey_verify=False,
                             device_params={'name': 'nexus'},
                             look_for_keys=False, allow_agent=False) as m:

            # print all NETCONF capabilities
            print('\n***Remote Devices Capabilities for device {} {}***\n'.format(DEVICE_NAMES[device], device))
            for capability in m.server_capabilities:
                print(capability.split('?')[0])
github CiscoDevNet / netprog_basics / programming_fundamentals / python_part_3 / api_ncclient_example.py View on Github external
router = {"ip": "10.10.20.48",
          "port": 830,
          "user": "developer",
          "pass": "C1sco12345"}

netconf_filter = """

"""

m = manager.connect(host=router["ip"],
                    port=router["port"],
                    username=router["user"],
                    password=router["pass"],
                    hostkey_verify=False)

interface_netconf = m.get_config("running", netconf_filter)
interface_python = xmltodict.parse(interface_netconf.xml)["rpc-reply"]["data"]
pprint(interface_python["interfaces"]["interface"]["name"]["#text"])
github ncclient / ncclient / examples / juniper / edit-config-text-std.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)

    conn.lock()

    # configuration as a text string
    host_name = """
    system {
        host-name foo-bar;
    }
    """
github ncclient / ncclient / examples / juniper / execute-rpc-string.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)

    rpc = """
    
        
    """

    result = conn.rpc(rpc)
    logging.info('Chassis serial-number: %s', result.xpath('//chassis-inventory/chassis/serial-number')[0].text)
github CiscoDevNet / ydk-py / core / ydk / providers / _provider_plugin.py View on Github external
def connect(self, session_config):
        assert session_config.transportMode == _SessionTransportMode.SSH
        if self.use_native_client:
            self.ydk_client = YdkClient(
                username=session_config.username,
                password=session_config.password,
                host=session_config.hostname,
                port=session_config.port)
            self.ydk_client.connect()
            return self.ydk_client
        else:
            self._nc_manager = manager.connect(
                host=session_config.hostname,
                port=session_config.port,
                username=session_config.username,
                password=session_config.password,
                look_for_keys=False,
                allow_agent=False,
                hostkey_verify=False)
            return self._nc_manager
github CiscoDevNet / devnet-express-code-samples / LM-4602 / 05-mission / 01_get_interface_stats_SOLUTION.py View on Github external
def get_netconf(xml_filter):
    """
    Main method that retrieves information via NETCONF get.
    """
    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:
        with open(xml_filter) as f:
            # MISSION: Replace XXX with the correct NETCONF operation
            return(m.get(f.read()))
github CiscoDevNet / catalyst9k-network-automation / 16.9.1 / QoS / QoS.py View on Github external
# Input parameters
    parser.add_argument('--host', type=str, required=True,
                        help="The device IP or DN")
    parser.add_argument('-u', '--username', type=str, default='cisco',
                        help="Go on, guess!")
    parser.add_argument('-p', '--password', type=str, default='cisco',
                        help="Yep, this one too! ;-)")
    parser.add_argument('--port', type=int, default=830,
                        help="Specify non-default port for NETCONF")


    args = parser.parse_args()

    global m 
    m = manager.connect(host=args.host,
                         port=args.port,
                         username=args.username,
                         password=args.password,
                         device_params={'name':"iosxe"})



    prompt = QoSPolicy()
    prompt.prompt = 'QoSPolicy> '
    prompt.cmdloop('Starting QoSPolicy prompt...')