Method: Puppet::NetDev::CE::CarApi#delete_car

Defined in:
lib/puppet/provider/ce/api/car/car_api.rb

#delete_car(resource) ⇒ Object



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
# File 'lib/puppet/provider/ce/api/car/car_api.rb', line 105

def delete_car(resource)
session = Puppet::NetDev::CE::Device.session
car_interface = nil
get_car_apply_xml = '<rpc><get><filter type="subtree"><qos xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><qosIfQoss><qosIfCars><qosIfCar><ifName></ifName><direction>inbound</direction><carTmplName></carTmplName></qosIfCar></qosIfCars></qosIfQoss></qos></filter></get></rpc>'
car_apply_all = session.rpc.do_config(get_car_apply_xml)

if car_apply_all.element_children.count != 0
  car_apply_elements = car_apply_all.first_element_child.first_element_child.first_element_child
  car_apply_elements.element_children.each do |car_apply_elem|
    car_doc = Nokogiri::XML(car_apply_elem.to_s)
    car_name_get = car_doc.xpath('/qosIfCar/carTmplName').text
    if car_name_get == resource[:name]
      car_interface = car_doc.xpath('/qosIfCar/ifName').text
     end
  end
    end

unless car_interface.nil?
  delete_car_apply_xml = '<rpc><edit-config><target><running/></target><default-operation>merge</default-operation><error-option>rollback-on-error</error-option><config><qos xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><qosIfQoss><qosIfCars><qosIfCar operation="delete"><ifName>' + car_interface.to_s + '</ifName><direction>inbound</direction></qosIfCar></qosIfCars></qosIfQoss></qos></config></edit-config></rpc>'
  session.rpc.do_config(delete_car_apply_xml)
end

delete_car_xml = '<rpc><edit-config><target><running/></target><default-operation>merge</default-operation><error-option>rollback-on-error</error-option><config><qos xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><qosIfCarTmpls><qosIfCarTmpl operation="delete"><carTmplName>' + (resource[:name]).to_s + '</carTmplName></qosIfCarTmpl></qosIfCarTmpls></qos></config></edit-config></rpc>'
session.rpc.do_config(delete_car_xml)
end