Class: AutomateIt::AddressManager::BaseDriver

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

Overview

AddressManager::BaseDriver

Base class for all AddressManager drivers.

Direct Known Subclasses

BSD, FreeBSD, Linux, OpenBSD, Portable, SunOS

Constant Summary

Constants inherited from Plugin::Driver

Plugin::Driver::BASE_DRIVER_NAME

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::Driver

#manager

Attributes inherited from Common

#interpreter

Instance Method Summary collapse

Methods inherited from Plugin::Driver

abstract_driver, #available?, base_driver, base_driver?, depends_on, inherited, manager_token, #setup, #suitability

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

#has?(opts) ⇒ Boolean

See AddressManager#has?

Returns:

  • (Boolean)

Raises:

  • (ArgumentError)


33
34
35
36
37
38
39
40
# File 'lib/automateit/address_manager/base.rb', line 33

def has?(opts)
  raise ArgumentError.new(":device or :address must be specified") unless opts[:device] or opts[:address]
  result = true
  result &= manager.interfaces.include?(opts[:device]) if opts[:device] and not opts[:label]
  result &= manager.interfaces.include?(opts[:device]+":"+opts[:label]) if opts[:device] and opts[:label]
  result &= manager.addresses.include?(opts[:address]) if opts[:address]
  return result
end

#hostnamesObject

See AddressManager#hostnames



8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/automateit/address_manager/base.rb', line 8

def hostnames()
  # NOTE: depends on driver's implementation of addresses
  names = manager.addresses.inject(Set.new) do |sum, address|
    # Some addresses can't be resolved, bummer.
    sum.merge(Resolv.getnames(address)) rescue Resolv::ResolvError; sum
  end
  names << Socket.gethostname
  names.merge(Socket.gethostbyname(Socket.gethostname)[1]) rescue SocketError

  names.each{|name| names.merge(hostnames_for(name))}
  names << "localhost"
  return names.to_a.sort
end

#hostnames_for(hostname) ⇒ Object

See AddressManager#hostname_for



23
24
25
26
27
28
29
30
# File 'lib/automateit/address_manager/base.rb', line 23

def hostnames_for(hostname)
  results = []
  elements = hostname.split(".")
  for i in 1..elements.size
    results << elements[0..i-1].join(".")
  end
  return results.to_a.sort
end