net-netconf 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,52 +1,49 @@
1
1
  require 'net/telnet'
2
2
 
3
3
  module Netconf
4
-
5
4
  class Telnet < Netconf::Transport
6
-
7
- def initialize( args, trans_args = nil, &block )
8
- os_type = args[:os_type] || Netconf::DEFAULT_OS_TYPE
5
+ def initialize(args, trans_args = nil, &block)
6
+ os_type = args[:os_type] || Netconf::DEFAULT_OS_TYPE
9
7
  @args = args.clone
10
-
8
+
11
9
  # extend this instance with the capabilities of the specific console
12
10
  # type; it needs to define #login and #start_netconf session
13
11
  begin
14
- extend Netconf::const_get( os_type )::TransTelnet
12
+ extend Netconf.const_get(os_type).TransTelnet
15
13
  rescue NameError
16
14
  # no extensions available ...
17
- end
18
-
15
+ end
16
+
19
17
  my_trans_args = {}
20
- my_trans_args["Host"] = @args[:target]
21
- my_trans_args["Port"] = @args[:port] if @args[:port]
22
-
23
- @trans = Net::Telnet.new( my_trans_args )
24
-
18
+ my_trans_args['Host'] = @args[:target]
19
+ my_trans_args['Port'] = @args[:port] if @args[:port]
20
+
21
+ @trans = Net::Telnet.new(my_trans_args)
22
+
25
23
  @trans_timeout = @args[:timeout] || Netconf::DEFAULT_TIMEOUT
26
- @trans_waitio = @args[:waitio] || Netconf::DEFAULT_WAITIO
27
-
28
- super( &block )
29
- end
30
-
31
- def trans_open( &block )
32
- trans_login()
33
- trans_start_netconf()
24
+ @trans_waitio = @args[:waitio] || Netconf::DEFAULT_WAITIO
25
+
26
+ super(&block)
27
+ end
28
+
29
+ def trans_open(&block)
30
+ trans_login
31
+ trans_start_netconf
34
32
  self
35
33
  end
36
-
34
+
37
35
  def trans_close
38
36
  @trans.write Netconf::RPC::MSG_CLOSE_SESSION
39
37
  @trans.close
40
38
  end
41
-
42
- def trans_send( cmd_str )
43
- @trans.write( cmd_str )
39
+
40
+ def trans_send(cmd_str)
41
+ @trans.write cmd_str
44
42
  end
45
-
46
- def trans_receive
47
- rsp = @trans.waitfor( Netconf::RPC::MSG_END_RE )
48
- rsp.chomp!( Netconf::RPC::MSG_END + "\n" )
43
+
44
+ def trans_receive
45
+ rsp = @trans.waitfor(Netconf::RPC::MSG_END_RE)
46
+ rsp.chomp!(Netconf::RPC::MSG_END + "\n")
49
47
  end
50
-
51
48
  end # class: Serial
52
49
  end # module: Netconf
@@ -12,24 +12,21 @@
12
12
 
13
13
  module Netconf
14
14
  class Transport
15
-
16
15
  attr_reader :rpc, :state, :session_id, :capabilities
17
16
  attr_writer :timeout, :waitio
18
17
 
19
- def initialize( &block )
20
-
18
+ def initialize(&block)
21
19
  @state = :NETCONF_CLOSED
22
20
  @os_type = @args[:os_type] || Netconf::DEFAULT_OS_TYPE
23
21
 
24
- @rpc = Netconf::RPC::Executor.new( self, @os_type )
22
+ @rpc = Netconf::RPC::Executor.new(self, @os_type)
25
23
  @rpc_message_id = 1
26
24
 
27
25
  if block_given?
28
- open( &block = nil ) # do not pass this block to open()
26
+ open(&block = nil) # do not pass this block to open()
29
27
  yield self
30
- close()
28
+ close
31
29
  end
32
-
33
30
  end # initialize
34
31
 
35
32
  def open?
@@ -40,25 +37,24 @@ module Netconf
40
37
  @state == :NECONF_CLOSED
41
38
  end
42
39
 
43
- def open( &block ) # :yield: specialized transport open, generally not used
44
-
40
+ def open(&block) # :yield: specialized transport open, generally not used
45
41
  raise Netconf::StateError if @state == :NETCONF_OPEN
46
42
 
47
43
  # block is used to deal with special open processing ...
48
44
  # this is *NOT* the block passed to initialize()
49
- raise Netconf::OpenError unless trans_open( &block )
45
+ raise Netconf::OpenError unless trans_open(&block)
50
46
 
