core/chef/cookbooks/network/recipes/default.rb
# given a conduit definition, resolve it down to a set of physical interfaces.
# The supported reference format is <sign><speed><#> where
#  * sign is optional, and determines behavior if exact match is not found.
#    + allows speed upgrade,
#    - allows downgrade, and
#    ? allows either. If no sign is specified, an exact match must be found.
#  * speed designates the interface speed. 10m, 100m, 1g and 10g are supported
#  * The final number designates the zero-based offset into the set of physical
#    interfaces that have the requested speed we want.
given a conduit definition, resolve it down to a set of physical interfaces.
The supported reference format is <#> where
sign is optional, and determines behavior if exact match is not found.
given a conduit definition resolve it down to a set of physical interfaces . The supported reference format is <# > where sign is optional and determines behavior if exact match is not found .
def resolve_conduit(conduit)
  if node["rebar_ohai"]["in_docker"]
    return ["eth0"]
  end
  if conduit.start_with?('raw:')
    return [conduit[4..-1]]
  end
  known_ifs = node["rebar"]["sorted_ifs"]
  speeds = %w{10m 100m 1g 10g}
  intf_re = /^([-+?]?)(\d{1,3}[mg])(\d+)$/
  finders = conduit.split(',').map{|f|f.strip}
  raise "#{conduit} does not want any interfaces!" if finders.nil? || finders.empty?
  finders = finders.map{|i|intf_re.match(i)}
  malformed = finders.find_all{|i|i.length != 4}
  raise "Malformed interface selectors: #{malformed}" unless malformed.empty?
  tmpl = finders[0]
  if ! finders.all? do |i|
      (i[1] == tmpl[1]) && (i[2] == tmpl[2])
    end
    raise "Interface selectors do not have the same speed and flags: #{conduit}"
  end
  speed_idx = speeds.index(tmpl[2])
  raise "Unknown requested speed #{template[2]}" unless speed_idx
  wanted_speeds = case tmpl[1]
                  when '+' then speeds[speed_idx..-1]
                  when "-" then speeds[0..speed_idx].reverse
                  when "?" then (speeds[speed_idx..-1] + (speeds[0..speed_idx].reverse)).uniq
                  else [tmpl[2]]
                  end
  wanted_speeds.each do |speed|
    candidates = known_ifs.select do |i|
     nic_speeds(i).first == speed
    end
    res = finders.map{|f|candidates[f[3].to_i]}.compact
    if res.length == finders.length
      return res
    end
  end
  raise "Cannot resolve conduit #{conduit} with known interfaces #{known_ifs}"
end
def resolve_conduit ( conduit ) if node [ "rebar_ohai" ] [ "in_docker" ] return [ "eth0" ] end if conduit . start_with? ( 'raw:' ) return [ conduit [ 4 .. - 1 ] ] end known_ifs = node [ "rebar" ] [ "sorted_ifs" ] speeds = %w{ 10m 100m 1g 10g } intf_re = / ^([-+?]?)( \d {1,3}[mg])( \d +)$ / finders = conduit . split ( ',' ) . map { | f | f . strip } raise "#{conduit} does not want any interfaces!" if finders . nil? || finders . empty? finders = finders . map { | i | intf_re . match ( i ) } malformed = finders . find_all { | i | i . length != 4 } raise "Malformed interface selectors: #{malformed}" unless malformed . empty? tmpl = finders [ 0 ] if ! finders . all? do | i | ( i [ 1 ] == tmpl [ 1 ] ) && ( i [ 2 ] == tmpl [ 2 ] ) end raise "Interface selectors do not have the same speed and flags: #{conduit}" end speed_idx = speeds . index ( tmpl [ 2 ] ) raise "Unknown requested speed #{template[2]}" unless speed_idx wanted_speeds = case tmpl [ 1 ] when '+' then speeds [ speed_idx .. - 1 ] when "-" then speeds [ 0 .. speed_idx ] . reverse when "?" then ( speeds [ speed_idx .. - 1 ] + ( speeds [ 0 .. speed_idx ] . reverse ) ) . uniq else [ tmpl [ 2 ] ] end wanted_speeds . each do | speed | candidates = known_ifs . select do | i | nic_speeds ( i ) . first == speed end res = finders . map { | f | candidates [ f [ 3 ] . to_i ] } . compact if res . length == finders . length return res end end raise "Cannot resolve conduit #{conduit} with known interfaces #{known_ifs}" end
given a conduit definition, resolve it down to a set of physical interfaces.
given a conduit definition resolve it down to a set of physical interfaces .
# At this point, the selectors are at least well-formed. Verify that they are sane. # The conduit looks sane, but is it requesting a speed we know about? # Check and see. # At this point, the conduit definition is sane. # Now, loop over all the wanted speeds until we find the interfaces with the desired # offsets. # Fastest speed is at the beginning, and that is all we care about comparing right now.
conduit
<not_specific>