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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'lib/puppet/provider/ce/api/l3_interface/l3_interface_api.rb', line 81
def set_l3_interface(resource)
session = Puppet::NetDev::CE::Device.session
set_interface_xml = '<rpc><edit-config><target><running/></target><default-operation>merge</default-operation><error-option>rollback-on-error</error-option><config><ifm xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><interfaces><interface operation="merge"><ifName>' + (resource[:name]).to_s + '</ifName>'
if resource[:description]
set_interface_xml += '<ifDescr>' + (resource[:description]).to_s + '</ifDescr>'
end
if resource[:enable] == :true
set_interface_xml += '<ifAdminStatus>up</ifAdminStatus>'
end
if resource[:enable] == :false
set_interface_xml += '<ifAdminStatus>down</ifAdminStatus>'
end
if resource[:ipaddress] && resource[:ipaddress] != 'null'
ipadd_and_mask = resource[:ipaddress].split
if ipadd_and_mask.count == 2
ip_address = ipadd_and_mask[0]
net_mask = ipadd_and_mask[1]
set_interface_xml += '<ifmAm4><am4CfgAddrs><am4CfgAddr operation="merge"><ifIpAddr>' + ip_address.to_s + '</ifIpAddr><subnetMask>' + net_mask.to_s + '</subnetMask><addrType>main</addrType></am4CfgAddr></am4CfgAddrs></ifmAm4>'
end
end
if resource[:ipaddress] == 'null'
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>' + (resource[:name]).to_s + '</ifName><ifmAm4></ifmAm4></interface></interfaces></ifm></filter></get></rpc>'
main_ipaddress_exist = false
main_ipaddress = '0.0.0.0'
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)
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
main_ipaddress_exist = true
main_ipaddress = ipaddress
break
end
end
if main_ipaddress_exist == true
set_interface_xml += '<ifmAm4><am4CfgAddrs><am4CfgAddr operation="delete"><ifIpAddr>' + main_ipaddress + '</ifIpAddr></am4CfgAddr></am4CfgAddrs></ifmAm4>'
end
end
set_interface_xml += '</interface></interfaces></ifm></config></edit-config></rpc>'
session.rpc.do_config(set_interface_xml)
end
|