Class: ClusterChef::ComputeBuilder

Inherits:
DslObject
  • Object
show all
Defined in:
lib/cluster_chef/compute.rb

Overview

Base class allowing us to layer settings for facet over cluster

Direct Known Subclasses

Cluster, Facet, Server

Instance Attribute Summary collapse

Class Method 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(builder_name, attrs = {}) ⇒ ComputeBuilder

Returns a new instance of ComputeBuilder.



11
12
13
14
15
16
# File 'lib/cluster_chef/compute.rb', line 11

def initialize(builder_name, attrs={})
  super(attrs)
  set :name, builder_name
  @run_list_info = attrs[:run_list] || Mash.new
  @volumes = Mash.new
end

Instance Attribute Details

#chef_rolesObject (readonly)

Returns the value of attribute chef_roles.



6
7
8
# File 'lib/cluster_chef/compute.rb', line 6

def chef_roles
  @chef_roles
end

#cloud(cloud_provider = nil, attrs = {}, &block) ⇒ Object (readonly)

Magic method to produce cloud instance:

  • returns the cloud instance, creating it if necessary.

  • executes the block in the cloud’s object context

Examples:

cloud do
  image_name     'maverick'
  security_group :nagios
end

# defines ec2-specific behavior
cloud(:ec2) do
  public_ip      '1.2.3.4'
  region         'us-east-1d'
end


39
40
41
# File 'lib/cluster_chef/compute.rb', line 39

def cloud
  @cloud
end

#volumesObject (readonly)

Returns the value of attribute volumes.



6
7
8
# File 'lib/cluster_chef/compute.rb', line 6

def volumes
  @volumes
end

Class Method Details

.role_implication(name) { ... } ⇒ Object

Some roles imply aspects of the machine that have to exist at creation. For instance, on an ec2 machine you may wish the ‘ssh’ role to imply a security group explicity opening port 22.

Parameters:

  • role_name (String)

    – the role that triggers the block

Yields:

  • block will be instance_eval’d in the object that calls ‘role’



139
140
141
# File 'lib/cluster_chef/compute.rb', line 139

def self.role_implication(name, &block)
  @@role_implications[name] = block
end

Instance Method Details

#bogus?Boolean

set the bogosity to a descriptive reason. Anything truthy implies bogusness

Returns:

  • (Boolean)


19
20
21
# File 'lib/cluster_chef/compute.rb', line 19

def bogus?
  !! self.bogosity
end

#ec2(attrs = {}, &block) ⇒ Object

sugar for cloud(:ec2)



47
48
49
# File 'lib/cluster_chef/compute.rb', line 47

def ec2(attrs={}, &block)
  cloud(:ec2, attrs, &block)
end

#raid_group(rg_name, attrs = {}, &block) ⇒ Object



73
74
75
76
77
78
79
80
# File 'lib/cluster_chef/compute.rb', line 73

def raid_group(rg_name, attrs={}, &block)
  volumes[rg_name] ||= ClusterChef::RaidGroup.new(:parent => self, :name => rg_name)
  volumes[rg_name].configure(attrs, &block)
  volumes[rg_name].sub_volumes.each do |sv_name|
    volume(sv_name){ in_raid(rg_name) ; mountable(false) ; tags({}) }
  end
  volumes[rg_name]
end

#recipe(name, placement = nil) ⇒ Object

Add the given recipe to the run list. You can specify placement of ‘:first`, `:normal` (or nil) or `:last`; the final runlist is assembled as

  • run_list :first items – cluster, then facet, then server

  • run_list :normal items – cluster, then facet, then server

  • run_list :last items – cluster, then facet, then server

(see ClusterChef::Server#combined_run_list for full details though)



114
115
116
# File 'lib/cluster_chef/compute.rb', line 114

def recipe(name, placement=nil)
  add_to_run_list(name, placement)
end

#role(role_name, placement = nil) ⇒ Object

Adds the given role to the run list, and invokes any role_implications it implies (for instance, defining and applying the ‘ssh’ security group if the ‘ssh’ role is applied.)

You can specify placement of ‘:first`, `:normal` (or nil) or `:last`; the final runlist is assembled as

  • run_list :first items – cluster, then facet, then server

  • run_list :normal items – cluster, then facet, then server

  • run_list :last items – cluster, then facet, then server

(see ClusterChef::Server#combined_run_list for full details though)



100
101
102
103
# File 'lib/cluster_chef/compute.rb', line 100

def role(role_name, placement=nil)
  add_to_run_list("role[#{role_name}]", placement)
  self.instance_eval(&@@role_implications[role_name]) if @@role_implications[role_name]
end

#root_volume(attrs = {}, &block) ⇒ Object



82
83
84
# File 'lib/cluster_chef/compute.rb', line 82

def root_volume(attrs={}, &block)
  volume(:root, attrs, &block)
end

#run_listObject

Roles and recipes for this element only.

See ClusterChef::Server#combined_run_list for run_list order resolution



121
122
123
124
# File 'lib/cluster_chef/compute.rb', line 121

def run_list
  groups = run_list_groups
  [ groups[:first], groups[:normal], groups[:last] ].flatten.compact.uniq
end

#run_list_groupsObject

run list elements grouped into :first, :normal and :last



127
128
129
# File 'lib/cluster_chef/compute.rb', line 127

def run_list_groups
  @run_list_info.keys.sort_by{|item| @run_list_info[item][:rank] }.group_by{|item| @run_list_info[item][:placement] }
end

#volume(volume_name, attrs = {}, &block) ⇒ Object

Magic method to describe a volume

  • returns the named volume, creating it if necessary.

  • executes the block (if any) in the volume’s context

Examples:

# a 1 GB volume at '/data' from the given snapshot
volume(:data) do
  size        1
  mount_point '/data'
  snapshot_id 'snap-12345'
end

Parameters:

  • volume_name (String)

    an arbitrary handle – you can use the device name, or a descriptive symbol.

  • attrs (Hash) (defaults to: {})

    a hash of attributes to pass down.



67
68
69
70
71
# File 'lib/cluster_chef/compute.rb', line 67

def volume(volume_name, attrs={}, &block)
  volumes[volume_name] ||= ClusterChef::Volume.new(:parent => self, :name => volume_name)
  volumes[volume_name].configure(attrs, &block)
  volumes[volume_name]
end