Sha256: ca23c7403e764a3d5c4da1553015918cf7ef7059d82912ada2e1e4c27b6adbfa

Contents?: true

Size: 1.62 KB

Versions: 10

Compression:

Stored size: 1.62 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`.match(/openbsd/i)}

  def suitability(method, *args) # :nodoc:
    # Must be higher than ::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

10 entries across 10 versions & 1 rubygems

Version Path
automateit-0.71031.1 lib/automateit/address_manager/openbsd.rb
automateit-0.71031.2 lib/automateit/address_manager/openbsd.rb
automateit-0.71030 lib/automateit/address_manager/openbsd.rb
automateit-0.71021 lib/automateit/address_manager/openbsd.rb
automateit-0.71101.2 lib/automateit/address_manager/openbsd.rb
automateit-0.71102 lib/automateit/address_manager/openbsd.rb
automateit-0.71103 lib/automateit/address_manager/openbsd.rb
automateit-0.71031 lib/automateit/address_manager/openbsd.rb
automateit-0.71101 lib/automateit/address_manager/openbsd.rb
automateit-0.71101.1 lib/automateit/address_manager/openbsd.rb