Sha256: 09113e89ef2a6ba598aa7bd84abc360088b47410d0c572636935c2df2ac1b4da

Contents?: true

Size: 1.66 KB

Versions: 6

Compression:

Stored size: 1.66 KB

Contents

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

  depends_on :programs => %w(ifconfig uname),
    :callbacks => lambda{`uname -s 2>&1`.match(/openbsd/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(_openbsd_ifconfig_helper(:add, opts))
    end
  end

  # See AddressManager#remove
  def remove(opts)
    _remove_helper(opts) do |opts|
      interpreter.sh(_openbsd_ifconfig_helper(:remove, opts))
      true
    end
  end
  
  # See AddressManager#addresses
  def addresses()
    _raise_unless_available
    # OpenBSD requires an "-A" to display aliases, not the usual "-a"
    return `ifconfig -A`.scan(/\s+inet\s+([^\s]+)\s+/).flatten
  end
  
  # See AddressManager#has?
  def has?(opts)
    opts2 = opts.clone
    is_alias = opts2.delete(:label)
    return super(opts2)
  end
  
protected

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

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
automate-it-0.9.2 lib/automateit/address_manager/openbsd.rb
automate-it-0.9.1 lib/automateit/address_manager/openbsd.rb
automate-it-0.9.0 lib/automateit/address_manager/openbsd.rb
automateit-0.71230 lib/automateit/address_manager/openbsd.rb
automateit-0.80624 lib/automateit/address_manager/openbsd.rb
automateit-0.80116 lib/automateit/address_manager/openbsd.rb