Module: Netconf::RPC::Standard

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

Instance Method Summary collapse

Instance Method Details

#commitObject


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

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


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

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


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

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

  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 options = arg
    when 'String' then target = arg
    end
  end

  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)) do |xml|
      yield(xml)
    end
  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


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

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')) do |xml|
      xml.filter(type: 'subtree') do
        yield(xml)
      end
    end
  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


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

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


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

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