Class: ClusterChef::ComputeBuilder
- Defined in:
- lib/cluster_chef/compute.rb
Overview
Base class allowing us to layer settings for facet over cluster
Instance Attribute Summary collapse
-
#chef_roles ⇒ Object
readonly
Returns the value of attribute chef_roles.
-
#cloud(cloud_provider = nil, attrs = {}, &block) ⇒ Object
readonly
Magic method to produce cloud instance: * returns the cloud instance, creating it if necessary.
-
#volumes ⇒ Object
readonly
Returns the value of attribute volumes.
Class Method Summary collapse
-
.role_implication(name) { ... } ⇒ Object
Some roles imply aspects of the machine that have to exist at creation.
Instance Method Summary collapse
-
#bogus? ⇒ Boolean
set the bogosity to a descriptive reason.
-
#ec2(attrs = {}, &block) ⇒ Object
sugar for cloud(:ec2).
-
#initialize(builder_name, attrs = {}) ⇒ ComputeBuilder
constructor
A new instance of ComputeBuilder.
- #raid_group(rg_name, attrs = {}, &block) ⇒ Object
-
#recipe(name, placement = nil) ⇒ Object
Add the given recipe to the run list.
-
#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.).
- #root_volume(attrs = {}, &block) ⇒ Object
-
#run_list ⇒ Object
Roles and recipes for this element only.
-
#run_list_groups ⇒ Object
run list elements grouped into :first, :normal and :last.
-
#volume(volume_name, attrs = {}, &block) ⇒ Object
Magic method to describe a volume * returns the named volume, creating it if necessary.
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_roles ⇒ Object (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
39 40 41 |
# File 'lib/cluster_chef/compute.rb', line 39 def cloud @cloud end |
#volumes ⇒ Object (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.
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
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) ; ({}) } 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_list ⇒ Object
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_groups ⇒ Object
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
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 |