Class: ClusterChef::Cloud::Base

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

Overview

Right now only one cloud provider is implemented, so the separation between ‘cloud` and `cloud(:ec2)` is muddy.

The goal though is to allow

  • cloud with no predicate – definitions that apply to all cloud providers. If you only use one provider ever nothing stops you from always saying ‘cloud`.

  • Declarations irrelevant to other providers are acceptable and will be ignored

  • Declarations that are wrong in the context of other providers (a ‘public_ip` that is not available) will presumably cause a downstream error – it’s your responsibility to overlay with provider-correct values.

  • There are several declarations that could be sensibly abstracted, but are not. Rather than specifying ‘flavor ’m1.xlarge’‘, I could ask for :ram => 15, :cores => 4 or storage => 1500 and get the cheapest machine that met or exceeded each constraint – the default of `:price => :smallest` would get me a t1.micro on EC2, a 256MB on Rackspace. Availability zones could also plausibly be parameterized.

Examples:

# these apply regardless of cloud provider
cloud do
  # this makes sense everywhere
  image_name            'maverick'

  # this is not offered by many providers, and its value is non-portable;
  # but if you only run in one cloud there's harm in putting it here
  # or overriding it.
  public_ip             '1.2.3.4'

  # Implemented differently across providers but its meaning is clear
  security_group        :nagios

  # This is harmless for the other clouds
  availability_zones   ['us-east-1d']
end

# these only apply to ec2 launches.
# `ec2` is sugar for `cloud(:ec2)`.
ec2 do
  spot_price_fraction   0.4
end

Direct Known Subclasses

Ec2, Rackspace, Slicehost, Terremark

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from DslObject

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

Constructor Details

#initialize(owner, *args) ⇒ Base

Returns a new instance of Base.



54
55
56
57
# File 'lib/cluster_chef/cloud.rb', line 54

def initialize(owner, *args)
  self.owner = owner
  super(*args)
end

Instance Attribute Details

#ownerObject

Returns the value of attribute owner.



52
53
54
# File 'lib/cluster_chef/cloud.rb', line 52

def owner
  @owner
end

Instance Method Details

#bitsObject

The instance bitness, drawn from the compute flavor’s info



107
108
109
# File 'lib/cluster_chef/cloud.rb', line 107

def bits
  flavor_info[:bits]
end

#bootstrap_distro(val = nil) ⇒ Object

Distribution knife should target when bootstrapping an instance

Returns:

  • the bootstrap_distro if set explicitly; otherwise, the bootstrap_distro implied by the image name



93
94
95
# File 'lib/cluster_chef/cloud.rb', line 93

def bootstrap_distro(val=nil)
  from_setting_or_image_info :bootstrap_distro, val, "ubuntu10.04-gems"
end

#defaultsObject

default values to apply where no value was set



61
62
63
64
65
# File 'lib/cluster_chef/cloud.rb', line 61

def defaults
  reverse_merge!({
    :image_name         => 'natty',
  })
end

#image_id(val = nil) ⇒ Object

ID of the machine image to use.

Returns:

  • the image_id if set explicitly; otherwise, the id implied by the image name



87
88
89
# File 'lib/cluster_chef/cloud.rb', line 87

def image_id(val=nil)
  from_setting_or_image_info :image_id, val
end

#priceObject

The instance price, drawn from the compute flavor’s info



102
103
104
# File 'lib/cluster_chef/cloud.rb', line 102

def price
  flavor_info[:price]
end

#ssh_identity_dir(val = nil) ⇒ Object

Location of ssh private keys



74
75
76
77
# File 'lib/cluster_chef/cloud.rb', line 74

def ssh_identity_dir(val=nil)
  set :ssh_identity_dir, File.expand_path(val) unless val.nil?
  @settings.include?(:ssh_identity_dir) ? @settings[:ssh_identity_dir] : Chef::Config.ec2_key_dir
end

#ssh_identity_file(val = nil) ⇒ Object

SSH identity file used for knife ssh, knife boostrap and such



80
81
82
83
# File 'lib/cluster_chef/cloud.rb', line 80

def ssh_identity_file(val=nil)
  set :ssh_identity_file, File.expand_path(val) unless val.nil?
  @settings.include?(:ssh_identity_file) ? @settings[:ssh_identity_file] : File.join(ssh_identity_dir, "#{keypair}.pem")
end

#ssh_user(val = nil) ⇒ Object

The username to ssh with.

Returns:

  • the ssh_user if set explicitly; otherwise, the user implied by the image name, if any; or else ‘root’



69
70
71
# File 'lib/cluster_chef/cloud.rb', line 69

def ssh_user(val=nil)
  from_setting_or_image_info :ssh_user, val, 'root'
end

#validation_keyObject



97
98
99
# File 'lib/cluster_chef/cloud.rb', line 97

def validation_key
  IO.read(Chef::Config.validation_key) rescue ''
end