Class: MotherBrain::Bootstrap::Manifest

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

Overview

Manifest for bootstrapping a collection of nodes as a specified node group

Examples:

valid manifest structure

{
  "nodes": [
    {
      "groups": ["activemq::master"],
      "hosts": [
        "euca-10-20-37-171.eucalyptus.cloud.riotgames.com",
        "euca-10-20-37-172.eucalyptus.cloud.riotgames.com"
      ]
    },
    {
      "groups": ["activemq::slave"],
      "hosts": [
        "euca-10-20-37-168.eucalyptus.cloud.riotgames.com"
       ]
    }
  ]
}

Instance Attribute Summary

Attributes inherited from Manifest

#path

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Manifest

from_file, from_hash, #from_hash, #from_json, from_json, #initialize, #node_count, #node_groups, #options, #save

Constructor Details

This class inherits a constructor from MotherBrain::Manifest

Class Method Details

.from_provisioner(nodes, provisioner_manifest, path = nil) ⇒ Bootstrap::Manifest

Create a new instance of MotherBrain::Bootstrap::Manifest from the returning value from calling Provisioner#up on a provisioner and the provision manifest sent to Provisioner#up.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/mb/bootstrap/manifest.rb', line 37

def from_provisioner(nodes, provisioner_manifest, path = nil)
  nodes      = nodes.dup
  attributes = provisioner_manifest.dup

  new.tap do |boot_manifest|
    boot_manifest.path    = path
    boot_manifest[:nodes] = Array.new
    boot_manifest[:options] = provisioner_manifest[:options]

    attributes.node_groups.each do |node_group|
      instance_type = node_group[:type]
      count         = node_group[:count] || 1
      groups        = node_group[:groups]
      hosts         = Set.new

      used_instances = nodes.select { |node|
        node[:instance_type] == instance_type
      }.take(count)

      used_instances.each do |used_instance|
        hosts.add(used_instance[:public_hostname])
        nodes.delete(used_instance)
      end

      boot_manifest[:nodes] << {
        groups: groups,
        hosts: hosts.to_a
      }
    end
  end
end

.validate!(manifest, plugin) ⇒ Object

Validates that the instance of manifest describes a layout for the given routine



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/mb/bootstrap/manifest.rb', line 76

def validate!(manifest, plugin)
  unless plugin.bootstrap_routine
    raise NoBootstrapRoutine,
      "Plugin '#{plugin.name}' (#{plugin.version}) does not contain a bootstrap routine"
  end

  unless manifest[:nodes].is_a?(Array)
    msg = "Manifest should contain an array of nodes"
    raise InvalidBootstrapManifest, msg
  end

  manifest.node_groups.each do |node_group|
    groups = node_group[:groups]

    groups.each do |group|
      match = group.match(Plugin::NODE_GROUP_ID_REGX)

      unless match
        msg = "Manifest contained the entry: '#{group}' which is not"
        msg << " in the proper node group format: 'component::group'"
        raise InvalidBootstrapManifest, msg
      end

      unless plugin.bootstrap_routine.has_task?(group)
        msg = "Manifest describes the node group '#{group}' which is not found"
        msg << " in the given routine for '#{plugin}'"
        raise InvalidBootstrapManifest, msg
      end
    end
  end
end

Instance Method Details

#hosts_for_group(group) ⇒ Array

Finds all hosts to be bootstrapped with a set of groups



112
113
114
115
116
117
118
# File 'lib/mb/bootstrap/manifest.rb', line 112

def hosts_for_group(group)
  hosts = node_groups.select do |node_group|
    node_group[:groups].include?(group)
  end.collect { |node_group| node_group[:hosts] }.flatten

  MB::NodeFilter.expand_ipranges(hosts)
end

#validate!(plugin) ⇒ Object

Validates that the instance of manifest describes a layout for the given routine



126
127
128
# File 'lib/mb/bootstrap/manifest.rb', line 126

def validate!(plugin)
  self.class.validate!(self, plugin)
end