Module: Netconf::RPC::Standard
- Included in:
- Executor
- Defined in:
- lib/net/netconf/rpc_std.rb
Instance Method Summary collapse
- #commit ⇒ Object
- #delete_config(target) ⇒ Object
-
#edit_config(*args) ⇒ Object
:yeield: config_builder.
-
#get_config(*args) ⇒ Object
:yeield: filter_builder.
- #lock(target) ⇒ Object
- #unlock(target) ⇒ Object
- #validate(source) ⇒ Object
Instance Method Details
#commit ⇒ Object
34 35 36 37 38 |
# File 'lib/net/netconf/rpc_std.rb', line 34 def commit rpc = Nokogiri::XML( "<rpc><commit/></rpc>" ).root Netconf::RPC.set_exception( rpc, Netconf::CommitError ) @trans.rpc_exec( rpc ) end |
#delete_config(target) ⇒ Object
40 41 42 43 |
# File 'lib/net/netconf/rpc_std.rb', line 40 def delete_config( target ) rpc = Nokogiri::XML( "<rpc><delete-config><target><#{target}/></target></delete-config></rpc>" ).root @trans.rpc_exec( rpc ) end |
#edit_config(*args) ⇒ Object
:yeield: config_builder
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/net/netconf/rpc_std.rb', line 83 def edit_config( *args ) # :yeield: config_builder toplevel = 'config' # default toplevel config element target = 'candidate' # default source is 'candidate' @@@/JLS hack; need to fix this config = nil = {} while arg = args.shift case arg.class.to_s when /^Nokogiri/ config = case arg when Nokogiri::XML::Builder then arg.doc.root when Nokogiri::XML::Document then arg.root else arg end when 'Hash' then = arg when 'String' then target = arg end end toplevel = [:toplevel] if [:toplevel] rpc_str = <<-EO_RPC <rpc> <edit-config> <target><#{target}/></target> <#{toplevel}/> </edit-config> </rpc> EO_RPC rpc = Nokogiri::XML( rpc_str ).root if block_given? Nokogiri::XML::Builder.with(rpc.at( toplevel )){ |xml| yield( xml ) } elsif config rpc.at( toplevel ) << config.dup else raise ArgumentError, "You must specify edit-config data!" end Netconf::RPC.set_exception( rpc, Netconf::EditError ) @trans.rpc_exec( rpc ) end |
#get_config(*args) ⇒ Object
:yeield: filter_builder
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/net/netconf/rpc_std.rb', line 45 def get_config( *args ) # :yeield: filter_builder source = 'running' # default source is 'running' filter = nil # no filter by default while arg = args.shift case arg.class.to_s when /^Nokogiri/ filter = case arg when Nokogiri::XML::Builder then arg.doc.root when Nokogiri::XML::Document then arg.root else arg end when 'Hash' then attrs = arg when 'String' then source = arg end end rpc = Nokogiri::XML("<rpc><get-config><source><#{source}/></source></get-config></rpc>").root if block_given? Nokogiri::XML::Builder.with( rpc.at( 'get-config' )){ |xml| xml.filter( :type => 'subtree' ) { yield( xml ) } } end if filter f_node = Nokogiri::XML::Node.new( 'filter', rpc ) f_node['type'] = 'subtree' f_node << filter.dup # copy filter, don't mess with the original since it may be re-used rpc.at('get-config') << f_node end @trans.rpc_exec( rpc ) end |
#lock(target) ⇒ Object
17 18 19 20 21 |
# File 'lib/net/netconf/rpc_std.rb', line 17 def lock( target ) rpc = Nokogiri::XML( "<rpc><lock><target><#{target}/></target></lock></rpc>" ).root Netconf::RPC.set_exception( rpc, Netconf::LockError ) @trans.rpc_exec( rpc ) end |
#unlock(target) ⇒ Object
23 24 25 26 |
# File 'lib/net/netconf/rpc_std.rb', line 23 def unlock( target ) rpc = Nokogiri::XML( "<rpc><unlock><target><#{target}/></target></unlock></rpc>" ).root @trans.rpc_exec( rpc ) end |
#validate(source) ⇒ Object
28 29 30 31 32 |
# File 'lib/net/netconf/rpc_std.rb', line 28 def validate( source ) rpc = Nokogiri::XML( "<rpc><validate><source><#{source}/></source></validate></rpc>" ).root Netconf::RPC.set_exception( rpc, Netconf::ValidateError ) @trans.rpc_exec( rpc ) end |