51
47
  # read the <hello> from the server and parse out
52
48
  # the capabilities and session-id
53
49
 
54
- hello_rsp = Nokogiri::XML( trans_receive_hello() )
50
+ hello_rsp = Nokogiri::XML(trans_receive_hello)
55
51
  hello_rsp.remove_namespaces!
56
52
 
57
- @capabilities = hello_rsp.xpath('//capability').map{ |c| c.text }
53
+ @capabilities = hello_rsp.xpath('//capability').map { |c| c.text }
58
54
  @session_id = hello_rsp.xpath('//session-id').text
59
55
 
60
56
  # send the <hello>
61
- trans_send_hello()
57
+ trans_send_hello
62
58
 
63
59
  @state = :NETCONF_OPEN
64
60
  self
@@ -69,27 +65,27 @@ module Netconf
69
65
  end
70
66
 
71
67
  def trans_send_hello
72
- trans_send( Netconf::RPC::MSG_HELLO )
73
- trans_send( RPC::MSG_END )
68
+ trans_send(Netconf::RPC::MSG_HELLO)
69
+ trans_send(RPC::MSG_END)
74
70
  end
75
71
 
76
- def has_capability?( capability )
77
- @capabilities.select{|c| c.include? capability }.pop
72
+ def has_capability?(capability)
73
+ @capabilities.select { |c| c.include? capability }.pop
78
74
  # note: the caller could also simply use #grep on @capabilities
79
75
  end
80
76
 
81
77
  def close
82
78
  raise Netconf::StateError unless @state == :NETCONF_OPEN
83
- trans_close()
79
+ trans_close
84
80
  @state = :NETCONF_CLOSED
85
81
  self
86
82
  end
87
83
 
88
84
  # string in; string out
89
- def send_and_receive( cmd_str )
90
- trans_send( cmd_str )
91
- trans_send( RPC::MSG_END )
92
- trans_receive()
85
+ def send_and_receive(cmd_str)
86
+ trans_send(cmd_str)
87
+ trans_send(RPC::MSG_END)
88
+ trans_receive
93
89
  end
94
90
 
95
91
  def rpc_exec( cmd_nx )
@@ -106,7 +102,7 @@ module Netconf
106
102
  # receive the response; then covert it to a Nokogiri XML
107
103
  # object so we can process it.
108
104
 
109
- rsp_nx = Nokogiri::XML( send_and_receive( cmd_nx.to_xml ))
105
+ rsp_nx = Nokogiri::XML(send_and_receive(cmd_nx.to_xml))
110
106
 
111
107
  # the following removes only the default namespace (xmlns)
112
108
  # definitions from the document. This is an alternative
@@ -115,7 +111,7 @@ module Netconf
115
111
  # nice "compromise" ... just don't know what it does
116
112
  # performance-wise on large datasets.
117
113
 
118
- rsp_nx.traverse{ |n| n.namespace = nil }
114
+ rsp_nx.traverse { |n| n.namespace = nil }
119
115
 
120
116
  # set the response context to the root node; <rpc-reply>
121
117
 
@@ -137,9 +133,9 @@ module Netconf
137
133
  # or if the caller wants to raise if severity == 'warning'
138
134
  # then generate the exception
139
135
 
140
- if(( sev_err.count > 0 ) || Netconf::raise_on_warning )
141
- exception = Netconf::RPC.get_exception( cmd_nx )
142
- raise exception.new( self, cmd_nx, rsp_nx )
136
+ if (sev_err.count > 0) || Netconf.raise_on_warning
137
+ exception = Netconf::RPC.get_exception(cmd_nx)
138
+ raise exception.new(self, cmd_nx, rsp_nx)
143
139
  end
144
140
  end
145
141
 
@@ -149,9 +145,6 @@ module Netconf
149
145
  # @@@/JLS: the generic case.
150
146
 
151
147
  rsp_nx.first_element_child
152
-
153
148
  end
154
-
155
-
156
149
  end #--class: Transport
157
150
  end #--module: Netconf
@@ -1,3 +1,3 @@
1
1
  module Netconf
2
- VERSION = '0.4.1'
2
+ VERSION = '0.4.2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-netconf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kevin Kirsche
@@ -52,7 +52,8 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '1.2'
55
- description: Updated and maintained fork of the Juniper Ruby NetConf client
55
+ description: Updated and maintained fork of the Juniper Ruby NetConf client. This
56
+ is used to manage Junos OS devices.
56
57
  email: kev.kirsche@gmail.com
57
58
  executables: []
58
59
  extensions: []