Sha256: b31196feae661d099fcc0c18b2a865bc62b0149cb3da29a412ca1fd8fb9ba100

Contents?: true

Size: 1.54 KB

Versions: 9

Compression:

Stored size: 1.54 KB

Contents

class Specinfra::Command::Freebsd::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_link_state(interface)
      str = %Q{ ifconfig #{interface} link | \
            awk '/flags/{ \
                   split($0,line,/ /) ; \
                   split(line[2],flags,/[,<>]/); \
                   for (idx in flags) { \
                     if (flags[idx] == "UP"){ \
                       print "up"; \
                       exit 0 ; \
                     } \
                   }; \
                   print "down"; \
                 }'}
      str
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
specinfra-2.43.2 lib/specinfra/command/freebsd/base/interface.rb
specinfra-2.43.1 lib/specinfra/command/freebsd/base/interface.rb
specinfra-2.43.0 lib/specinfra/command/freebsd/base/interface.rb
specinfra-2.42.2 lib/specinfra/command/freebsd/base/interface.rb
specinfra-2.42.1 lib/specinfra/command/freebsd/base/interface.rb
specinfra-2.42.0 lib/specinfra/command/freebsd/base/interface.rb
specinfra-2.41.1 lib/specinfra/command/freebsd/base/interface.rb
specinfra-2.41.0 lib/specinfra/command/freebsd/base/interface.rb
specinfra-2.40.2 lib/specinfra/command/freebsd/base/interface.rb