Sha256: 675ae0371e625caee28645f680f9ea1e7bcb3387e8722e34da981e37178d94cb

Contents?: true

Size: 1.42 KB

Versions: 8

Compression:

Stored size: 1.42 KB

Contents

# == AddressManager::FreeBSD
#
# A FreeBSD-specific driver for the AddressManager provides complete support for
# querying, adding and removing addresses.
class AutomateIt::AddressManager::FreeBSD < AutomateIt::AddressManager::BaseDriver
  def self.token
    :freebsd
  end

  depends_on :programs => %w(ifconfig uname),
    :callbacks => lambda{`uname -s 2>&1`.match(/freebsd/i)}

  def suitability(method, *args) # :nodoc:
    # Must be higher than AddressManager::BSD
    available? ? 3 : 0
  end

  # See AddressManager#add
  def add(opts)
    _add_helper(opts) do |opts|
      interpreter.sh(_freebsd_ifconfig_helper(:add, opts))
    end
  end

  # See AddressManager#remove
  def remove(opts)
    _remove_helper(opts) do |opts|
      interpreter.sh(_freebsd_ifconfig_helper(:remove, opts))
      true
    end
  end
  
  # See AddressManager#has?
  def has?(opts)
    opts2 = opts.clone
    is_alias = opts2.delete(:label)
    return super(opts2)
  end
  
protected

  # ifconfig fxp0 inet 172.16.1.3 netmask 255.255.255.255 alias
  def _freebsd_ifconfig_helper(action, opts)    
    helper_opts = {:state => false, :prepend => %w(inet)}
    opts2 = opts.clone
    if opts2.delete(:label)
      helper_opts[:append] = \
        case action
        when :add: %w(alias)
        when :remove, :del: %w(-alias)
        else ArgumentError.new("Unknown action: #{action}")
        end
    end
    return _ifconfig_helper(action, opts2, helper_opts)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
automateit-0.71111 lib/automateit/address_manager/freebsd.rb
automateit-0.71112 lib/automateit/address_manager/freebsd.rb
automateit-0.71219 lib/automateit/address_manager/freebsd.rb
automateit-0.71220 lib/automateit/address_manager/freebsd.rb
automateit-0.71221 lib/automateit/address_manager/freebsd.rb
automateit-0.71104 lib/automateit/address_manager/freebsd.rb
automateit-0.71226.1 lib/automateit/address_manager/freebsd.rb
automateit-0.71226 lib/automateit/address_manager/freebsd.rb