Class: MotherBrain::Bootstrap::Routine

Inherits:
Object
  • Object
show all
Defined in:
lib/mb/bootstrap/routine.rb

Defined Under Namespace

Classes: CleanRoom, Task

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plugin, &block) ⇒ Routine

Returns a new instance of Routine.

Parameters:



113
114
115
116
117
118
119
120
# File 'lib/mb/bootstrap/routine.rb', line 113

def initialize(plugin, &block)
  @plugin     = plugin
  @task_procs = Array.new

  if block_given?
    dsl_eval(&block)
  end
end

Instance Attribute Details

#pluginMB::Plugin (readonly)

Returns:



110
111
112
# File 'lib/mb/bootstrap/routine.rb', line 110

def plugin
  @plugin
end

Class Method Details

.map_instructions(tasks, manifest) ⇒ Hash

Takes a task, or array of tasks, and a Bootstrap::Manifest and returns a Hash containing instructions for how to bootstrap each node found in the manifest based on the set of tasks, or task, given.

Parameters:

Returns:

  • (Hash)

    A hash containing an entry for every host to bootstrap and the groups it belongs to, the run list it should be bootstrapped with, and the chef attributes to be applied to the node for it’s first run.

    {

    "euca-10-20-37-171.eucalyptus.cloud.riotgames.com" => {
      groups: [ "app_server::default" ],
      options: {
        run_list: Array.new,
        chef_attributes: Hashie::Hash.new
      }
    },
    "euca-10-20-37-172.eucalyptus.cloud.riotgames.com" => {
      groups: [ "app_server::default", "database_slave::default" ],
      options: {
        run_list: Array.new,
        chef_attributes: Hashie::Hash.new
      }
    },
    "euca-10-20-37-168.eucalyptus.cloud.riotgames.com" => {
      groups: [ "database_master::default" ],
      options: {
        run_list: Array.new,
        chef_attributes: Hashie::Hash.new
      }
    }
    

    }



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/mb/bootstrap/routine.rb', line 87

def map_instructions(tasks, manifest)
  {}.tap do |nodes|
    Array(tasks).each do |task|
      manifest.hosts_for_group(task.group_name).each do |host|
        nodes[host] ||= {
          groups: Array.new,
          options: {
            run_list: Array.new,
            chef_attributes: Hashie::Mash.new
          }
        }

        nodes[host][:groups] << task.group_name unless nodes[host][:groups].include?(task.group_name)
        nodes[host][:options][:run_list]        = nodes[host][:options][:run_list] | task.run_list
        nodes[host][:options][:chef_attributes] =
          nodes[host][:options][:chef_attributes].deep_merge(task.chef_attributes)
      end
    end
  end
end

Instance Method Details

#has_task?(node_group, task_queue = self.task_queue) ⇒ Boolean

Checks if the routine contains a boot task for the given node group

Parameters:

  • node_group (String)

    name for a bootstrap task to check for

Returns:

  • (Boolean)


138
139
140
141
142
143
144
145
146
# File 'lib/mb/bootstrap/routine.rb', line 138

def has_task?(node_group, task_queue = self.task_queue)
  task_queue.find do |task|
    if task.is_a?(Array)
      has_task?(node_group, task)
    else
      task.group_name == node_group
    end
  end
end

#task_queueArray<Bootstrap::Routine::Task>+

Returns an array of groups or an array of an array groups representing the order in which the cluster should be bootstrapped in. Groups which can be bootstrapped together are contained within an array. Groups should be bootstrapped starting from index 0 of the returned array.

Returns:



128
129
130
# File 'lib/mb/bootstrap/routine.rb', line 128

def task_queue
  @task_queue ||= MB.expand_procs(task_procs)
end