Class: ClusterChef::Volume
- Defined in:
- lib/cluster_chef/volume.rb
Overview
Internal or external storage
Direct Known Subclasses
Constant Summary collapse
- 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, }
Instance Attribute Summary collapse
-
#fog_volume ⇒ Object
Returns the value of attribute fog_volume.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Instance Method Summary collapse
-
#block_device_mapping ⇒ Object
An array of hashes with dorky-looking keys, just like Fog wants it.
-
#create_at_launch? ⇒ Boolean
With snapshot specified but volume missing, have it auto-created at launch.
- #defaults ⇒ Object
-
#desc ⇒ Object
human-readable description for logging messages and such.
- #ephemeral_device? ⇒ Boolean
- #has_server? ⇒ Boolean
- #in_cloud? ⇒ Boolean
-
#initialize(attrs = {}) ⇒ Volume
constructor
Describes a volume.
- #reverse_merge!(other_hsh) ⇒ Object
-
#snapshot_name(name) ⇒ Object
Named snapshots, as defined in ClusterChef::Volume::VOLUME_IDS.
Methods inherited from DslObject
#configure, #die, #dump, has_keys, #safely, #set, #step, #to_hash, #to_mash, #to_s, #ui, ui
Constructor Details
#initialize(attrs = {}) ⇒ Volume
Describes a volume
53 54 55 56 57 |
# File 'lib/cluster_chef/volume.rb', line 53 def initialize attrs={} @parent = attrs.delete(:parent) super(attrs) @settings[:tags] ||= {} end |
Instance Attribute Details
#fog_volume ⇒ Object
Returns the value of attribute fog_volume.
7 8 9 |
# File 'lib/cluster_chef/volume.rb', line 7 def fog_volume @fog_volume end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
6 7 8 |
# File 'lib/cluster_chef/volume.rb', line 6 def parent @parent end |
Instance Method Details
#block_device_mapping ⇒ Object
An array of hashes with dorky-looking keys, just like Fog wants it.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/cluster_chef/volume.rb', line 103 def block_device_mapping hsh = { 'DeviceName' => device } if ephemeral_device? hsh['VirtualName'] = volume_id elsif create_at_launch? raise "Must specify a size or a snapshot ID for #{self}" if snapshot_id.blank? && size.blank? hsh['Ebs.SnapshotId'] = snapshot_id if snapshot_id.present? hsh['Ebs.VolumeSize'] = size.to_s if size.present? hsh['Ebs.DeleteOnTermination'] = (! keep).to_s else return end hsh end |
#create_at_launch? ⇒ Boolean
With snapshot specified but volume missing, have it auto-created at launch
Be careful with this – you can end up with multiple volumes claiming to be the same thing.
84 85 86 |
# File 'lib/cluster_chef/volume.rb', line 84 def create_at_launch? volume_id.blank? && self.create_at_launch end |
#defaults ⇒ Object
64 65 66 |
# File 'lib/cluster_chef/volume.rb', line 64 def defaults self.configure(VOLUME_DEFAULTS) end |
#desc ⇒ Object
human-readable description for logging messages and such
60 61 62 |
# File 'lib/cluster_chef/volume.rb', line 60 def desc "#{name} on #{parent.fullname} (#{volume_id} @ #{device})" end |
#ephemeral_device? ⇒ Boolean
68 69 70 |
# File 'lib/cluster_chef/volume.rb', line 68 def ephemeral_device? volume_id =~ /^ephemeral/ end |
#has_server? ⇒ Boolean
92 93 94 |
# File 'lib/cluster_chef/volume.rb', line 92 def has_server? in_cloud? && fog_volume.server_id.present? end |
#in_cloud? ⇒ Boolean
88 89 90 |
# File 'lib/cluster_chef/volume.rb', line 88 def in_cloud? !! fog_volume end |
#reverse_merge!(other_hsh) ⇒ Object
96 97 98 99 100 |
# File 'lib/cluster_chef/volume.rb', line 96 def reverse_merge!(other_hsh) super(other_hsh) self..reverse_merge!(other_hsh.) if other_hsh.respond_to?(:tags) && other_hsh..present? self end |
#snapshot_name(name) ⇒ Object
Named snapshots, as defined in ClusterChef::Volume::VOLUME_IDS
73 74 75 76 77 |
# File 'lib/cluster_chef/volume.rb', line 73 def snapshot_name(name) snap_id = VOLUME_IDS[name.to_sym] raise "Unknown snapshot name #{name} - is it defined in ClusterChef::Volume::VOLUME_IDS?" unless snap_id self.snapshot_id(snap_id) end |