Class: ClusterChef::Cloud::Ec2

Inherits:
Base show all
Defined in:
lib/cluster_chef/cloud.rb,
lib/cluster_chef/deprecated.rb

Constant Summary collapse

FLAVOR_INFO =

code $/hr $/mo $/day CPU/$ Mem/$ mem cpu cores cpcore storage bits IO type name t1.micro $0.02 14 0.48 10.00 33.50 0.67 0.2 1 0.2 0 64 Low Micro Micro m1.small $0.085 61 2.04 11.76 20.00 1.7 1 1 1 160 32 Moderate Standard Small c1.medium $0.17 123 4.08 29.41 10.00 1.7 5 2 2.5 350 32 Moderate High-CPU Medium m1.large $0.34 246 8.16 11.76 22.06 7.5 4 2 2 850 64 High Standard Large m2.xlarge $0.50 363 12.00 13.00 35.40 17.7 6.5 2 3.25 420 64 Moderate High-Memory Extra Large c1.xlarge $0.68 493 16.32 29.41 10.29 7 20 8 2.5 1690 64 High High-CPU Extra Large m1.xlarge $0.68 493 16.32 11.76 22.06 15 8 4 2 1690 64 High Standard Extra Large m2.2xlarge $1.00 726 24.00 13.00 34.20 34.2 13 4 3.25 850 64 High High-Memory Double Extra Large m2.4xlarge $2.00 1452 48.00 13.00 34.20 68.4 26 8 3.25 1690 64 High High-Memory Quadruple Extra Large cc1.4xlarge $1.60 1161 38.40 20.94 14.38 23 33.5 2 16.75 1690 64 Very High 10GB Compute Quadruple Extra Large cg1.4xlarge $2.10 1524 50.40 15.95 10.48 22 33.5 2 16.75 1690 64 Very High 10GB Cluster GPU Quadruple Extra Large

{
  't1.micro'    => { :price => 0.02,  :bits => '64-bit', :ram =>    686, :cores => 1, :core_size => 0.25, :inst_disks => 0, :inst_disk_size =>    0, :ephemeral_volumes => 0 },
  'm1.small'    => { :price => 0.085, :bits => '32-bit', :ram =>   1740, :cores => 1, :core_size => 1,    :inst_disks => 1, :inst_disk_size =>  160, :ephemeral_volumes => 1 },
  'c1.medium'   => { :price => 0.17,  :bits => '32-bit', :ram =>   1740, :cores => 2, :core_size => 2.5,  :inst_disks => 1, :inst_disk_size =>  350, :ephemeral_volumes => 1 },
  'm1.large'    => { :price => 0.34,  :bits => '64-bit', :ram =>   7680, :cores => 2, :core_size => 2,    :inst_disks => 2, :inst_disk_size =>  850, :ephemeral_volumes => 2 },
  'm2.xlarge'   => { :price => 0.50,  :bits => '64-bit', :ram =>  18124, :cores => 2, :core_size => 3.25, :inst_disks => 1, :inst_disk_size =>  420, :ephemeral_volumes => 1 },
  'c1.xlarge'   => { :price => 0.68,  :bits => '64-bit', :ram =>   7168, :cores => 8, :core_size => 2.5,  :inst_disks => 4, :inst_disk_size => 1690, :ephemeral_volumes => 4 },
  'm1.xlarge'   => { :price => 0.68,  :bits => '64-bit', :ram =>  15360, :cores => 4, :core_size => 2,    :inst_disks => 4, :inst_disk_size => 1690, :ephemeral_volumes => 4 },
  'm2.2xlarge'  => { :price => 1.00,  :bits => '64-bit', :ram =>  35020, :cores => 4, :core_size => 3.25, :inst_disks => 2, :inst_disk_size =>  850, :ephemeral_volumes => 2 },
  'm2.4xlarge'  => { :price => 2.00,  :bits => '64-bit', :ram =>  70041, :cores => 8, :core_size => 3.25, :inst_disks => 4, :inst_disk_size => 1690, :ephemeral_volumes => 4 },
  'cc1.4xlarge' => { :price => 1.60,  :bits => '64-bit', :ram =>  23552, :cores => 2, :core_size =>16.75, :inst_disks => 4, :inst_disk_size => 1690, :ephemeral_volumes => 2 },
  'cg1.4xlarge' => { :price => 2.10,  :bits => '64-bit', :ram =>  22528, :cores => 2, :core_size =>16.75, :inst_disks => 4, :inst_disk_size => 1690, :ephemeral_volumes => 2 },
}

Instance Attribute Summary

Attributes inherited from Base

#owner

Instance Method Summary collapse

Methods inherited from Base

#bits, #bootstrap_distro, #image_id, #price, #ssh_identity_dir, #ssh_identity_file, #ssh_user, #validation_key

Methods inherited from DslObject

#configure, #die, #dump, has_keys, #safely, #set, #step, #to_hash, #to_mash, #to_s, #ui, ui

Constructor Details

#initialize(*args) ⇒ Ec2

Returns a new instance of Ec2.



