Class: RedZone::Machine

Inherits:
Object
  • Object
show all
Defined in:
lib/redzone/machine.rb

Overview

Machine entry

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, config) ⇒ Machine

Construct a new machine entry

Parameters:

  • name (String)

    Relative domain name

  • config (Hash)

    Machine configuration

Options Hash (config):

  • :ipv4 (String)

    IPV4 Address

  • :ipv6 (String)

    IPV6 Address



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/redzone/machine.rb', line 15

def initialize(name,config) 
  @name  = name
  if config.is_a? Hash
    @alias = nil
    @ipv4  = IPAddr.new(config[:ipv4]) if config.has_key?(:ipv4)
    @ipv6  = IPAddr.new(config[:ipv6]) if config.has_key?(:ipv6)
  elsif config.is_a? Machine
    @alias = config
    @ipv4  = config.ipv4
    @ipv6  = config.ipv6
  end
end

Instance Attribute Details

#ipv4IPAddr

IPV4 Address

Returns:

  • (IPAddr)

    the current value of ipv4



8
9
10
# File 'lib/redzone/machine.rb', line 8

def ipv4
  @ipv4
end

#ipv6IPAddr

IPV6 Address

Returns:

  • (IPAddr)

    the current value of ipv6



8
9
10
# File 'lib/redzone/machine.rb', line 8

def ipv6
  @ipv6
end

#nameString

Relative domain name

Returns:

  • (String)

    the current value of name



8
9
10
# File 'lib/redzone/machine.rb', line 8

def name
  @name
end

Instance Method Details

#alias(name) ⇒ Machine

Returns a new machine that is an alias of this machine. If this machine is already an alias, it delegates this call to the aliased machine rather than this one.

Returns:



36
37
38
39
40
41
42
# File 'lib/redzone/machine.rb', line 36

def alias(name)
  if @alias.nil?
    Machine.new(name,self)
  else
    @alias.alias(name)
  end
end

#alias?Boolean

Returns true if this machine is an alias of another

Returns:

  • (Boolean)

    true if the machine is an alias



29
30
31
# File 'lib/redzone/machine.rb', line 29

def alias? 
  not @alias.nil?
end

#ipv4?Boolean

Test if the machine has an ipv4 address

Returns:

  • (Boolean)

    if the machine has an ipv4 address



45
46
47
# File 'lib/redzone/machine.rb', line 45

def ipv4?
  not @ipv4.nil?
end

#ipv6?Boolean

Test if the machine has an ipv6 address

Returns:

  • (Boolean)

    if the machine has an ipv6 address



50
51
52
# File 'lib/redzone/machine.rb', line 50

def ipv6?
  not @ipv6.nil?
end

#recordsArray<Record>

Get the list of A/AAAA records

Returns:



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/redzone/machine.rb', line 55

def records
  r = []
  comment = "Machine #{@alias.name}" if not @alias.nil?
  if ipv4?
    ipv4opt = {:name => @name, :data => @ipv4.to_s, :type => 'A', :comment => comment }
    r << Record.new(ipv4opt)
  end
  if ipv6?

    ipv6opt = {:name => @name, :data => @ipv6.to_s, :type => 'AAAA', :comment => comment }
    r << Record.new(ipv6opt)
  end
  r
end