Method: Puppet::NetDev::CE::CarApi#set_car

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

#set_car(resource) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/puppet/provider/ce/api/car/car_api.rb', line 67

def set_car(resource)
  session = Puppet::NetDev::CE::Device.session
  create_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="create"><carTmplName>' + (resource[:name]).to_s + '</carTmplName><cir>' + (resource[:speed]).to_s + '</cir><pir></pir><cbs></cbs><pbs></pbs></qosIfCarTmpl></qosIfCarTmpls></qos></config></edit-config></rpc>'
  session.rpc.do_config(create_car_xml)

  if !resource[:interface_name].nil? && !resource[:interface_name].empty?
    set_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="create"><ifName>' + (resource[:interface_name]).to_s + '</ifName><direction>inbound</direction><carTmplName>' + (resource[:name]).to_s + '</carTmplName></qosIfCar></qosIfCars></qosIfQoss></qos></config></edit-config></rpc>'
    session.rpc.do_config(set_car_apply_xml)
  end

  if !resource[:interface_name].nil? && resource[:interface_name].empty?
    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
 end
end