Sha256: 23c06588b96afe70164dc58d3492787000181bea1f938642bf3c22feb3315237

Contents?: true

Size: 1.79 KB

Versions: 145

Compression:

Stored size: 1.79 KB

Contents

class Specinfra::Command::Darwin::Base::Interface < Specinfra::Command::Base::Interface
  class << self
    def check_exists(name)
      "ifconfig #{name}"
    end

    def check_has_ipv4_address(interface, ip_address)
      ip_address = ip_address.dup
      if ip_address =~ /\/\d+$/
        # remove the prefix - better would be to calculate the netmask
        ip_address.gsub!(/\/\d+$/, "")
      end
      ip_address << " "
      ip_address.gsub!(".", "\\.")
      "ifconfig #{interface} inet | grep 'inet #{ip_address}'"
    end

    def check_has_ipv6_address(interface, ip_address)
      ip_address = ip_address.dup
      (ip_address, prefixlen) = ip_address.split(/\//)
      ip_address.downcase!
      if ip_address =~ /^fe80::/i
        # link local needs the scope (interface) appended
        ip_address << "%#{interface}"
      end
      unless prefixlen.to_s.empty?
        # append prefixlen
        ip_address << " prefixlen #{prefixlen}"
      else
        ip_address << " "
      end
      "ifconfig #{interface} inet6 | grep 'inet6 #{ip_address}'"
    end

    def get_ipv4_address(interface)
      "ifconfig #{interface} inet | grep inet | awk '{print $2}'"
    end

    def get_ipv6_address(interface)
      # Awk refuses to print '/' even with using escapes or hex so workaround with sed employed here.
      "ifconfig #{interface} inet6 | grep inet6 | awk '{print $2$3$4}' | sed 's/prefixlen/\//'; exit"
    end

    def get_link_state(interface)
      # Checks if interfaces is administratively up with the -u arg.
      # L1 check via status. Virtual interfaces like tapX missing the status will report up.
      # Emulates operstate in linux with exception of the unknown status.
      %Q{ifconfig -u #{interface} 2>&1 | awk -v s=up '/status:/ && $2 != "active" { s="down" }; END {print s}'}
    end
  end
end

Version data entries

145 entries across 145 versions & 1 rubygems

Version Path
specinfra-2.91.0 lib/specinfra/command/darwin/base/interface.rb
specinfra-2.90.1 lib/specinfra/command/darwin/base/interface.rb
specinfra-2.90.0 lib/specinfra/command/darwin/base/interface.rb
specinfra-2.89.0 lib/specinfra/command/darwin/base/interface.rb
specinfra-2.88.2 lib/specinfra/command/darwin/base/interface.rb
specinfra-2.88.1 lib/specinfra/command/darwin/base/interface.rb
specinfra-2.88.0 lib/specinfra/command/darwin/base/interface.rb
specinfra-2.87.2 lib/specinfra/command/darwin/base/interface.rb
specinfra-2.87.1 lib/specinfra/command/darwin/base/interface.rb
specinfra-2.87.0 lib/specinfra/command/darwin/base/interface.rb
specinfra-2.86.0 lib/specinfra/command/darwin/base/interface.rb
specinfra-2.85.1 lib/specinfra/command/darwin/base/interface.rb
specinfra-2.85.0 lib/specinfra/command/darwin/base/interface.rb
specinfra-2.84.1 lib/specinfra/command/darwin/base/interface.rb
specinfra-2.84.0 lib/specinfra/command/darwin/base/interface.rb
specinfra-2.83.4 lib/specinfra/command/darwin/base/interface.rb
specinfra-2.83.3 lib/specinfra/command/darwin/base/interface.rb
specinfra-2.83.2 lib/specinfra/command/darwin/base/interface.rb
specinfra-2.83.1 lib/specinfra/command/darwin/base/interface.rb
specinfra-2.83.0 lib/specinfra/command/darwin/base/interface.rb