Class: ClusterChef::Facet
- Inherits:
-
ComputeBuilder
- Object
- DslObject
- ComputeBuilder
- ClusterChef::Facet
- Defined in:
- lib/cluster_chef/facet.rb
Instance Attribute Summary collapse
-
#cluster ⇒ Object
readonly
Returns the value of attribute cluster.
Attributes inherited from ComputeBuilder
Instance Method Summary collapse
- #assign_volume_ids(volume_name, *volume_ids) ⇒ Object
- #cluster_name ⇒ Object
- #facet_name ⇒ Object
-
#facet_role(&block) ⇒ Chef::Role
The auto-generated role for this facet.
-
#has_server?(idx) ⇒ Boolean
if the server has been added to this facet or is in range.
-
#indexes ⇒ Object
indexes in the 0…instances range plus bogus ones that showed up (probably from chef or fog).
-
#initialize(cluster, facet_name, attrs = {}) ⇒ Facet
constructor
A new instance of Facet.
-
#resolve! ⇒ Object
Resolve:.
-
#server(idx, attrs = {}) { ... } ⇒ ClusterChef::Facet
Retrieve or define the given server.
-
#servers ⇒ ClusterChef::ServerSlice
All servers in this facet.
-
#slice(slice_indexes = nil) ⇒ ClusterChef::ServerSlice
A slice of servers from this facet, in index order.
-
#valid_indexes ⇒ Object
all valid server indexes.
Methods inherited from ComputeBuilder
#bogus?, #ec2, #raid_group, #recipe, #role, role_implication, #root_volume, #run_list, #run_list_groups, #volume
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(cluster, facet_name, attrs = {}) ⇒ Facet
Returns a new instance of Facet.
6 7 8 9 10 11 12 13 14 |
# File 'lib/cluster_chef/facet.rb', line 6 def initialize cluster, facet_name, attrs={} super(facet_name.to_sym, attrs) @cluster = cluster @servers = Mash.new @chef_roles = [] @settings[:instances] ||= 1 create_facet_role create_facet_security_group unless attrs[:no_security_group] end |
Instance Attribute Details
#cluster ⇒ Object (readonly)
Returns the value of attribute cluster.
3 4 5 |
# File 'lib/cluster_chef/facet.rb', line 3 def cluster @cluster end |
Instance Method Details
#assign_volume_ids(volume_name, *volume_ids) ⇒ Object
40 41 42 43 44 |
# File 'lib/cluster_chef/facet.rb', line 40 def assign_volume_ids(volume_name, *volume_ids) volume_ids.flatten.zip(servers).each do |volume_id, server| server.volume(volume_name){ volume_id(volume_id) } if server end end |
#cluster_name ⇒ Object
16 17 18 |
# File 'lib/cluster_chef/facet.rb', line 16 def cluster_name cluster.name end |
#facet_name ⇒ Object
20 21 22 |
# File 'lib/cluster_chef/facet.rb', line 20 def facet_name name end |
#facet_role(&block) ⇒ Chef::Role
The auto-generated role for this facet. Instance-evals the given block in the context of that role,
35 36 37 38 |
# File 'lib/cluster_chef/facet.rb', line 35 def facet_role(&block) @facet_role.instance_eval( &block ) if block_given? @facet_role end |
#has_server?(idx) ⇒ Boolean
if the server has been added to this facet or is in range
63 64 65 |
# File 'lib/cluster_chef/facet.rb', line 63 def has_server? idx (idx.to_i < instances) || @servers.include?(idx.to_i) end |
#indexes ⇒ Object
indexes in the 0…instances range plus bogus ones that showed up (probably from chef or fog)
101 102 103 |
# File 'lib/cluster_chef/facet.rb', line 101 def indexes [@servers.keys, valid_indexes].flatten.compact.uniq.sort end |
#resolve! ⇒ Object
Resolve:
108 109 110 |
# File 'lib/cluster_chef/facet.rb', line 108 def resolve! servers.each(&:resolve!) end |
#server(idx, attrs = {}) { ... } ⇒ ClusterChef::Facet
Retrieve or define the given server
55 56 57 58 59 60 |
# File 'lib/cluster_chef/facet.rb', line 55 def server(idx, attrs={}, &block) idx = idx.to_i @servers[idx] ||= ClusterChef::Server.new(self, idx) @servers[idx].configure(attrs, &block) @servers[idx] end |
#servers ⇒ ClusterChef::ServerSlice
All servers in this facet
74 75 76 |
# File 'lib/cluster_chef/facet.rb', line 74 def servers slice(indexes) end |
#slice(slice_indexes = nil) ⇒ ClusterChef::ServerSlice
A slice of servers from this facet, in index order
If slice_indexes
is nil, returns all servers. Otherwise, takes slice (given by *args) from the requested facet.
87 88 89 90 91 92 |
# File 'lib/cluster_chef/facet.rb', line 87 def slice(slice_indexes=nil) slice_indexes = self.indexes if slice_indexes.blank? slice_indexes = indexes_from_intervals(slice_indexes) if slice_indexes.is_a?(String) svrs = Array(slice_indexes).map(&:to_i).sort!.select{|idx| has_server?(idx) }.map{|idx| server(idx) } ClusterChef::ServerSlice.new(self.cluster, svrs) end |
#valid_indexes ⇒ Object
all valid server indexes
95 96 97 |
# File 'lib/cluster_chef/facet.rb', line 95 def valid_indexes (0 ... instances).to_a # note the '...' end |