Method: Puppet::NetDev::CE::CarApi#get_car

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

#get_carObject



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

def get_car
car_array = []
session = Puppet::NetDev::CE::Device.session

get_car_xml = '<rpc><get><filter type="subtree"><qos xmlns="http://www.huawei.com/netconf/vrp" content-version="1.0" format-version="1.0"><qosIfCarTmpls><qosIfCarTmpl><carTmplName></carTmplName><cir></cir><pir></pir><cbs></cbs><pbs></pbs></qosIfCarTmpl></qosIfCarTmpls></qos></filter></get></rpc>'
car_all = session.rpc.do_config(get_car_xml)

if car_all.element_children.count != 0
  car_element = car_all.first_element_child.first_element_child
  car_element.element_children.each do |car_elem|
    car_doc_speed = Nokogiri::XML(car_elem.to_s)
    car_name = car_doc_speed.xpath('/qosIfCarTmpl/carTmplName').text
    car_speed = car_doc_speed.xpath('/qosIfCarTmpl/cir').text

    property_hash = { ensure: :present }
    property_hash[:name] = car_name
    property_hash[:speed] = car_speed

    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
        next unless car_name_get == car_name

        car_interface = car_doc.xpath('/qosIfCar/ifName').text
        property_hash[:interface_name] = car_interface
      end
  end

    car_array << property_hash
  end

 end
car_array
end