Class: MotherBrain::Provisioner::Manifest
- Defined in:
- lib/mb/provisioner/manifest.rb
Overview
Manifest for creating a set of nodes of a given instance type for a set of node groups
Instance Attribute Summary
Attributes inherited from Manifest
Class Method Summary collapse
-
.validate!(manifest, plugin) ⇒ Object
Validate the given parameter contains a Hash or Manifest with a valid structure.
Instance Method Summary collapse
-
#provisioner ⇒ String
The provisioner token from the manifest.
- #validate!(plugin) ⇒ Object
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
.validate!(manifest, plugin) ⇒ Object
Validate the given parameter contains a Hash or Manifest with a valid structure
32 33 34 35 36 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 68 69 70 71 72 73 74 75 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 107 108 109 |
# File 'lib/mb/provisioner/manifest.rb', line 32 def validate!(manifest, plugin) unless manifest.is_a?(Hash) raise InvalidProvisionManifest, "The provisioner manifest needs to be a hash, but you provided a(n) #{manifest.class}" end nodes = manifest[:nodes] unless nodes raise InvalidProvisionManifest, "The provisioner manifest needs to have a key 'nodes' containing an array" end unless nodes.is_a?(Array) raise InvalidProvisionManifest, "The provisioner manifest needs to have a key 'nodes' containing an array, but it was a(n) #{nodes.class}" end nodes.each do |node| unless node.is_a?(Hash) raise InvalidProvisionManifest, "The provisioner manifest needs to have an array of hashes at 'nodes', but there was a #{node.class}: #{node.inspect}" end unless node.has_key?(:type) && !node[:type].nil? raise InvalidProvisionManifest, "A node entry in a provision manifest needs to contain key 'type' with a value." end unless node.has_key?(:groups) && !node[:groups].nil? raise InvalidProvisionManifest, "A node entry in a provision manifest needs to contain a key 'groups' with a value." end type = node[:type] count = node[:count] groups = node[:groups] unless type.to_s.match(/\w+\.\w+/) raise InvalidProvisionManifest, "Provision manifest contained an entry not in the proper format: '#{type}'. Expected: 'a1.size'" end if count unless count.is_a?(Fixnum) && count >= 0 raise InvalidProvisionManifest, "Provision manifest contained an invalid value for count: '#{count}'. Expected an integer greater than 0." end end unless groups.is_a?(Array) raise InvalidProvisionManifest, "The provisioner manifest contains a node group without an array of groups: #{node.inspect}" end groups.each do |group| match = group.match(Plugin::NODE_GROUP_ID_REGX) unless match raise InvalidProvisionManifest, "Provision manifest contained an entry not in the proper format: '#{name}'. Expected: 'component::group'" end component = match[1] group = match[2] unless plugin.has_component?(component) raise InvalidProvisionManifest, "Provision manifest describes the component: '#{component}' but '#{plugin.name}' does not have this component" end unless plugin.component(component).has_group?(group) raise InvalidProvisionManifest, "Provision manifest describes the group: '#{group}' in the component '#{component}' but that component does not have this group" end end end end |
Instance Method Details
#provisioner ⇒ String
Returns the provisioner token from the manifest.
120 121 122 |
# File 'lib/mb/provisioner/manifest.rb', line 120 def provisioner self[:provisioner] end |
#validate!(plugin) ⇒ Object
115 116 117 |
# File 'lib/mb/provisioner/manifest.rb', line 115 def validate!(plugin) self.class.validate!(self, plugin) end |