129
130
131
132
133
# File 'lib/cluster_chef/cloud.rb', line 129

def initialize(*args)
  super *args
  @settings[:security_groups]      ||= Mash.new
  @settings[:user_data]            ||= Mash.new
end

Instance Method Details

#default_availability_zoneObject



194
195
196
# File 'lib/cluster_chef/cloud.rb', line 194

def default_availability_zone
  availability_zones.first if availability_zones
end

#defaultsObject

Sets some defaults for amazon cloud usage, and registers the root volume



138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/cluster_chef/cloud.rb', line 138

def defaults
  owner.volume(:root).reverse_merge!({
      :device      => '/dev/sda1',
      :mount_point => '/',
      :mountable   => false,
    })
  self.reverse_merge!({
      :availability_zones => ['us-east-1d'],
      :backing            => 'ebs',
      :flavor             => 't1.micro',
    })
  super
end

#elastic_ip(*args, &block) ⇒ Object

DEPRECATED: Please use public_ip instead.



28
29
30
# File 'lib/cluster_chef/deprecated.rb', line 28

def elastic_ip(*args, &block)
  public_ip(*args, &block)
end

#flavor(val = nil) ⇒ Object



219
220
221
222
223
224
225
# File 'lib/cluster_chef/cloud.rb', line 219

def flavor(val=nil)
  if val && (not FLAVOR_INFO.has_key?(val.to_s))
    ui.warn("Unknown machine image flavor '#{val}'")
    list_flavors
  end
  set :flavor, val
end

#flavor_infoObject



227
228
229
# File 'lib/cluster_chef/cloud.rb', line 227

def flavor_info
  FLAVOR_INFO[flavor] or ( ui.warn "Please define the machine's flavor: have #{self.inspect}" ; {} )
end

#image_infoObject

Utility methods



208
209
210
# File 'lib/cluster_chef/cloud.rb', line 208

def image_info
  Chef::Config[: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].inspect})" ; {} )
end

#list_flavorsObject



231
232
233
234
235
236
# File 'lib/cluster_chef/cloud.rb', line 231

def list_flavors
  ui.info("Available flavors:")
  FLAVOR_INFO.each do |flavor_name, flavor|
    ui.info("  #{flavor_name}\t#{flavor.inspect}")
  end
end

#list_imagesObject



212
213
214
215
216
217
# File 'lib/cluster_chef/cloud.rb', line 212

def list_images
  ui.info("Available images:")
  Chef::Config[:ec2_image_info].each do |flavor_name, flavor|
    ui.info("  #{flavor_name}\t#{flavor.inspect}")
  end
end

#mount_ephemerals(attrs = {}) ⇒ Object

Bring the ephemeral storage (local scratch disks) online



199
200
201
202
203
204
# File 'lib/cluster_chef/cloud.rb', line 199

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

#region(val = nil) ⇒ Object



186
187
188
189
190
191
192
# File 'lib/cluster_chef/cloud.rb', line 186

def region(val=nil)
  set(:region, val)
  if    @settings[:region]        then @settings[:region]
  elsif default_availability_zone then default_availability_zone.gsub(/^(\w+-\w+-\d)[a-z]/, '\1')
  else  nil
  end
end

#reverse_merge!(hsh) ⇒ Object



179
180
181
182
183
184
# File 'lib/cluster_chef/cloud.rb', line 179

def reverse_merge!(hsh)
  super(hsh.to_mash.compact)
  @settings[:security_groups].reverse_merge!(hsh.security_groups) if hsh.respond_to?(:security_groups)
  @settings[:user_data      ].reverse_merge!(hsh.user_data)       if hsh.respond_to?(:user_data)
  self
end

#security_group(sg_name, hsh = {}, &block) ⇒ Object

adds a security group to the cloud instance



153
154
155
156
157
158
# File 'lib/cluster_chef/cloud.rb', line 153

def security_group(sg_name, hsh={}, &block)
  sg_name = sg_name.to_s
  security_groups[sg_name] ||= ClusterChef::Cloud::SecurityGroup.new(self, sg_name)
  security_groups[sg_name].configure(hsh, &block)
  security_groups[sg_name]
end

#spot_price_fraction(val = nil) ⇒ Object

With a value, sets the spot price to the given fraction of the

instance's full price (as found in ClusterChef::Cloud::Aws::FLAVOR_INFO)

With no value, returns the spot price as a fraction of the full instance price.



163
164
165
166
167
168
169
# File 'lib/cluster_chef/cloud.rb', line 163

def spot_price_fraction(val=nil)
  if val
    spot_price( price.to_f * val )
  else
    spot_price / price rescue 0
  end
end

#user_data(hsh = {}) ⇒ Object

EC2 User data – DNA typically used to bootstrap the machine.

Parameters:

  • value (Hash)

    – when present, merged with the existing user data (overriding it)

Returns:

  • the user_data hash



174
175
176
177
# File 'lib/cluster_chef/cloud.rb', line 174

def user_data(hsh={})
  @settings[:user_data].merge!(hsh.to_hash) unless hsh.empty?
  @settings[:user_data]
end