Class: Puppet::Provider::Junos::Interface

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

Instance Method Summary collapse

Instance Method Details

#default_descriptionObject



94
95
96
# File 'lib/puppet/provider/junos/junos_interface.rb', line 94

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

#init_resourceObject


called from #netdev_exists?




80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/puppet/provider/junos/junos_interface.rb', line 80

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
68
69
70
71
72
73
74
# File 'lib/puppet/provider/junos/junos_interface.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
  
  phy_options = ifd.xpath('ether-options')
  
  if phy_options.empty?
    @ndev_res[:speed] = :auto
    @ndev_res[:duplex] = :auto
  else 
    
    @ndev_res[:duplex] = case phy_options.xpath('link-mode').text.chomp
      when 'full-duplex' then :full
      when 'half-duplex' then :half
      else :auto
    end
    
    if speed = phy_options.xpath('speed')[0]
      @ndev_res[:speed] = speed_from_junos( speed.first_element_child.name )
    else
      @ndev_res[:speed] = :auto
    end
  end
  
  return true     
end

#speed_from_junos(jval) ⇒ Object



107
108
109
110
111
112
113
114
# File 'lib/puppet/provider/junos/junos_interface.rb', line 107

def speed_from_junos( jval )
  case jval
    when 'ethernet-100m' then :'100m'
    when 'ethernet-10m' then :'10m'
    when 'ethernet-1g' then :'1g'
    else :auto
  end
end

#speed_to_junos(pval) ⇒ Object



98
99
100
101
102
103
104
105
# File 'lib/puppet/provider/junos/junos_interface.rb', line 98

def speed_to_junos( pval )
  case pval
     when :'1g' then :'ethernet-1g'
     when :'100m' then :'ethernet-100m'
     when :'10m' then :'ethernet-10m'
     else :auto
  end        
end

#xml_change_admin(xml) ⇒ Object



128
129
130
131
132
133
# File 'lib/puppet/provider/junos/junos_interface.rb', line 128

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



135
136
137
# File 'lib/puppet/provider/junos/junos_interface.rb', line 135

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

#xml_change_duplex(xml) ⇒ Object



154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/puppet/provider/junos/junos_interface.rb', line 154

def xml_change_duplex( xml )     
  xml.send(:'ether-options') {
    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




120
121
122
123
124
125
126
# File 'lib/puppet/provider/junos/junos_interface.rb', line 120

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



139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/puppet/provider/junos/junos_interface.rb', line 139

def xml_change_speed( xml )         
  xml.send(:'ether-options') {
    xml.speed {
      if resource[:speed] == :auto
        if not @ndev_res.is_new?
          jval = speed_to_junos( @ndev_res[:speed] )
          xml.send( jval, Netconf::JunosConfig::DELETE )
        end
      else
        xml.send( speed_to_junos( resource[:speed] ))
      end
    }
  }    
end