class AutomateIt::AddressManager

AddressManager

The AddressManager provides a way to query, add and remove network addresses on a host.

Constants

DEFAULT_ANNOUNCEMENTS

Number of ARP announcements to make by default during add.

Public Instance Methods

add(opts) click to toggle source

Add address to host if it doesn’t have it. Requires root-level access. Returns true if action was taken and succeeded.

Arguments hash must include either a :device (e.g., “eth0”) or :address (e.g., “10.0.0.10”), and an optional :label (e.g., “foo”) and :mask (e.g. “24”).

An optional number of ARP :announcements may be specified, defaulting to AutomateIt::AddressManager::DEFAULT_ANNOUNCEMENTS. Drivers that handle announcements will block an extra second while making each announcement.

Example:

add(:address => "10.0.0.10", :mask => 24, :device => "eth0",
  :label => "foo", :announcements => 3)
# File lib/automateit/address_manager.rb, line 38
def add(opts) dispatch(opts) end
addresses() click to toggle source

Array of addresses for this host. Example:

addresses
=> ["10.0.0.10", "127.0.0.1"]
# File lib/automateit/address_manager.rb, line 58
def addresses() dispatch() end
has?(opts) click to toggle source

Does host have an address or interface? Arguments hash must include either a :device (e.g., “eth0”) or :address (e.g., “10.0.0.10”), and an optional :label (e.g., “foo”). Note that an interface is the combination of a :device and :label, so “eth0” isn’t the same as “eth0:foo”.

Examples on a host with address “10.0.0.10” on interface “eth0:foo”:

has?(:address => "10.0.0.10")
=> true
has?(:address => "10.0.0.10", :device => "eth0")
=> false
has?(:address => "10.0.0.10", :device => "eth0", :label => "foo")
=> true
has?(:device => "eth0")
=> false
has?(:device => "eth0", :label => "foo")
=> true
# File lib/automateit/address_manager.rb, line 22
def has?(opts) dispatch(opts) end
hostnames() click to toggle source

Array of hostnames for this host, including variants by trying to resolve names for all addresses owned by this host. Example:

hostnames
=> ["kagami", "kagami.lucky-channel", "kagami.lucky-channel.jp"]
# File lib/automateit/address_manager.rb, line 69
def hostnames() dispatch() end
hostnames_for(hostname) click to toggle source

Array of hostname variants for this hostname. This method performs no name resolution and simply infers a less qualified name from a more qualified hostname argument. Example:

hostnames_for("kagami.lucky-channel")
=> ["kagami", "kagami.lucky-channel"]
hostnames_for("kagami")
=> ["kagami"]
# File lib/automateit/address_manager.rb, line 78
def hostnames_for(hostname) dispatch(hostname) end
interfaces() click to toggle source

Array of interfaces for this host. Example:

interfaces
=> ["eth0", "lo"]
# File lib/automateit/address_manager.rb, line 63
def interfaces() dispatch() end
remove(opts) click to toggle source

Remove address from host if it has it. Requires root-level access. Returns true if action was taken and succeeded.

Arguments hash must include either a :device (e.g., “eth0”) or :address (e.g., “10.0.0.10”), and an optional :label (e.g., “foo”) and :mask (e.g. “24”).

Example:

remove(:address => "10.0.0.10", :mask => 24, :device => "eth0",
  :label => "foo")
# File lib/automateit/address_manager.rb, line 53
def remove(opts) dispatch(opts) end