forked from Juniper/net-netconf
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
158 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,67 @@ | ||
require 'net/netconf/jnpr' # note: including Juniper specific extension | ||
require 'net/netconf/jnpr' | ||
|
||
puts "NETCONF v.#{Netconf::VERSION}" | ||
|
||
login = { :target => 'ex4', :username => "jeremy", :password => "jeremy1" } | ||
|
||
puts "Connecting to device: #{login[:target]}" | ||
login = { | ||
target: 'ex4', | ||
username: 'jeremy', | ||
password: 'jeremy1' | ||
} | ||
|
||
puts "Connecting to device: #{login[:target]}" | ||
|
||
Netconf::SSH.new(login) do |dev| | ||
puts 'Connected.' | ||
|
||
Netconf::SSH.new( login ){ |dev| | ||
puts "Connected." | ||
|
||
puts "Retrieving full config, please wait ... " | ||
cfgall = dev.rpc.get_configuration # Junos specific RPC | ||
puts 'Retrieving full config, please wait ... ' | ||
# Junos specific RPC | ||
cfgall = dev.rpc.get_configuration | ||
puts "Showing 'system' hierarchy ..." | ||
puts cfgall.xpath('system') # Root is <configuration>, so don't need to include it in XPath | ||
# Root is <configuration>, so don't need to include it in XPath | ||
puts cfgall.xpath('system') | ||
|
||
# ---------------------------------------------------------------------- | ||
# ---------------------------------------------------------------------- | ||
# specifying a filter as a block to get_configuration | ||
# Junos extension does the proper toplevel wrapping | ||
|
||
puts "Retrieved services from BLOCK, as XML:" | ||
cfgsvc1_1 = dev.rpc.get_configuration{ |x| | ||
puts 'Retrieved services from BLOCK, as XML:' | ||
|
||
cfgsvc1 = dev.rpc.get_configuration do |x| | ||
x.system { x.services } | ||
x.system { x.login } | ||
} | ||
|
||
cfgsvc1_1.xpath('system/services/*').each{|s| puts s.name } | ||
end | ||
|
||
puts "Retrieved services from BLOCK, as TEXT:" | ||
|
||
cfgsvc1_2 = dev.rpc.get_configuration( :format => 'text' ){ |x| | ||
cfgsvc1.xpath('system/services/*').each { |s| puts s.name } | ||
|
||
puts 'Retrieved services from BLOCK, as TEXT:' | ||
|
||
cfgsvc2 = dev.rpc.get_configuration(format: 'text') do |x| | ||
x.system { x.services } | ||
} | ||
puts cfgsvc1_2.text | ||
end | ||
|
||
puts cfgsvc2.text | ||
|
||
# ---------------------------------------------------------------------- | ||
# specifying a filter as a parameter to get_configuration | ||
# you must wrap the config in a toplevel <configuration> element | ||
|
||
filter = Nokogiri::XML::Builder.new{ |x| x.configuration { | ||
x.system { x.services } | ||
x.system { x.login } | ||
}} | ||
|
||
puts "Retrieved services by PARAM, as XML" | ||
|
||
cfgsvc2 = dev.rpc.get_configuration( filter ) | ||
cfgsvc2.xpath('system/services/*').each{|s| puts s.name } | ||
filter = Nokogiri::XML::Builder.new do |x| | ||
x.configuration do | ||
x.system { x.services } | ||
x.system { x.login } | ||
end | ||
end | ||
|
||
puts 'Retrieved services by PARAM, as XML' | ||
|
||
cfgsvc3 = dev.rpc.get_configuration(filter) | ||
cfgsvc3.xpath('system/services/*').each { |s| puts s.name } | ||
|
||
# ---------------------------------------------------------------------- | ||
# specifying a filter as a parameter to get_configuration, | ||
# get response back in "text" format | ||
|
||
puts "Retrieved services by PARAM, as TEXT:" | ||
cfgsvc3 = dev.rpc.get_configuration( filter, :format => 'text' ) | ||
puts cfgsvc3.text | ||
} | ||
|
||
|
||
|
||
puts 'Retrieved services by PARAM, as TEXT:' | ||
cfgsvc4 = dev.rpc.get_configuration(filter, format: 'text') | ||
puts cfgsvc4.text | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters