Class: PoolParty::Pool

Inherits:
Base show all
Defined in:
lib/poolparty/pool.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#name

Instance Method Summary collapse

Methods inherited from Base

#after_initialized, #initialize, #method_missing

Constructor Details

This class inherits a constructor from PoolParty::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class PoolParty::Base

Instance Attribute Details

#auto_executeObject

Returns the value of attribute auto_execute.



4
5
6
# File 'lib/poolparty/pool.rb', line 4

def auto_execute
  @auto_execute
end

#debuggingObject

Returns the value of attribute debugging.



4
5
6
# File 'lib/poolparty/pool.rb', line 4

def debugging
  @debugging
end

#verboseObject

Returns the value of attribute verbose.



4
5
6
# File 'lib/poolparty/pool.rb', line 4

def verbose
  @verbose
end

#very_debuggingObject

Returns the value of attribute very_debugging.



4
5
6
# File 'lib/poolparty/pool.rb', line 4

def very_debugging
  @very_debugging
end

#very_verboseObject

Returns the value of attribute very_verbose.



4
5
6
# File 'lib/poolparty/pool.rb', line 4

def very_verbose
  @very_verbose
end

Instance Method Details

#chef_step(name = nil) ⇒ Object

Description

Set / Get the chef_step which will be executed on the remote host



42
43
44
45
46
47
48
# File 'lib/poolparty/pool.rb', line 42

def chef_step name = nil
  @selected_chef_step ||= :default
  if name
    @selected_chef_step = name.to_sym
  end
  @selected_chef_step
end

#cloud(name, &block) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/poolparty/pool.rb', line 6

def cloud(name, &block)
  c = Cloud.new(name.to_s, {:parent => self}, &block)
  clouds[name.to_s] = c
  # Create a dummy security group for tagging purposes. Do not want to
  # conflict with advance usage of security groups
  c.security_group "#poolparty-#{c.proper_name}"
end

#cloudsObject



14
15
16
# File 'lib/poolparty/pool.rb', line 14

def clouds
  @clouds ||= {}
end

#cmd(commands, opts = {}) ⇒ Object

Run command/s on all nodes in the pool. Returns a hash in the form of => [{instance_id=>result]}



20
21
22
23
24
25
26
27
# File 'lib/poolparty/pool.rb', line 20

def cmd(commands, opts={})
  results = {}
  threads = clouds.collect do |name, c|
    Thread.new{ results[ name ] = c.cmd(commands, opts) }
  end
  threads.each{ |aThread| aThread.join }
  results
end

#runObject



50
51
52
53
54
55
# File 'lib/poolparty/pool.rb', line 50

def run
  clouds.each do |cloud_name, cld|
    puts "----> Starting to build cloud #{cloud_name}"
    cld.run
  end
end

#to_hashObject



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/poolparty/pool.rb', line 57

def to_hash
  c = clouds.collect do |cloud_name, cld|
    nodes = cld.nodes.collect do |node|
      h = {}
      [:dns_name, :private_ip, :public_ip].each do |f|
        h[f] = node[f]
      end
      h
    end
    { cloud_name => nodes }
  end
  h = c.inject({})do |old, new|
   old.merge! new
  end 
  {:clouds => h }
end