Permalink
Browse files

Switching Volumes to use DslBuilder

  • Loading branch information...
1 parent 9f9c7b8 commit a62aa2f7a4d60989903898c22a81a41ae7bdaf55 @temujin9 temujin9 committed Jun 28, 2012
Showing with 52 additions and 63 deletions.
  1. +8 −10 lib/ironfan/cloud.rb
  2. +1 −1 lib/ironfan/dsl_builder.rb
  3. +43 −52 lib/ironfan/volume.rb
View
@@ -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
@@ -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
@@ -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
@@ -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'
@@ -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)
View
@@ -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
@@ -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
@@ -62,7 +60,6 @@ def desc
end
def defaults
- self.configure(VOLUME_DEFAULTS)
end
def ephemeral_device?
@@ -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
@@ -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.