Class: RedZone::Machine
- Inherits:
-
Object
- Object
- RedZone::Machine
- Defined in:
- lib/redzone/machine.rb
Overview
Machine entry
Instance Attribute Summary collapse
-
#ipv4 ⇒ IPAddr
IPV4 Address.
-
#ipv6 ⇒ IPAddr
IPV6 Address.
-
#name ⇒ String
Relative domain name.
Instance Method Summary collapse
-
#alias(name) ⇒ Machine
Returns a new machine that is an alias of this machine.
-
#alias? ⇒ Boolean
Returns true if this machine is an alias of another.
-
#initialize(name, config) ⇒ Machine
constructor
Construct a new machine entry.
-
#ipv4? ⇒ Boolean
Test if the machine has an ipv4 address.
-
#ipv6? ⇒ Boolean
Test if the machine has an ipv6 address.
-
#records ⇒ Array<Record>
Get the list of A/AAAA records.
Constructor Details
#initialize(name, config) ⇒ Machine
Construct a new machine entry
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
#ipv4 ⇒ IPAddr
IPV4 Address
8 9 10 |
# File 'lib/redzone/machine.rb', line 8 def ipv4 @ipv4 end |
#ipv6 ⇒ IPAddr
IPV6 Address
8 9 10 |
# File 'lib/redzone/machine.rb', line 8 def ipv6 @ipv6 end |
#name ⇒ String
Relative domain 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.
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
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
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
50 51 52 |
# File 'lib/redzone/machine.rb', line 50 def ipv6? not @ipv6.nil? end |
#records ⇒ Array<Record>
Get the list of A/AAAA records
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 |