Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abates/netconf
https://github.com/abates/netconf
Last synced: about 7 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/abates/netconf
- Owner: abates
- Created: 2012-04-18T22:48:56.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2014-03-11T12:55:09.000Z (over 10 years ago)
- Last Synced: 2023-03-11T09:57:18.673Z (over 1 year ago)
- Language: Ruby
- Size: 174 KB
- Stars: 7
- Watchers: 6
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Netconf
=======Introduction
------------Ruby implementation of some Netconf (RFC 6241) capabilities. In addition
to the Netconf base capabilities, there is specific support for managing
Juniper Infranet ControllersFor examples of use with a Juniper Infranet confoller see the code in
the examples/ directoryExamples
--------### Connecting to a device (default port 22)
begin
n = Netconf::Factory.create(
:transport => 'ssh',
:login => 'username',
:password => 'password',
:hostname => 'host.example.com'
)
rescue Netconf::RPCException => e
puts "RPCException received:"
e.errors.each do |error|
puts "\t#{error.error_message}"
end
end### Connecting to a device (alternate port)
begin
n = Netconf::Factory.create(
:transport => 'ssh',
:login => 'username',
:password => 'password',
:hostname => 'host.example.com',
:port => 830
)
rescue Netconf::RPCException => e
puts "RPCException received:"
e.errors.each do |error|
puts "\t#{error.error_message}"
end
end### Getting the entire config
begin
n = Netconf::Factory.create(
:transport => 'ssh',
:login => 'username',
:password => 'password',
:hostname => 'host.example.com',
:port => 830
)
config = n.get_config
rescue Netconf::RPCException => e
puts "RPCException received:"
e.errors.each do |error|
puts "\t#{error.error_message}"
end
end### Getting a specific block of config
begin
n = Netconf::Factory.create(
:transport => 'ssh',
:login => 'username',
:password => 'password',
:hostname => 'host.example.com',
:port => 830
)
filter = <<_EOF
_EOF
config = n.get_config(filter)
rescue Netconf::RPCException => e
puts "RPCException received:"
e.errors.each do |error|
puts "\t#{error.error_message}"
end
end### Setting a config value
We use builder to build XML blocks to send to the device. This is very efficient since
the xml is being sent to the device (as opposed to being built in memory) as it is
being built. It is very easy to send config in an "edit-config" operation using builder,
simply supply a block to the edit_config method. When called, the block will be passed an
instance of the builder object.begin
n = Netconf::Factory.create(
:transport => 'ssh',
:login => 'username',
:password => 'password',
:hostname => 'host.example.com',
:port => 830
)
n.edit_config('running') do |xml|
xml.top( 'xmlns' => 'http://example.com/schema/1.2/config') do
xml.interface do
xml.name 'Ethernet0/0'
xml.mtu '1500'
end
end
end
rescue Netconf::RPCException => e
puts "RPCException received:"
e.errors.each do |error|
puts "\t#{error.error_message}"
end
end### Adding new capabilities
It is also very easy to add new capabilities. Capabilities are added in the form of
Ruby modules. Any module that implements a set of capabilities need only have a
has_capability? method that will return true for a matching capability in the
Netconf hello received for the device. The Ruby Netconf API will iterate all the
modules in the capabilities directory and will include them in the Device class if
the has_capability? returns true.module MyCapabilities
def self.has_capability? capability
capability =~ /http:\/\/example.net\/router\/2.3\/myfeature/
enddef myfeature
# do whatever you need to do here
end
endFor more detailed use please see the existing capabilities in lib/netconf/capabilities/