class Specinfra::Command::Freebsd::Base::Interface

Public Class Methods

check_exists(name) click to toggle source
# File lib/specinfra/command/freebsd/base/interface.rb, line 3
def check_exists(name)
  "ifconfig #{name}"
end
check_has_ipv4_address(interface, ip_address) click to toggle source
# File lib/specinfra/command/freebsd/base/interface.rb, line 15
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
check_has_ipv6_address(interface, ip_address) click to toggle source
# File lib/specinfra/command/freebsd/base/interface.rb, line 26
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
get_ipv4_address(interface) click to toggle source
# File lib/specinfra/command/freebsd/base/interface.rb, line 43
def get_ipv4_address(interface)
  "ifconfig #{interface} inet | grep inet | awk '{print $2}'"
end
get_ipv6_address(interface) click to toggle source
# File lib/specinfra/command/freebsd/base/interface.rb, line 47
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
get_mtu_of(name) click to toggle source
# File lib/specinfra/command/freebsd/base/interface.rb, line 11
def get_mtu_of(name)
  "ifconfig #{name} | awk '/mtu /{print $NF}'"
end
get_speed_of(name) click to toggle source
# File lib/specinfra/command/freebsd/base/interface.rb, line 7
def get_speed_of(name)
  "ifconfig #{name} | awk '/media:/{if(match($0,/[0-9]+/)){ print substr($0, RSTART, RLENGTH);}}'"
end