Class: EC2Launcher::BlockDeviceBuilder
- Inherits:
-
Object
- Object
- EC2Launcher::BlockDeviceBuilder
- Defined in:
- lib/ec2launcher/block_device_builder.rb
Overview
Helper class to build EC2 block device definitions.
Instance Attribute Summary collapse
-
#block_device_mappings ⇒ Object
readonly
Returns the value of attribute block_device_mappings.
-
#block_device_tags ⇒ Object
readonly
Returns the value of attribute block_device_tags.
Instance Method Summary collapse
-
#generate_block_devices(instance_type, environment, application, clone_host = nil) ⇒ Hash<String, Hash] returns a mapping of device names to device details
Generates the mappings for ephemeral and ebs volumes.
-
#generate_device_tags(hostname, short_hostname, environment_name, block_devices) ⇒ Hash<String, Hash<String, String>] returns a mapping of device names to maps tag names and values.
Generates a mapping of block device names to tags.
-
#initialize(ec2, volume_size = nil) ⇒ BlockDeviceBuilder
constructor
A new instance of BlockDeviceBuilder.
Constructor Details
#initialize(ec2, volume_size = nil) ⇒ BlockDeviceBuilder
Returns a new instance of BlockDeviceBuilder.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ec2launcher/block_device_builder.rb', line 19 def initialize(ec2, volume_size = nil) @ec2 = ec2 @block_size = volume_size @volume_size ||= EC2Launcher::DEFAULT_VOLUME_SIZE @block_device_mappings = {} @block_device_tags = {} @log = Logger['ec2launcher'] end |
Instance Attribute Details
#block_device_mappings ⇒ Object (readonly)
Returns the value of attribute block_device_mappings.
13 14 15 |
# File 'lib/ec2launcher/block_device_builder.rb', line 13 def block_device_mappings @block_device_mappings end |
#block_device_tags ⇒ Object (readonly)
Returns the value of attribute block_device_tags.
14 15 16 |
# File 'lib/ec2launcher/block_device_builder.rb', line 14 def @block_device_tags end |
Instance Method Details
#generate_block_devices(instance_type, environment, application, clone_host = nil) ⇒ Hash<String, Hash] returns a mapping of device names to device details
Generates the mappings for ephemeral and ebs volumes.
39 40 41 42 43 44 45 46 47 |
# File 'lib/ec2launcher/block_device_builder.rb', line 39 def generate_block_devices(instance_type, environment, application, clone_host = nil) block_device_mappings = {} build_ephemeral_drives(block_device_mappings, instance_type) build_ebs_volumes(block_device_mappings, application.block_devices) clone_volumes(block_device_mappings, application, clone_host) block_device_mappings end |
#generate_device_tags(hostname, short_hostname, environment_name, block_devices) ⇒ Hash<String, Hash<String, String>] returns a mapping of device names to maps tag names and values.
Generates a mapping of block device names to tags.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/ec2launcher/block_device_builder.rb', line 57 def (hostname, short_hostname, environment_name, block_devices) = {} unless block_devices.nil? base_device_name = "sdf" block_devices.each do |block_device| build_block_devices(block_device.count, base_device_name) do |device_name, index| ["/dev/#{device_name}"] = { "purpose" => block_device.name, "host" => hostname, "environment" => environment_name } if block_device.raid_level.nil? ["/dev/#{device_name}"]["Name"] = "#{short_hostname} #{block_device.name}" else ["/dev/#{device_name}"]["Name"] = "#{short_hostname} #{block_device.name} raid (#{(index + 1).to_s})" ["/dev/#{device_name}"]["raid_number"] = (index + 1).to_s end end end end end |