netconf 0.2.5 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/examples/confd/get-running.rb +27 -27
- data/examples/jnpr/edit-config-jnpr-set.rb +55 -55
- data/examples/jnpr/edit-config-jnpr-text.rb +64 -64
- data/examples/jnpr/edit-config-jnpr.rb +73 -73
- data/examples/jnpr/edit-config-std.rb +64 -64
- data/examples/jnpr/edit-config-text-std.rb +68 -68
- data/examples/jnpr/get-config-jnpr.rb +62 -62
- data/examples/jnpr/get-config-matching.rb +20 -20
- data/examples/jnpr/get-config-std.rb +49 -49
- data/examples/jnpr/get-inventory-serial-explicit.rb +27 -27
- data/examples/jnpr/get-inventory-serial.rb +25 -25
- data/examples/jnpr/get-inventory-telnet.rb +14 -14
- data/examples/jnpr/get-inventory.rb +16 -16
- data/examples/jnpr/scp.rb +22 -22
- data/lib/net/netconf.rb +11 -1
- data/lib/net/netconf/exception.rb +38 -38
- data/lib/net/netconf/ioproc.rb +88 -88
- data/lib/net/netconf/jnpr.rb +9 -9
- data/lib/net/netconf/jnpr/ioproc.rb +14 -14
- data/lib/net/netconf/jnpr/rpc.rb +162 -140
- data/lib/net/netconf/jnpr/serial.rb +15 -15
- data/lib/net/netconf/jnpr/telnet.rb +23 -23
- data/lib/net/netconf/rpc.rb +71 -71
- data/lib/net/netconf/rpc_std.rb +133 -134
- data/lib/net/netconf/serial.rb +135 -135
- data/lib/net/netconf/ssh.rb +78 -77
- data/lib/net/netconf/telnet.rb +52 -52
- data/lib/net/netconf/transport.rb +28 -5
- data/lib/net/netconf/version.rb +3 -0
- metadata +21 -12
@@ -1,27 +1,27 @@
|
|
1
|
-
require 'net/netconf/jnpr/serial'
|
2
|
-
|
3
|
-
puts "NETCONF v.#{Netconf::VERSION}"
|
4
|
-
|
5
|
-
login = {
|
6
|
-
:port => '/dev/ttyS4',
|
7
|
-
:username => "root", :password => "juniper1"
|
8
|
-
}
|
9
|
-
|
10
|
-
# we want to mount the USB drive, so we need to explicity
|
11
|
-
# do something special when opening the serial console ...
|
12
|
-
# therefore, we can *NOT* pass a block directly to new()
|
13
|
-
|
14
|
-
dev = Netconf::Serial.new( login )
|
15
|
-
dev.open { |con|
|
16
|
-
# login has occurred successfully
|
17
|
-
|
18
|
-
con.puts 'mount_msdosfs /dev/da1s1 /mnt'
|
19
|
-
|
20
|
-
# netconf will be started once block completes
|
21
|
-
}
|
22
|
-
|
23
|
-
inv = dev.rpc.get_chassis_inventory
|
24
|
-
|
25
|
-
dev.close
|
26
|
-
|
27
|
-
|
1
|
+
require 'net/netconf/jnpr/serial'
|
2
|
+
|
3
|
+
puts "NETCONF v.#{Netconf::VERSION}"
|
4
|
+
|
5
|
+
login = {
|
6
|
+
:port => '/dev/ttyS4',
|
7
|
+
:username => "root", :password => "juniper1"
|
8
|
+
}
|
9
|
+
|
10
|
+
# we want to mount the USB drive, so we need to explicity
|
11
|
+
# do something special when opening the serial console ...
|
12
|
+
# therefore, we can *NOT* pass a block directly to new()
|
13
|
+
|
14
|
+
dev = Netconf::Serial.new( login )
|
15
|
+
dev.open { |con|
|
16
|
+
# login has occurred successfully
|
17
|
+
|
18
|
+
con.puts 'mount_msdosfs /dev/da1s1 /mnt'
|
19
|
+
|
20
|
+
# netconf will be started once block completes
|
21
|
+
}
|
22
|
+
|
23
|
+
inv = dev.rpc.get_chassis_inventory
|
24
|
+
|
25
|
+
dev.close
|
26
|
+
|
27
|
+
|
@@ -1,25 +1,25 @@
|
|
1
|
-
require 'net/netconf/jnpr/serial'
|
2
|
-
|
3
|
-
puts "NETCONF v.#{Netconf::VERSION}"
|
4
|
-
|
5
|
-
serial_port = '/dev/ttyS4'
|
6
|
-
|
7
|
-
login = { :port => serial_port,
|
8
|
-
:username => "jeremy", :password => "jeremy1" }
|
9
|
-
|
10
|
-
puts "Connecting to SERIAL: #{serial_port} ... please wait."
|
11
|
-
|
12
|
-
Netconf::Serial.new( login ){ |dev|
|
13
|
-
|
14
|
-
puts "Connected."
|
15
|
-
puts "Nabbing Inventory ..."
|
16
|
-
|
17
|
-
inv = dev.rpc.get_chassis_inventory
|
18
|
-
|
19
|
-
puts "Chassis: " + inv.xpath('chassis/description').text
|
20
|
-
puts "Chassis Serial-Number: " + inv.xpath('chassis/serial-number').text
|
21
|
-
|
22
|
-
}
|
23
|
-
|
24
|
-
|
25
|
-
|
1
|
+
require 'net/netconf/jnpr/serial'
|
2
|
+
|
3
|
+
puts "NETCONF v.#{Netconf::VERSION}"
|
4
|
+
|
5
|
+
serial_port = '/dev/ttyS4'
|
6
|
+
|
7
|
+
login = { :port => serial_port,
|
8
|
+
:username => "jeremy", :password => "jeremy1" }
|
9
|
+
|
10
|
+
puts "Connecting to SERIAL: #{serial_port} ... please wait."
|
11
|
+
|
12
|
+
Netconf::Serial.new( login ){ |dev|
|
13
|
+
|
14
|
+
puts "Connected."
|
15
|
+
puts "Nabbing Inventory ..."
|
16
|
+
|
17
|
+
inv = dev.rpc.get_chassis_inventory
|
18
|
+
|
19
|
+
puts "Chassis: " + inv.xpath('chassis/description').text
|
20
|
+
puts "Chassis Serial-Number: " + inv.xpath('chassis/serial-number').text
|
21
|
+
|
22
|
+
}
|
23
|
+
|
24
|
+
|
25
|
+
|
@@ -1,14 +1,14 @@
|
|
1
|
-
require 'net/netconf/jnpr/telnet'
|
2
|
-
|
3
|
-
puts "NETCONF v#{Netconf::VERSION}"
|
4
|
-
|
5
|
-
login = { :target => 'vsrx', :username => "jeremy", :password => "jeremy1" }
|
6
|
-
|
7
|
-
Netconf::Telnet.new( login ){ |dev|
|
8
|
-
inv = dev.rpc.get_chassis_inventory
|
9
|
-
puts "Chassis: " + inv.xpath('chassis/description').text
|
10
|
-
puts "Chassis Serial-Number: " + inv.xpath('chassis/serial-number').text
|
11
|
-
|
12
|
-
}
|
13
|
-
|
14
|
-
|
1
|
+
require 'net/netconf/jnpr/telnet'
|
2
|
+
|
3
|
+
puts "NETCONF v#{Netconf::VERSION}"
|
4
|
+
|
5
|
+
login = { :target => 'vsrx', :username => "jeremy", :password => "jeremy1" }
|
6
|
+
|
7
|
+
Netconf::Telnet.new( login ){ |dev|
|
8
|
+
inv = dev.rpc.get_chassis_inventory
|
9
|
+
puts "Chassis: " + inv.xpath('chassis/description').text
|
10
|
+
puts "Chassis Serial-Number: " + inv.xpath('chassis/serial-number').text
|
11
|
+
|
12
|
+
}
|
13
|
+
|
14
|
+
|
@@ -1,16 +1,16 @@
|
|
1
|
-
require 'net/netconf'
|
2
|
-
|
3
|
-
puts "NETCONF v#{Netconf::VERSION}"
|
4
|
-
|
5
|
-
login = { :target => 'vsrx', :username => "jeremy", :password => "jeremy1" }
|
6
|
-
|
7
|
-
Netconf::SSH.new( login ){ |dev|
|
8
|
-
|
9
|
-
inv = dev.rpc.get_chassis_inventory
|
10
|
-
|
11
|
-
puts "Chassis: " + inv.xpath('chassis/description').text
|
12
|
-
puts "Chassis Serial-Number: " + inv.xpath('chassis/serial-number').text
|
13
|
-
}
|
14
|
-
|
15
|
-
|
16
|
-
|
1
|
+
require 'net/netconf'
|
2
|
+
|
3
|
+
puts "NETCONF v#{Netconf::VERSION}"
|
4
|
+
|
5
|
+
login = { :target => 'vsrx', :username => "jeremy", :password => "jeremy1" }
|
6
|
+
|
7
|
+
Netconf::SSH.new( login ){ |dev|
|
8
|
+
|
9
|
+
inv = dev.rpc.get_chassis_inventory
|
10
|
+
|
11
|
+
puts "Chassis: " + inv.xpath('chassis/description').text
|
12
|
+
puts "Chassis Serial-Number: " + inv.xpath('chassis/serial-number').text
|
13
|
+
}
|
14
|
+
|
15
|
+
|
16
|
+
|
data/examples/jnpr/scp.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
require 'net/netconf'
|
2
|
-
require 'net/scp'
|
3
|
-
|
4
|
-
login = { :target => 'vsrx', :username => "jeremy", :password => "jeremy1" }
|
5
|
-
|
6
|
-
file_name = __FILE__
|
7
|
-
|
8
|
-
Netconf::SSH.new( login ){ |dev|
|
9
|
-
|
10
|
-
inv = dev.rpc.get_chassis_inventory
|
11
|
-
|
12
|
-
puts "Chassis: " + inv.xpath('chassis/description').text
|
13
|
-
puts "Chassis Serial-Number: " + inv.xpath('chassis/serial-number').text
|
14
|
-
|
15
|
-
puts "Copying file #{file_name} to home directory ..."
|
16
|
-
dev.scp.upload! file_name, file_name
|
17
|
-
|
18
|
-
puts "Copying latest config file from target to local machine ..."
|
19
|
-
|
20
|
-
dev.scp.download! "/config/juniper.conf.gz", "/var/tmp/config.gz"
|
21
|
-
}
|
22
|
-
|
1
|
+
require 'net/netconf'
|
2
|
+
require 'net/scp'
|
3
|
+
|
4
|
+
login = { :target => 'vsrx', :username => "jeremy", :password => "jeremy1" }
|
5
|
+
|
6
|
+
file_name = __FILE__
|
7
|
+
|
8
|
+
Netconf::SSH.new( login ){ |dev|
|
9
|
+
|
10
|
+
inv = dev.rpc.get_chassis_inventory
|
11
|
+
|
12
|
+
puts "Chassis: " + inv.xpath('chassis/description').text
|
13
|
+
puts "Chassis Serial-Number: " + inv.xpath('chassis/serial-number').text
|
14
|
+
|
15
|
+
puts "Copying file #{file_name} to home directory ..."
|
16
|
+
dev.scp.upload! file_name, file_name
|
17
|
+
|
18
|
+
puts "Copying latest config file from target to local machine ..."
|
19
|
+
|
20
|
+
dev.scp.download! "/config/juniper.conf.gz", "/var/tmp/config.gz"
|
21
|
+
}
|
22
|
+
|
data/lib/net/netconf.rb
CHANGED
@@ -1,15 +1,25 @@
|
|
1
1
|
|
2
2
|
require 'nokogiri'
|
3
3
|
|
4
|
+
require 'net/netconf/version'
|
4
5
|
require 'net/netconf/rpc'
|
5
6
|
require 'net/netconf/exception'
|
6
7
|
require 'net/netconf/transport'
|
7
8
|
require 'net/netconf/ssh'
|
8
9
|
|
9
10
|
module Netconf
|
10
|
-
VERSION = "0.2.5"
|
11
11
|
NAMESPACE = "urn:ietf:params:xml:ns:netconf:base:1.0"
|
12
12
|
DEFAULT_OS_TYPE = :Junos
|
13
13
|
DEFAULT_TIMEOUT = 10
|
14
14
|
DEFAULT_WAITIO = 0
|
15
|
+
|
16
|
+
@raise_on_warning = false # rpc-error with <error-severity> = 'warning' will not raise RpcError excption
|
17
|
+
|
18
|
+
def self.raise_on_warning=( bool )
|
19
|
+
@raise_on_warning = bool
|
20
|
+
end
|
21
|
+
def self.raise_on_warning
|
22
|
+
@raise_on_warning
|
23
|
+
end
|
24
|
+
|
15
25
|
end
|
@@ -1,38 +1,38 @@
|
|
1
|
-
module Netconf
|
2
|
-
|
3
|
-
class InitError < StandardError
|
4
|
-
end
|
5
|
-
|
6
|
-
class StateError < StandardError
|
7
|
-
end
|
8
|
-
|
9
|
-
class OpenError < StandardError
|
10
|
-
end
|
11
|
-
|
12
|
-
class RpcError < StandardError
|
13
|
-
attr_reader :trans
|
14
|
-
attr_reader :cmd, :rsp
|
15
|
-
|
16
|
-
def initialize( trans, cmd, rsp )
|
17
|
-
@trans = trans
|
18
|
-
@cmd = cmd; @rsp = rsp;
|
19
|
-
end
|
20
|
-
|
21
|
-
def to_s
|
22
|
-
"RPC command error: #{cmd.first_element_child.name}"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
class EditError < Netconf::RpcError
|
27
|
-
end
|
28
|
-
|
29
|
-
class LockError < Netconf::RpcError
|
30
|
-
end
|
31
|
-
|
32
|
-
class CommitError < Netconf::RpcError
|
33
|
-
end
|
34
|
-
|
35
|
-
class ValidateError < Netconf::RpcError
|
36
|
-
end
|
37
|
-
|
38
|
-
end
|
1
|
+
module Netconf
|
2
|
+
|
3
|
+
class InitError < StandardError
|
4
|
+
end
|
5
|
+
|
6
|
+
class StateError < StandardError
|
7
|
+
end
|
8
|
+
|
9
|
+
class OpenError < StandardError
|
10
|
+
end
|
11
|
+
|
12
|
+
class RpcError < StandardError
|
13
|
+
attr_reader :trans
|
14
|
+
attr_reader :cmd, :rsp
|
15
|
+
|
16
|
+
def initialize( trans, cmd, rsp )
|
17
|
+
@trans = trans
|
18
|
+
@cmd = cmd; @rsp = rsp;
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
"RPC command error: #{cmd.first_element_child.name}\n#{rsp.to_xml}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class EditError < Netconf::RpcError
|
27
|
+
end
|
28
|
+
|
29
|
+
class LockError < Netconf::RpcError
|
30
|
+
end
|
31
|
+
|
32
|
+
class CommitError < Netconf::RpcError
|
33
|
+
end
|
34
|
+
|
35
|
+
class ValidateError < Netconf::RpcError
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/lib/net/netconf/ioproc.rb
CHANGED
@@ -1,88 +1,88 @@
|
|
1
|
-
module Netconf
|
2
|
-
|
3
|
-
class IOProc < Netconf::Transport
|
4
|
-
|
5
|
-
DEFAULT_RDBLKSZ = (1024*1024)
|
6
|
-
|
7
|
-
attr_reader :args
|
8
|
-
|
9
|
-
def initialize( args_h = {}, &block )
|
10
|
-
os_type = args_h[:os_type] || Netconf::DEFAULT_OS_TYPE
|
11
|
-
|
12
|
-
@args = args_h.clone
|
13
|
-
|
14
|
-
# an OS specific implementation must exist to support this transport type
|
15
|
-
extend Netconf::const_get( os_type )::IOProc
|
16
|
-
|
17
|
-
@trans_timeout = @args[:timeout] || Netconf::DEFAULT_TIMEOUT
|
18
|
-
@trans_waitio = @args[:waitio] || Netconf::DEFAULT_WAITIO
|
19
|
-
|
20
|
-
super( &block )
|
21
|
-
end
|
22
|
-
|
23
|
-
# the OS specific transport must implement this method
|
24
|
-
def trans_open # :yield: self
|
25
|
-
raise "Unsupported IOProc"
|
26
|
-
end
|
27
|
-
|
28
|
-
def trans_receive_hello
|
29
|
-
trans_receive()
|
30
|
-
end
|
31
|
-
|
32
|
-
def trans_send_hello
|
33
|
-
nil
|
34
|
-
end
|
35
|
-
|
36
|
-
def trans_close
|
37
|
-
@trans.write Netconf::RPC::MSG_CLOSE_SESSION
|
38
|
-
@trans.close
|
39
|
-
end
|
40
|
-
|
41
|
-
def trans_send( cmd_str )
|
42
|
-
@trans.write( cmd_str )
|
43
|
-
end
|
44
|
-
|
45
|
-
def trans_receive
|
46
|
-
got = waitfor( Netconf::RPC::MSG_END_RE )
|
47
|
-
msg_end = got.rindex( Netconf::RPC::MSG_END )
|
48
|
-
got[msg_end .. -1] = ''
|
49
|
-
got
|
50
|
-
end
|
51
|
-
|
52
|
-
def puts( str = nil )
|
53
|
-
@trans.puts( str )
|
54
|
-
end
|
55
|
-
|
56
|
-
def waitfor( on_re )
|
57
|
-
|
58
|
-
time_out = @trans_timeout
|
59
|
-
wait_io = @trans_waitio
|
60
|
-
|
61
|
-
time_out = nil if time_out == false
|
62
|
-
done = false
|
63
|
-
rx_buf = ''
|
64
|
-
|
65
|
-
until( rx_buf.match( on_re ) and not IO::select( [@trans], nil, nil, wait_io ) )
|
66
|
-
|
67
|
-
unless IO::select( [@trans], nil, nil, time_out )
|
68
|
-
raise TimeoutError, "Netconf IO timed out while waiting for more data"
|
69
|
-
end
|
70
|
-
|
71
|
-
begin
|
72
|
-
|
73
|
-
rx_some = @trans.readpartial( DEFAULT_RDBLKSZ )
|
74
|
-
|
75
|
-
rx_buf += rx_some
|
76
|
-
break if rx_buf.match( on_re )
|
77
|
-
|
78
|
-
rescue EOFError # End of file reached
|
79
|
-
rx_buf = nil if rx_buf == ''
|
80
|
-
break # out of outer 'until' loop
|
81
|
-
end
|
82
|
-
|
83
|
-
end
|
84
|
-
rx_buf
|
85
|
-
end
|
86
|
-
|
87
|
-
end # class: IOProc
|
88
|
-
end # module: Netconf
|
1
|
+
module Netconf
|
2
|
+
|
3
|
+
class IOProc < Netconf::Transport
|
4
|
+
|
5
|
+
DEFAULT_RDBLKSZ = (1024*1024)
|
6
|
+
|
7
|
+
attr_reader :args
|
8
|
+
|
9
|
+
def initialize( args_h = {}, &block )
|
10
|
+
os_type = args_h[:os_type] || Netconf::DEFAULT_OS_TYPE
|
11
|
+
|
12
|
+
@args = args_h.clone
|
13
|
+
|
14
|
+
# an OS specific implementation must exist to support this transport type
|
15
|
+
extend Netconf::const_get( os_type )::IOProc
|
16
|
+
|
17
|
+
@trans_timeout = @args[:timeout] || Netconf::DEFAULT_TIMEOUT
|
18
|
+
@trans_waitio = @args[:waitio] || Netconf::DEFAULT_WAITIO
|
19
|
+
|
20
|
+
super( &block )
|
21
|
+
end
|
22
|
+
|
23
|
+
# the OS specific transport must implement this method
|
24
|
+
def trans_open # :yield: self
|
25
|
+
raise "Unsupported IOProc"
|
26
|
+
end
|
27
|
+
|
28
|
+
def trans_receive_hello
|
29
|
+
trans_receive()
|
30
|
+
end
|
31
|
+
|
32
|
+
def trans_send_hello
|
33
|
+
nil
|
34
|
+
end
|
35
|
+
|
36
|
+
def trans_close
|
37
|
+
@trans.write Netconf::RPC::MSG_CLOSE_SESSION
|
38
|
+
@trans.close
|
39
|
+
end
|
40
|
+
|
41
|
+
def trans_send( cmd_str )
|
42
|
+
@trans.write( cmd_str )
|
43
|
+
end
|
44
|
+
|
45
|
+
def trans_receive
|
46
|
+
got = waitfor( Netconf::RPC::MSG_END_RE )
|
47
|
+
msg_end = got.rindex( Netconf::RPC::MSG_END )
|
48
|
+
got[msg_end .. -1] = ''
|
49
|
+
got
|
50
|
+
end
|
51
|
+
|
52
|
+
def puts( str = nil )
|
53
|
+
@trans.puts( str )
|
54
|
+
end
|
55
|
+
|
56
|
+
def waitfor( on_re )
|
57
|
+
|
58
|
+
time_out = @trans_timeout
|
59
|
+
wait_io = @trans_waitio
|
60
|
+
|
61
|
+
time_out = nil if time_out == false
|
62
|
+
done = false
|
63
|
+
rx_buf = ''
|
64
|
+
|
65
|
+
until( rx_buf.match( on_re ) and not IO::select( [@trans], nil, nil, wait_io ) )
|
66
|
+
|
67
|
+
unless IO::select( [@trans], nil, nil, time_out )
|
68
|
+
raise TimeoutError, "Netconf IO timed out while waiting for more data"
|
69
|
+
end
|
70
|
+
|
71
|
+
begin
|
72
|
+
|
73
|
+
rx_some = @trans.readpartial( DEFAULT_RDBLKSZ )
|
74
|
+
|
75
|
+
rx_buf += rx_some
|
76
|
+
break if rx_buf.match( on_re )
|
77
|
+
|
78
|
+
rescue EOFError # End of file reached
|
79
|
+
rx_buf = nil if rx_buf == ''
|
80
|
+
break # out of outer 'until' loop
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
rx_buf
|
85
|
+
end
|
86
|
+
|
87
|
+
end # class: IOProc
|
88
|
+
end # module: Netconf
|