Class: AutomateIt::AddressManager

Inherits:
Plugin::Manager show all
Defined in:
lib/automateit/address_manager.rb

Overview

AddressManager

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

Defined Under Namespace

Classes: BSD, BaseDriver, FreeBSD, Linux, OpenBSD, Portable, SunOS

Constant Summary collapse

DEFAULT_ANNOUNCEMENTS =

Number of ARP announcements to make by default during #add.

3

Constants included from Constants

Constants::HELPERS_DIR, Constants::INSTALL_DIR, Constants::PERROR, Constants::PEXEC, Constants::PNOTE, Constants::WARNING_BOILERPLATE

Instance Attribute Summary

Attributes inherited from Plugin::Manager

#drivers

Attributes inherited from Common

#interpreter

Instance Method Summary collapse

Methods inherited from Plugin::Manager

#[], abstract_manager, alias_methods, #available?, #default, #default=, #dispatch, #dispatch_safely, #dispatch_safely_to, #dispatch_to, driver_classes, #driver_for, #driver_suitability_levels_for, inherited, #instantiate_drivers, #setup

Methods inherited from Plugin::Base

#setup, #token, token

Methods inherited from Common

#initialize, #log, #nitpick, #noop, #noop=, #noop?, #preview, #preview=, #preview?, #preview_for, #setup, #superuser?, #writing, #writing=, #writing?

Constructor Details

This class inherits a constructor from AutomateIt::Common

Instance Method Details

#add(opts) ⇒ Object

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)


38
# File 'lib/automateit/address_manager.rb', line 38

def add(opts) dispatch(opts) end

#addressesObject

Array of addresses for this host. Example:

addresses
=> ["10.0.0.10", "127.0.0.1"]


58
# File 'lib/automateit/address_manager.rb', line 58

def addresses() dispatch() end

#has?(opts) ⇒ Boolean

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

Returns:

  • (Boolean)


22
# File 'lib/automateit/address_manager.rb', line 22

def has?(opts) dispatch(opts) end

#hostnamesObject

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"]


69
# File 'lib/automateit/address_manager.rb', line 69

def hostnames() dispatch() end

#hostnames_for(hostname) ⇒ Object

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"]


78
# File 'lib/automateit/address_manager.rb', line 78

def hostnames_for(hostname) dispatch(hostname) end

#interfacesObject

Array of interfaces for this host. Example:

interfaces
=> ["eth0", "lo"]


63
# File 'lib/automateit/address_manager.rb', line 63

def interfaces() dispatch() end

#remove(opts) ⇒ Object

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")


53
# File 'lib/automateit/address_manager.rb', line 53

def remove(opts) dispatch(opts) end