Class: ClusterChef::Volume

Inherits:
DslObject show all
Defined in:
lib/cluster_chef/volume.rb

Overview

Internal or external storage

Direct Known Subclasses

RaidGroup

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

Instance Method Summary collapse

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

Examples:

ClusterChef::Volume.new( :name => 'redis',
  :device => '/dev/sdp', :mount_point => '/data/redis', :fstype => 'xfs', :mount_options => 'defaults,nouuid,noatime'
  :size => 1024, :snapshot_id => 'snap-66494a08', :volume_id => 'vol-12312',
  :tags => {}, :keep => true )


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_volumeObject

Returns the value of attribute fog_volume.



7
8
9
# File 'lib/cluster_chef/volume.rb', line 7

def fog_volume
  @fog_volume
end

#parentObject (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_mappingObject

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.

Returns:

  • (Boolean)


84
85
86
# File 'lib/cluster_chef/volume.rb', line 84

def create_at_launch?
  volume_id.blank? && self.create_at_launch
end

#defaultsObject



64
65
66
# File 'lib/cluster_chef/volume.rb', line 64

def defaults
  self.configure(VOLUME_DEFAULTS)
end

#descObject

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

Returns:

  • (Boolean)


68
69
70
# File 'lib/cluster_chef/volume.rb', line 68

def ephemeral_device?
  volume_id =~ /^ephemeral/
end

#has_server?Boolean

Returns:

  • (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

Returns:

  • (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.tags.reverse_merge!(other_hsh.tags) if other_hsh.respond_to?(:tags) && other_hsh.tags.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