Module Rudy::Machines

  1. lib/rudy/machines.rb

Methods

public class

  1. list

public instance

  1. create
  2. exists?
  3. find_next_position
  4. from_hash
  5. get
  6. restart
  7. running?

Constants

RTYPE = 'm'.freeze

Public class methods

list (*args, &blk)
[show source]
    # File lib/rudy/machines.rb, line 19
19:     def self.list(*args, &blk)
20:       machs = super(*args, &blk) || []
21:       manual = [fetch_machine_param(:hostname)].flatten.compact
22:       manual.reject! { |m| m.is_a?(Symbol) }
23:       machs.push *manual
24:       machs
25:     end

Public instance methods

create (size=nil)

Returns an Array of newly created Rudy::Machine objects

[show source]
    # File lib/rudy/machines.rb, line 48
48:     def create(size=nil)
49:       if Rudy::Huxtable.global.position.nil?
50:         size ||= current_machine_count.to_i || 1
51:         group = Array.new(size) do |i|
52:           m = Rudy::Machine.new(i + 1)
53:           m.create
54:           li "Created: #{m.to_s}"
55:           m
56:         end
57:       else
58:         m = Rudy::Machine.new(Rudy::Huxtable.global.position)
59:         m.create
60:         li "Created: #{m.to_s}"
61:         group = [m]
62:       end
63:       group
64:     end
exists? (pos=nil)

Returns true if any machine metadata exists for this group

[show source]
    # File lib/rudy/machines.rb, line 34
34:     def exists?(pos=nil)
35:       machines = pos.nil? ? list : get(pos)
36:       !machines.nil?
37:     end
find_next_position ()
[show source]
    # File lib/rudy/machines.rb, line 26
26:     def find_next_position
27:       raise "reimplement by looking at position values"
28:       list = Rudy::Machines.list({}, [:position]) || []
29:       pos = list.size + 1
30:       pos.to_s.rjust(2, '0')
31:     end
from_hash (h)
[show source]
    # File lib/rudy/machines.rb, line 75
75:     def from_hash(h)
76:       Rudy::Machine.from_hash h
77:     end
get (position)
[show source]
    # File lib/rudy/machines.rb, line 12
12:     def get(position)
13:       tmp = Rudy::Machine.new position
14:       record = Rudy::Metadata.get tmp.name
15:       return nil unless record.is_a?(Hash)
16:       tmp.from_hash record
17:     end
restart ()
[show source]
    # File lib/rudy/machines.rb, line 66
66:     def restart
67:       group = list 
68:       raise MachineGroupNotRunning, current_machine_group if group.nil?
69:       group.each do |inst|
70:         inst.restart
71:       end
72:       group
73:     end
running? (pos=nil)

Returns true if all machines in the group are running instances

[show source]
    # File lib/rudy/machines.rb, line 40
40:     def running?(pos=nil)
41:       group = pos.nil? ? list : [get(pos)].compact
42:       return false if group.nil? || group.empty?
43:       group.collect! { |m| m.instance_running? }
44:       !group.member?(false)
45:     end