{"id":20074166,"url":"https://github.com/juniper/net-netconf","last_synced_at":"2025-05-05T21:31:21.269Z","repository":{"id":6242238,"uuid":"7474357","full_name":"Juniper/net-netconf","owner":"Juniper","description":"A Ruby gem for NETCONF","archived":true,"fork":false,"pushed_at":"2024-02-22T12:30:20.000Z","size":287,"stargazers_count":65,"open_issues_count":27,"forks_count":38,"subscribers_count":35,"default_branch":"master","last_synced_at":"2025-05-04T12:40:52.869Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Juniper.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-01-06T23:59:45.000Z","updated_at":"2025-03-13T10:02:14.000Z","dependencies_parsed_at":"2024-06-18T21:41:10.933Z","dependency_job_id":null,"html_url":"https://github.com/Juniper/net-netconf","commit_stats":null,"previous_names":["juniper-workflow/net-netconf"],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Juniper%2Fnet-netconf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Juniper%2Fnet-netconf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Juniper%2Fnet-netconf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Juniper%2Fnet-netconf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Juniper","download_url":"https://codeload.github.com/Juniper/net-netconf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252580021,"owners_count":21771252,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T14:49:39.402Z","updated_at":"2025-05-05T21:31:20.866Z","avatar_url":"https://github.com/Juniper.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Netconf\n[![Gem Version](https://badge.fury.io/rb/netconf.svg)](https://badge.fury.io/rb/netconf)\n[![Dependency Status](https://gemnasium.com/badges/github.com/Juniper/net-netconf.svg)](https://gemnasium.com/github.com/Juniper/net-netconf)\n[![Build Status](https://travis-ci.org/Juniper/net-netconf.svg?branch=master)](https://travis-ci.org/Juniper/net-netconf)\n[![Code Climate](https://codeclimate.com/github/Juniper/net-netconf/badges/gpa.svg)](https://codeclimate.com/github/Juniper/net-netconf)\n[![Test Coverage](https://codeclimate.com/github/Juniper/net-netconf/badges/coverage.svg)](https://codeclimate.com/github/Juniper/net-netconf/coverage)\n\n## Description\nDevice management using the NETCONF protocol as specified in\n[RFC4741](http://tools.ietf.org/html/rfc4741) and\n[RFC6241](http://tools.ietf.org/html/rfc6241).\n\n## Features\n* Extensible protocol transport framework for SSH and non-SSH\n  * SSH transport using [Net::SSH](http://net-ssh.rubyforge.org)\n  * Telnet transport using Net::Telnet (Ruby Library)\n  * Serial transport using [Ruby/SerialPort](http://ruby-serialport.rubyforge.org/)\n\n* NETCONF Standard RPCs\n  * get-config, edit-config\n  * lock, unlock\n  * validate, discard-changes\n\n* Flexible RPC mechanism\n  * Netconf::RPC::Builder to metaprogram RPCs\n  * Vendor extension framework for custom RPCs\n\n* XML processing using [Nokogiri](http://nokogiri.org)\n\n## Synopsis\n\n```ruby\nrequire 'net/netconf'\n\n# create the options hash for the new NETCONF session. If you are\n# using ssh-agent, then omit the :password\n\nlogin = { target: 'vsrx', username: 'root', password: 'Amnesiac' }\n\n# provide a block and the session will open, execute, and close\n\nNetconf::SSH.new( login ){ |dev|\n\n  # perform the RPC command:\n  # \u003crpc\u003e\n  #    \u003cget-chassis-inventory/\u003e\n  # \u003c/rpc\u003e\n\n  inv = dev.rpc.get_chassis_inventory\n\n  # The response is in Nokogiri XML format for easy processing ...\n\n  puts 'Chassis: ' + inv.xpath('chassis/description').text\n  puts 'Chassis Serial-Number: ' + inv.xpath('chassis/serial-number').text\n}\n```\n\nAlternative explicity open, execute RPCs, and close\n\n```ruby\nrequire 'net/netconf'\n\nlogin = { target: 'vsrx', username: 'root', password: 'Amnesiac' }\n\ndev = Netconf::SSH.new(login)\ndev.open\n\ninv = dev.rpc.get_chassis_inventory\n\nputs 'Chassis: ' + inv.xpath('chassis/description').text\nputs 'Chassis Serial-Number: ' + inv.xpath('chassis/serial-number').text\n\ndev.close\n```\n\n## Using Netconf\n### Remote Procedure Calls (RPCs)\nEach Netconf session provides a readable instance variable - __rpc__. This is used to execute Remote Procedure Calls (RPCs). The @rpc will include the NETCONF standard RPCs, any vendor specific extension, as well as the ability to metaprogram new onces via method_missing.\n\nHere are some examples to illustrate the metaprogamming:\n\nWithout any parameters, the RPC is created by swapping underscores (_) to\nhyphens (-):\n\n```ruby\nrequire 'net/netconf'\n\ndev.rpc.get_chassis_inventory\n\n# \u003crpc\u003e\n#    \u003cget-chassis-inventory/\u003e\n# \u003c/rpc\u003e\n```\n\nYou can optionally provide RPC parameters as a hash:\n\n```ruby\ndev.rpc.get_interface_information(interface_name: 'ge-0/0/0', terse: true )\n\n# \u003crpc\u003e\n#    \u003cget-interface-information\u003e\n#       \u003cinterface-name\u003ege-0/0/0\u003c/interface-name\u003e\n#       \u003cterse/\u003e\n#   \u003c/get-interface-information\u003e\n# \u003c/rpc\u003e\n```\n\nYou can additionally supply attributes that get assigned to the toplevel\nelement. In this case You must enclose the parameters hash to disambiquate it\nfrom the attributes hash, or declare  a variable for the parameters hash.\n\n```ruby\ndev.rpc.get_interface_information({interface_name: 'ge-0/0/0', terse: true }, { format: 'text'})\n\n# \u003crpc\u003e\n#    \u003cget-interface-information format='text'\u003e\n#       \u003cinterface-name\u003ege-0/0/0\u003c/interface-name\u003e\n#       \u003cterse/\u003e\n#   \u003c/get-interface-information\u003e\n# \u003c/rpc\u003e\n```\n\nIf you want to provide attributes, but no parameters, then:\n\n```ruby\ndev.rpc.get_chassis_inventory(nil, format: 'text')\n\n# \u003crpc\u003e\n#    \u003cget-chassis-inventory format='text'/\u003e\n# \u003c/rpc\u003e\n```\n\n### Retrieving Configuration\nTo retrieve configuration from a device, use the `get-config` RPC. Here is\nan example, but you can find others in the __examples__ directory:\n\n```ruby\nrequire 'net/netconf'\n\nlogin = { target: 'vsrx', username: 'root', password: 'Amnesia' }\n\nputs \"Connecting to device: #{login[:target]}\"\n\nNetconf::SSH.new(login) do |dev|\n  puts 'Connected.'\n\n  # ----------------------------------------------------------------------\n  # retrieve the full config.  Default source is 'running'\n  # Alternatively you can pass the source name as a string parameter\n  # to #get_config\n\n  puts 'Retrieving full config, please wait ... '\n  cfgall = dev.rpc.get_config\n  puts \"Showing 'system' hierarchy ...\"\n  puts cfgall.xpath('configuration/system')     # JUNOS toplevel config element is \u003cconfiguration\u003e\n\n  # ----------------------------------------------------------------------\n  # specifying a filter as a block to get_config\n\n  cfgsvc1 = dev.rpc.get_config do |x|\n   x.configuration { x.system { x.services } }\n  end\n\n  puts 'Retrieved services as BLOCK:'\n  cfgsvc1.xpath('//services/*').each { |s| puts s.name }\n\n  # ----------------------------------------------------------------------\n  # specifying a filter as a parameter to get_config\n\n  filter = Nokogiri::XML::Builder.new do |x|\n   x.configuration { x.system { x.services } }\n  end\n\n  cfgsvc2 = dev.rpc.get_config(filter)\n  puts 'Retrieved services as PARAM:'\n  cfgsvc2.xpath('//services/*').each { |s| puts s.name }\n\n  cfgsvc3 = dev.rpc.get_config(filter)\n  puts 'Retrieved services as PARAM, re-used filter'\n  cfgsvc3.xpath('//services/*').each { |s| puts s.name }\nend\n```\n\n__NOTE__: There is a JUNOS RPC, `get-configuration`, that provides Juniper\nspecific extensions as well.\n\n### Changing Configuration\nTo retrieve configuration from a device, use the `edit-config` RPC. Here is\nan example, but you can find others in the __examples__ directory:\n\n```ruby\nrequire 'net/netconf'\n\nlogin = { target: 'vsrx', username: 'root', password: 'Amnesia' }\n\nnew_host_name = 'vsrx-abc'\n\nputs \"Connecting to device: #{login[:target]}\"\n\nNetconf::SSH.new(login) do |dev|\n  puts 'Connected!'\n\n  target = 'candidate'\n\n  # JUNOS toplevel element is 'configuration'\n\n  location = Nokogiri::XML::Builder.new do |x|\n    x.configuration {\n      x.system {\n        x.location {\n          x.building 'Main Campus, A'\n          x.floor 5\n          x.rack 27\n        }\n      }\n    }\n  end\n\n  begin\n    rsp = dev.rpc.lock target\n\n    # --------------------------------------------------------------------\n    # configuration as BLOCK\n\n    rsp = dev.rpc.edit_config do |x|\n      x.configuration {\n        x.system {\n          x.send(:'host-name', new_host_name )\n        }\n      }\n    end\n\n    # --------------------------------------------------------------------\n    # configuration as PARAM\n\n    rsp = dev.rpc.edit_config(location)\n\n    rsp = dev.rpc.validate target\n    rpc = dev.rpc.commit\n    rpc = dev.rpc.unlock target\n\n  rescue Netconf::LockError =\u003e e\n    puts 'Lock error'\n  rescue Netconf::EditError =\u003e e\n    puts 'Edit error'\n  rescue Netconf::ValidateError =\u003e e\n    puts 'Validate error'\n  rescue Netconf::CommitError =\u003e e\n    puts 'Commit error'\n  rescue Netconf::RpcError =\u003e e\n    puts 'General RPC error'\n  else\n    puts 'Configuration Committed.'\n  end\nend\n```\n\n__NOTE__: There is a JUNOS RPC, `load-configuration`, that provides\nJuniper specific extensions as well.\n\n## Authors and Contributors\n* [Jeremy Schulman](www.linkedin.com/in/jeremyschulman), Juniper Networks\n* [Ankit Jain](http://www.linkedin.com/in/ankitj093), Juniper Networks\n* [Kevin Kirsche](mailto:Kev.Kirsche+GitHub@gmail.com)\n* [David Gethings](https://www.linkedin.com/in/david-gethings-59a2051/), Juniper Networks\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuniper%2Fnet-netconf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjuniper%2Fnet-netconf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjuniper%2Fnet-netconf/lists"}