Class: Puppet::NetDev::CE::InterfaceApi

Inherits:
ApiBase
  • Object
show all
Defined in:
lib/puppet/provider/ce/api/interface/interface_api.rb

Instance Method Summary collapse

Constructor Details

#initializeInterfaceApi

Returns a new instance of InterfaceApi.

[View source]

22
23
24
# File 'lib/puppet/provider/ce/api/interface/interface_api.rb', line 22

def initialize
  super()
end

Instance Method Details

#get_interfaceObject

[View source]

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

def get_interface
  interface_array = []
  session = Puppet::NetDev::CE::Device.session

  get_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></interface></interfaces></ifm></filter></get></rpc>'

  interface_all = session.rpc.do_config(get_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_name = interface_doc.xpath('/interface/ifName').text
    interface_des = interface_doc.xpath('/interface/ifDescr').text
    interface_enable = interface_doc.xpath('/interface/ifAdminStatus').text

    property_hash = {}
    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

    interface_array << property_hash
  end

  interface_array
end

#set_interface(resource) ⇒ Object

[View source]

58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/puppet/provider/ce/api/interface/interface_api.rb', line 58

def set_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

  set_interface_xml += '</interface></interfaces></ifm></config></edit-config></rpc>'

  session.rpc.do_config(set_interface_xml)
end