Class: Furnish::Provisioner::AutoIP
- Inherits:
-
API
- Object
- API
- Furnish::Provisioner::AutoIP
- Defined in:
- lib/furnish/provisioners/auto_ip.rb
Overview
The AutoIP provisioner is used to create IP addresses for other systems that allow them as direct input, such as VirtualBox VMs. The expectation is that this will be chained to another provisioner who would accept it as input during startup.
Instance Method Summary collapse
-
#initialize(args) ⇒ AutoIP
constructor
Create the provisioner, requires :ip be passed and referring to a Furnish::IP object with subnet semantics (see Furnish::IP#new), and :number_of_addresses can also be supplied or will default to 1.
-
#ip ⇒ Object
:attr: ip.
-
#number_of_addresses ⇒ Object
:attr: number_of_addresses.
-
#report ⇒ Object
Display the allocated addresses for this group.
-
#shutdown(args = { }) ⇒ Object
Release the IP addresses back to the allocator.
-
#startup(args = {}) ⇒ Object
Allocate addresses and forward them on to the next provisioner.
Constructor Details
#initialize(args) ⇒ AutoIP
Create the provisioner, requires :ip be passed and referring to a Furnish::IP object with subnet semantics (see Furnish::IP#new), and :number_of_addresses can also be supplied or will default to 1.
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/furnish/provisioners/auto_ip.rb', line 44 def initialize(args) super unless ip raise ArgumentError, "A Furnish::IP object must be provided" end unless ip.subnet raise ArgumentError, "The Furnish::IP object must have a subnet associated" end @number_of_addresses ||= 1 end |
Instance Method Details
#ip ⇒ Object
:attr: ip
A Furnish::IP registry object. If a subnet is not assigned to this object (see Furnish::IP#new), ArgumentError will be raised when attempting to generate IP addresses.
21 |
# File 'lib/furnish/provisioners/auto_ip.rb', line 21 furnish_property :ip, "A Furnish::IP registry object", Furnish::IP |
#number_of_addresses ⇒ Object
:attr: number_of_addresses
An integer value specifying the number of addresses to allocate at provisioning time.
29 |
# File 'lib/furnish/provisioners/auto_ip.rb', line 29 furnish_property :number_of_addresses, "An integer indicating the number of addresses to generate", Integer |
#report ⇒ Object
Display the allocated addresses for this group.
92 93 94 |
# File 'lib/furnish/provisioners/auto_ip.rb', line 92 def report ip.group_items(furnish_group_name).to_a rescue [] end |
#shutdown(args = { }) ⇒ Object
Release the IP addresses back to the allocator. Only releases the IPs that were allocated by this specific provisioner. Destroys the group if it’s empty after releasing.
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/furnish/provisioners/auto_ip.rb', line 78 def shutdown(args={ }) if @controlled_ips ip.remove_from_group(furnish_group_name, @controlled_ips) end if ip.group_items(furnish_group_name).empty? ip.decommission_group(furnish_group_name) end return { } end |
#startup(args = {}) ⇒ Object
Allocate addresses and forward them on to the next provisioner. Uses the provisioner group name as the key for the address set. Fills key :ips with a Set of IP addresses.
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/furnish/provisioners/auto_ip.rb', line 62 def startup(args={}) @controlled_ips = Set.new number_of_addresses.times do this_ip = ip.unused_ip(furnish_group_name) @controlled_ips.add(this_ip) end return({ :ips => ip.group_items(furnish_group_name) }) end |