Class: AutomateIt::AddressManager::BaseDriver
- Inherits:
-
Plugin::Driver
- Object
- Common
- Plugin::Base
- Plugin::Driver
- AutomateIt::AddressManager::BaseDriver
- Defined in:
- lib/automateit/address_manager/base.rb
Overview
AddressManager::BaseDriver
Base class for all AddressManager drivers.
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
Attributes inherited from Common
Instance Method Summary collapse
-
#has?(opts) ⇒ Boolean
See AddressManager#has?.
-
#hostnames ⇒ Object
See AddressManager#hostnames.
-
#hostnames_for(hostname) ⇒ Object
See AddressManager#hostname_for.
Methods inherited from Plugin::Driver
abstract_driver, #available?, base_driver, base_driver?, depends_on, inherited, manager_token, #setup, #suitability
Methods inherited from Plugin::Base
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?
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 |
#hostnames ⇒ Object
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 |