Class: NetdevComware::Resource

Inherits:
Netconf::ComwareConfig
  • Object
show all
Defined in:
lib/puppet/provider/comware/comware_res.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pp_obj, edit_path, edit_item = nil) ⇒ Resource

Returns a new instance of Resource.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/puppet/provider/comware/comware_res.rb', line 7

def initialize( pp_obj, edit_path, edit_item = nil )
  @edit_path = edit_path
  @edit_item = edit_item
  super( :edit => edit_path, :build => method(:netdev_on_makeconfig_xml) )

  @pp_obj = pp_obj
  @property_hash = pp_obj.instance_variable_get(:@property_hash)

  @rpc = pp_obj.netdev_get.netconf.rpc

  @ndev_hash = Hash.new
  @ndev_hash[:active] = :true    # config items are active by default
  @ndev_hash[:netconf_op] = Netconf::Operation::GET
end

Instance Attribute Details

#edit_itemObject (readonly)

Returns the value of attribute edit_item.



5
6
7
# File 'lib/puppet/provider/comware/comware_res.rb', line 5

def edit_item
  @edit_item
end

#rpcObject (readonly)

Returns the value of attribute rpc.



5
6
7
# File 'lib/puppet/provider/comware/comware_res.rb', line 5

def rpc
  @rpc
end

Instance Method Details

#[](key) ⇒ Object



22
23
24
# File 'lib/puppet/provider/comware/comware_res.rb', line 22

def [](key)
  @ndev_hash[key]
end

#[]=(key, value) ⇒ Object



26
27
28
# File 'lib/puppet/provider/comware/comware_res.rb', line 26

def []=(key,value)
  @ndev_hash[key] = value
end

#change_edit_path(edit_path) ⇒ Object



54
55
56
57
# File 'lib/puppet/provider/comware/comware_res.rb', line 54

def change_edit_path(edit_path)
  @edit_path = edit_path
  @edit_path = "#{@doc_ele}/#{edit_path.strip}" unless @doc_ele.empty?
end

#del(name) ⇒ Object



35
36
37
38
# File 'lib/puppet/provider/comware/comware_res.rb', line 35

def del( name )
  self << { :name => name, :comware_delete => true }
  @deleted = true
end

#getconfigObject



50
51
52
# File 'lib/puppet/provider/comware/comware_res.rb', line 50

def getconfig
  got_config = @rpc.get_configuration(netdev_resxml_top)
end

#netdev_on_makeconfig_xml(xml, netdev_res) ⇒ Object



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/puppet/provider/comware/comware_res.rb', line 66

def netdev_on_makeconfig_xml(xml, netdev_res)
  if netdev_res[:comware_delete]
    @pp_obj.netdev_resxml_delete(xml)
    return
  end

  #if @edit_top = false means that we only want to use netdev_resxml_edit method to construct
  #our xml packet for edit_config in flush.This often happens when the edit_config involving multiple
  #tables
  case @ndev_hash[:netconf_op]
    when Netconf::Operation::CREATE
      @top_xml ||= @pp_obj.netdev_resxml_create_top( xml )
    when Netconf::Operation::MERGE
      @top_xml ||= @pp_obj.netdev_resxml_merge_top( xml )
    when Netconf::Operation::REPLACE
      @top_xml ||= @pp_obj.netdev_resxml_replace_top( xml )
    else
      @top_xml ||= @pp_obj.netdev_resxml_top( xml )
  end

  dot = @pp_obj.netdev_resxml_edit( @top_xml )
  @property_hash.each do |k,v|
    @pp_obj.send("xml_change_#{k}", dot )
  end
end

#netdev_resxml_topObject



40
41
42
43
44
45
46
47
48
# File 'lib/puppet/provider/comware/comware_res.rb', line 40

def netdev_resxml_top
  cfg = Netconf::ComwareConfig.new(:TOP)
  xml = cfg.doc
  at_ele = cfg.edit_path( xml, @edit_path )
  Nokogiri::XML::Builder.with( at_ele ) do |dot|
    @pp_obj.netdev_resxml_top( dot )
  end
  return xml
end

#set_active_state(ndev_xml) ⇒ Object

flush method use #ndev_res to decide flush or not



60
61
62
63
64
# File 'lib/puppet/provider/comware/comware_res.rb', line 60

def set_active_state( ndev_xml )
  #@ndev_hash[:active] = ndev_xml['inactive'] ? :false : :true
  @pp_obj.ndev_res[:name] = @pp_obj.resource[:name]
  ndev_xml
end

#update(name) ⇒ Object



30
31
32
33
# File 'lib/puppet/provider/comware/comware_res.rb', line 30

def update( name )
  return if defined? @deleted
  self << {:name => name }
end