26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
79
|
# File 'lib/puppet/provider/ce/api/l3_interface/l3_interface_api.rb', line 26
def get_l3_interface
l3_interface_array = []
session = Puppet::NetDev::CE::Device.session
get_l3_interface_xml = '<rpc><get><filter type="subtree"><ifm xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><interfaces><interface><ifName></ifName><ifDescr></ifDescr><ifAdminStatus></ifAdminStatus><isL2SwitchPort></isL2SwitchPort><ifmAm4></ifmAm4></interface></interfaces></ifm></filter></get></rpc>'
interface_all = session.rpc.do_config(get_l3_interface_xml)
interface_elements = interface_all.first_element_child.first_element_child
interface_elements.element_children.each do |interface_elem|
interface_doc = Nokogiri::XML(interface_elem.to_s)
interface_mode = interface_doc.xpath('/interface/isL2SwitchPort').text
next if interface_mode == 'true'
interface_name = interface_doc.xpath('/interface/ifName').text
interface_des = interface_doc.xpath('/interface/ifDescr').text
interface_enable = interface_doc.xpath('/interface/ifAdminStatus').text
interface_ipaddress = nil
ip_info = interface_doc.xpath('/interface/ifmAm4/am4CfgAddrs/am4CfgAddr')
ip_info.each do |node|
ip_node = Nokogiri::XML(node.to_s)
add_type = ip_node.xpath('/am4CfgAddr/addrType').text
next unless add_type == 'main'
ipaddress = ip_node.xpath('/am4CfgAddr/ifIpAddr').text
netmask = ip_node.xpath('/am4CfgAddr/subnetMask').text
interface_ipaddress = ipaddress + ' ' + netmask
break
end
property_hash = { ensure: :present }
property_hash[:name] = interface_name
property_hash[:description] = interface_des if interface_des
if interface_enable == 'up'
property_hash[:enable] = :true
elsif interface_enable == 'down'
property_hash[:enable] = :false
end
property_hash[:ipaddress] = if !interface_ipaddress.nil?
interface_ipaddress
else
'null'
end
l3_interface_array << property_hash
end
l3_interface_array
end
|