Class: NetdevJunos::Resource

Inherits:
Netconf::JunosConfig
  • Object
show all
Defined in:
lib/puppet/provider/junos/junos_netdev_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.



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/puppet/provider/junos/junos_netdev_res.rb', line 53

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
end

Instance Attribute Details

#edit_itemObject (readonly)

Returns the value of attribute edit_item.



51
52
53
# File 'lib/puppet/provider/junos/junos_netdev_res.rb', line 51

def edit_item
  @edit_item
end

#rpcObject (readonly)

Returns the value of attribute rpc.



51
52
53
# File 'lib/puppet/provider/junos/junos_netdev_res.rb', line 51

def rpc
  @rpc
end

Instance Method Details

#[](key) ⇒ Object


Hash/parameter methods




71
72
73
# File 'lib/puppet/provider/junos/junos_netdev_res.rb', line 71

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

#[]=(key, value) ⇒ Object



75
76
77
# File 'lib/puppet/provider/junos/junos_netdev_res.rb', line 75

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

#del(name) ⇒ Object



84
85
86
87
# File 'lib/puppet/provider/junos/junos_netdev_res.rb', line 84

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

#getconfigObject



143
144
145
# File 'lib/puppet/provider/junos/junos_netdev_res.rb', line 143

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

#is_new?Boolean

Returns:

  • (Boolean)


160
161
162
# File 'lib/puppet/provider/junos/junos_netdev_res.rb', line 160

def is_new?
  return @ndev_hash[:name].nil?
end

#netdev_on_makeconfig_xml(xml, netdev_res) ⇒ Object

this method gets called when the provider adds the resource contents to the NetdevJunos managed object. Refer to NetdevJunos#edit_config



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/puppet/provider/junos/junos_netdev_res.rb', line 93

def netdev_on_makeconfig_xml( xml, netdev_res )
  
  if netdev_res[:junos_delete]
    @pp_obj.netdev_resxml_delete( xml )
    return
  end        
  
  if @property_hash.empty?      
    
    @top_xml ||= @pp_obj.netdev_resxml_top( xml )
    unless @pp_obj.ndev_res[:unmanaged_active]
      unless @pp_obj.resource[:active] == @pp_obj.ndev_res[:active]
        @pp_obj.netdev_resxml_change_active( @top_xml ) 
      end
    end
    dot = @pp_obj.netdev_resxml_edit( @top_xml )
    @pp_obj.netdev_resxml_new( dot )       
    
  else
            
    @top_xml ||= @pp_obj.netdev_resxml_top( xml )
    
    if @property_hash.delete :active
      @pp_obj.netdev_resxml_change_active( 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    
  
end

#netdev_resxml_topObject


This following is used to generate the XML needed to
get the configuration for the given resource from device



133
134
135
136
137
138
139
140
141
# File 'lib/puppet/provider/junos/junos_netdev_res.rb', line 133

def netdev_resxml_top
  cfg = Netconf::JunosConfig.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

method to extract the ‘active/inactive’ state from the Junos configuration item.



154
155
156
157
158
# File 'lib/puppet/provider/junos/junos_netdev_res.rb', line 154

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



79
80
81
82
# File 'lib/puppet/provider/junos/junos_netdev_res.rb', line 79

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