Class: Puppet::Provider::Junos::InterfaceClassic

Inherits:
Puppet::Provider::Junos
  • Object
show all
Defined in:
lib/puppet/provider/junos/junos_interface_classic.rb

Instance Method Summary collapse

Instance Method Details

#default_descriptionObject



87
88
89
# File 'lib/puppet/provider/junos/junos_interface_classic.rb', line 87

def default_description
  "Puppet created interface: #{resource[:name]}"
end

#init_resourceObject


called from #netdev_exists?




73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/puppet/provider/junos/junos_interface_classic.rb', line 73

def init_resource
  
  resource[:mtu] ||= -1    
  resource[:description] ||= default_description
  
  @ndev_res ||= NetdevJunos::Resource.new( self, "interfaces", "interface" ) 
  
  ndev_config = @ndev_res.getconfig
  return false unless (ifd = ndev_config.xpath('//interface')[0])
  
  @ndev_res.set_active_state( ifd )
  return ifd
end

#netdev_res_exists?Boolean


triggered from Provider #exists?


Returns:

  • (Boolean)


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/puppet/provider/junos/junos_interface_classic.rb', line 45

def netdev_res_exists?
          
  return false unless (ifd = init_resource)
  
  @ndev_res[:description] = ifd.xpath('description').text.chomp
  @ndev_res[:admin] = ifd.xpath('disable').empty? ? :up : :down
  @ndev_res[:mtu] = (mtu = ifd.xpath('mtu')[0]).nil? ? -1 : mtu.text.to_i
      
  @ndev_res[:duplex] = case ifd.xpath('link-mode').text.chomp
    when 'full-duplex' then :full
    when 'half-duplex' then :half
    else
      if Facter.value('hardwaremodel') =~ /^ex4300/i
        :full
      else
        :auto
      end
  end
    
  @ndev_res[:speed] = ( speed = ifd.xpath('speed')[0] ) ? speed.text : :auto
        
  return true     
end

#xml_change_admin(xml) ⇒ Object



103
104
105
106
107
108
# File 'lib/puppet/provider/junos/junos_interface_classic.rb', line 103

def xml_change_admin( xml )
  return xml.disable if resource[:admin] == :down
  return if @ndev_res.is_new?
  # must be up
  xml.disable Netconf::JunosConfig::DELETE
end

#xml_change_description(xml) ⇒ Object



110
111
112
# File 'lib/puppet/provider/junos/junos_interface_classic.rb', line 110

def xml_change_description( xml )
  xml.description resource[:description]
end

#xml_change_duplex(xml) ⇒ Object



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/puppet/provider/junos/junos_interface_classic.rb', line 124

def xml_change_duplex( xml )
 if Facter.value('hardwaremodel') =~ /^ex4300/i
   return (resource[:duplex] == :full) ? nil : (NetdevJunos::Log.notice "On EX4300 switches, the interfaces operate in full duplex mode only. Duplex attribute value \'#{resource[:duplex]}\' will be ignored")
 end  
 if resource[:duplex] == :auto
    unless @ndev_res.is_new?
      xml.send( :'link-mode', Netconf::JunosConfig::DELETE )
    end
  else
    xml.send( :'link-mode', case resource[:duplex]
      when :full then 'full-duplex'
      when :half then 'half-duplex'
      end )
  end
end

#xml_change_mtu(xml) ⇒ Object


XML builder methods




95
96
97
98
99
100
101
# File 'lib/puppet/provider/junos/junos_interface_classic.rb', line 95

def xml_change_mtu( xml )
  if resource[:mtu] > 0
    xml.mtu resource[:mtu]
  else
    xml.mtu( Netconf::JunosConfig::DELETE )
  end
end

#xml_change_speed(xml) ⇒ Object



114
115
116
117
118
119
120
121
122
# File 'lib/puppet/provider/junos/junos_interface_classic.rb', line 114

def xml_change_speed( xml )         
  if resource[:speed] == :auto
    if not @ndev_res.is_new?
      xml.speed Netconf::JunosConfig::DELETE 
    end
  else
    xml.speed resource[:speed] 
  end
end