Module: Netconf::RPC::Standard

Included in:
Executor
Defined in:
lib/net/netconf/rpc_std.rb

Instance Method Summary collapse

Instance Method Details

#commitObject



37
38
39
40
41
# File 'lib/net/netconf/rpc_std.rb', line 37

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



43
44
45
46
# File 'lib/net/netconf/rpc_std.rb', line 43

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



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
# File 'lib/net/netconf/rpc_std.rb', line 90

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
  options = {}

  arg = process_args(args)

  toplevel = options[:toplevel] if options[: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



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/net/netconf/rpc_std.rb', line 63

def get_config( *args ) # :yeield: filter_builder

  source = 'running'    # default source is 'running'
  filter = nil          # no filter by default

  arg = process_args(args)

  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



16
17
18
19
# File 'lib/net/netconf/rpc_std.rb', line 16

def lock( target )
  run_valid_or_lock_rpc "<rpc><lock><target><#{target}/></target></lock></rpc>",
                        Netconf::LockError
end

#process_args(args) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/net/netconf/rpc_std.rb', line 48

def process_args(args)
  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
end

#run_valid_or_lock_rpc(rpc_string, error_type) ⇒ Object



31
32
33
34
35
# File 'lib/net/netconf/rpc_std.rb', line 31

def run_valid_or_lock_rpc(rpc_string, error_type)
  rpc = Nokogiri::XML(rpc_string).root
  Netconf::RPC.set_exception( rpc, error_type )
  @trans.rpc_exec( rpc )
end

#unlock(target) ⇒ Object



21
22
23
24
# File 'lib/net/netconf/rpc_std.rb', line 21

def unlock( target )
  rpc = Nokogiri::XML( "<rpc><unlock><target><#{target}/></target></unlock></rpc>" ).root
  @trans.rpc_exec( rpc )
end

#validate(source) ⇒ Object



26
27
28
29
# File 'lib/net/netconf/rpc_std.rb', line 26

def validate( source )
  run_valid_or_lock_rpc "<rpc><validate><source><#{source}/></source></validate></rpc>",
                        Netconf::ValidateError
end