Skip to content

Commit

Permalink
Switching Volumes to use DslBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
temujin9 committed Jun 28, 2012
1 parent 9f9c7b8 commit a62aa2f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 63 deletions.
18 changes: 8 additions & 10 deletions lib/ironfan/cloud.rb
Expand Up @@ -189,7 +189,6 @@ class Ec2 < Base
magic :flavor, String, :default => 't1.micro'
magic :image_name, String, :default => 'natty'
magic :keypair, Whatever
magic :mount_ephemerals, String
magic :monitoring, String
magic :permanent, String
magic :public_ip, String
Expand All @@ -216,6 +215,14 @@ def default_availability_zone
availability_zones.first if availability_zones
end

# Bring the ephemeral storage (local scratch disks) online
def mount_ephemerals(attrs={})
owner.volume(:ephemeral0, attrs){ device '/dev/sdb'; volume_id 'ephemeral0' ; mount_point '/mnt' ; tags( :bulk => true, :local => true, :fallback => true) } if flavor_info[:ephemeral_volumes] > 0
owner.volume(:ephemeral1, attrs){ device '/dev/sdc'; volume_id 'ephemeral1' ; mount_point '/mnt2'; tags( :bulk => true, :local => true, :fallback => true) } if flavor_info[:ephemeral_volumes] > 1
owner.volume(:ephemeral2, attrs){ device '/dev/sdd'; volume_id 'ephemeral2' ; mount_point '/mnt3'; tags( :bulk => true, :local => true, :fallback => true) } if flavor_info[:ephemeral_volumes] > 2
owner.volume(:ephemeral3, attrs){ device '/dev/sde'; volume_id 'ephemeral3' ; mount_point '/mnt4'; tags( :bulk => true, :local => true, :fallback => true) } if flavor_info[:ephemeral_volumes] > 3
end

def image_info
ec2_image_info[ [region, bits, backing, image_name] ] or ( ui.warn "Make sure to define the machine's region, bits, backing and image_name. (Have #{[region, bits, backing, image_name, virtualization].inspect})" ; {} )
end
Expand Down Expand Up @@ -303,7 +310,6 @@ class VirtualBox < Base
# magic :default_availability_zone, String
# magic :flavor_info, Array, :default => { :placement_groupable => false }
# magic :keypair, Ironfan::PrivateKey
# magic :mount_ephemerals, String
# magic :monitoring, String
# magic :permanent, String
# magic :public_ip, String
Expand Down Expand Up @@ -448,14 +454,6 @@ def initialize(*args)
# @settings[:placement_group] || owner.cluster_name
# end
#
# # Bring the ephemeral storage (local scratch disks) online
# def mount_ephemerals(attrs={})
# owner.volume(:ephemeral0, attrs){ device '/dev/sdb'; volume_id 'ephemeral0' ; mount_point '/mnt' ; tags( :bulk => true, :local => true, :fallback => true) } if flavor_info[:ephemeral_volumes] > 0
# owner.volume(:ephemeral1, attrs){ device '/dev/sdc'; volume_id 'ephemeral1' ; mount_point '/mnt2'; tags( :bulk => true, :local => true, :fallback => true) } if flavor_info[:ephemeral_volumes] > 1
# owner.volume(:ephemeral2, attrs){ device '/dev/sdd'; volume_id 'ephemeral2' ; mount_point '/mnt3'; tags( :bulk => true, :local => true, :fallback => true) } if flavor_info[:ephemeral_volumes] > 2
# owner.volume(:ephemeral3, attrs){ device '/dev/sde'; volume_id 'ephemeral3' ; mount_point '/mnt4'; tags( :bulk => true, :local => true, :fallback => true) } if flavor_info[:ephemeral_volumes] > 3
# end
#
# # Utility methods
#
# require 'pry'
Expand Down
2 changes: 1 addition & 1 deletion lib/ironfan/dsl_builder.rb
Expand Up @@ -37,7 +37,7 @@ def read_set_attribute(field_name)

def read_underlay_attribute(field_name)
return if field_name == :underlay
underlay.read_attribute(field_name) if instance_variable_defined?("@underlay")
underlay.read_attribute(field_name) unless @underlay.nil?
end

