Class: AutomateIt::AddressManager::Linux

Inherits:
BaseDriver show all
Defined in:
lib/automateit/address_manager/linux.rb

Overview

AddressManager::Linux

A Linux-specific driver for the AddressManager provides complete support for querying, adding and removing addresses on platforms that feature Linux-like tools.

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 BaseDriver

#has?, #hostnames, #hostnames_for

Methods inherited from Plugin::Driver

abstract_driver, #available?, base_driver, base_driver?, depends_on, inherited, manager_token, #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

See AddressManager#add



15
16
17
18
19
20
21
22
# File 'lib/automateit/address_manager/linux.rb', line 15

def add(opts)
  _add_helper(opts) do |opts|
    interpreter.sh(_ifconfig_helper(:add, opts))
    if interpreter.which("arping")
      interpreter.sh("arping -q -c #{opts[:announcements]} -w #{opts[:announcements]} -I #{opts[:device]} #{opts[:address]}")
    end
  end
end

#addressesObject

See AddressManager#addresses



38
39
40
41
# File 'lib/automateit/address_manager/linux.rb', line 38

def addresses()
  _raise_unless_available
  return `ifconfig`.scan(/inet6? addr:\s*(.+?)\s+/).flatten
end

#interfacesObject

See AddressManager#interfaces



32
33
34
35
# File 'lib/automateit/address_manager/linux.rb', line 32

def interfaces()
  _raise_unless_available
  return `ifconfig`.scan(/^(\w+?(?::\w+)?)\b\s+Link/).flatten
end

#remove(opts) ⇒ Object

See AddressManager#remove



25
26
27
28
29
# File 'lib/automateit/address_manager/linux.rb', line 25

def remove(opts)
  _remove_helper(opts) do |opts|
    interpreter.sh(_ifconfig_helper(:remove, opts))
  end
end

#suitability(method, *args) ⇒ Object

:nodoc:



10
11
12
# File 'lib/automateit/address_manager/linux.rb', line 10

def suitability(method, *args) # :nodoc:
  available? ? 2 : 0
end