def read_unset_attribute(field_name)
Expand Down
95 changes: 43 additions & 52 deletions lib/ironfan/volume.rb
Expand Up @@ -2,32 +2,31 @@ module Ironfan
#
# Internal or external storage
#
class Volume < Ironfan::DslObject
class Volume < Ironfan::DslBuilder
attr_reader :parent
attr_accessor :fog_volume
has_keys(
:name,
# mountable volume attributes
:device, :mount_point, :mount_options, :fstype, :mount_dump, :mount_pass,
:mountable, :formattable, :resizable, :in_raid,
# cloud volume attributes
:attachable, :create_at_launch, :volume_id, :snapshot_id, :size, :keep, :availability_zone,
# arbitrary tags
:tags
)

VOLUME_DEFAULTS = {
:fstype => 'xfs',
:mount_options => 'defaults,nouuid,noatime',
:keep => true,
:attachable => :ebs,
:create_at_launch => false,
#
:mountable => true,
:resizable => false,
:formattable => false,
:in_raid => false,
}
magic :name, String
# mountable volume attributes
magic :device, String
magic :mount_point, String
magic :mount_options, String, :default => 'defaults,nouuid,noatime'
magic :fstype, String, :default => 'xfs'
magic :mount_dump, String
magic :mount_pass, String
magic :mountable, Whatever, :default => true
magic :formattable, Whatever, :default => false
magic :resizable, Whatever, :default => false
magic :in_raid, Whatever, :default => false
# cloud volume attributes
magic :attachable, Whatever, :default => :ebs
magic :create_at_launch, Whatever, :default => false
magic :volume_id, String
magic :snapshot_id, String
magic :size, String
magic :keep, Whatever, :default => true
magic :availability_zone, String
# arbitrary tags
magic :tags, Hash, :default => {}

# Snapshot for snapshot_name method.
# Set your own by adding
Expand All @@ -53,7 +52,6 @@ class Volume < Ironfan::DslObject
def initialize attrs={}
@parent = attrs.delete(:parent)
super(attrs)
@settings[:tags] ||= {}
end

# human-readable description for logging messages and such
Expand All @@ -62,7 +60,6 @@ def desc
end

def defaults
self.configure(VOLUME_DEFAULTS)
end

def ephemeral_device?
Expand Down Expand Up @@ -93,11 +90,11 @@ def has_server?
in_cloud? && fog_volume.server_id.present?
end

def reverse_merge!(other_hsh)
super(other_hsh)
self.tags.reverse_merge!(other_hsh.tags) if other_hsh.respond_to?(:tags) && other_hsh.tags.present?
self
end
# def reverse_merge!(other_hsh)
# super(other_hsh)
# self.tags.reverse_merge!(other_hsh.tags) if other_hsh.respond_to?(:tags) && other_hsh.tags.present?
# self
# end

# An array of hashes with dorky-looking keys, just like Fog wants it.
def block_device_mapping
Expand Down Expand Up @@ -127,31 +124,25 @@ def block_device_mapping
# * http://stu.mp/2009/12/disk-io-and-throughput-benchmarks-on-amazons-ec2.html
#
class RaidGroup < Volume
has_keys(
:sub_volumes, # volumes that comprise this raid group
:level, # RAID level (http://en.wikipedia.org/wiki/RAID#Standard_levels)
:chunk, # Raid chunk size (https://raid.wiki.kernel.org/articles/r/a/i/RAID_setup_cbb2.html)
:read_ahead, # read-ahead buffer
)
# volumes that comprise this raid group
magic :sub_volumes, Array, :default => []
# RAID level (http://en.wikipedia.org/wiki/RAID#Standard_levels)
magic :level, String
# Raid chunk size (https://raid.wiki.kernel.org/articles/r/a/i/RAID_setup_cbb2.html)
magic :chunk, String
# read-ahead buffer
magic :read_ahead, String

# Overrides of Volume field defaults
magic :attachable, Whatever, :default => false
magic :formattable, Whatever, :default => true
magic :mount_options, String, :default => 'defaults,nobootwait,noatime,nouuid,comment=ironfan'

def desc
"#{name} on #{parent.fullname} (#{volume_id} @ #{device} from #{sub_volumes.join(',')})"
end

def defaults()
super
fstype 'xfs'
mount_options "defaults,nobootwait,noatime,nouuid,comment=ironfan"
attachable false
create_at_launch false
#
mountable true
resizable false
formattable true
#
in_raid false
#
sub_volumes []
end
attr_reader :parent
attr_accessor :fog_volume
end
end

0 comments on commit a62aa2f

Please sign in to comment.