Module: BlackStack::Deployer::RoutineModule
- Included in:
- Routine
- Defined in:
- lib/blackstack-deployer.rb
Overview
define attributes and methods of a deployer routine
Instance Attribute Summary collapse
-
#commands ⇒ Object
Returns the value of attribute commands.
-
#name ⇒ Object
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(h) ⇒ Object
def self.descriptor_error(h).
- #run(node) ⇒ Object
- #to_hash ⇒ Object
Instance Attribute Details
#commands ⇒ Object
Returns the value of attribute commands.
84 85 86 |
# File 'lib/blackstack-deployer.rb', line 84 def commands @commands end |
#name ⇒ Object
Returns the value of attribute name.
84 85 86 |
# File 'lib/blackstack-deployer.rb', line 84 def name @name end |
Class Method Details
.descriptor_errors(h) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'lib/blackstack-deployer.rb', line 86 def self.descriptor_errors(h) errors = [] # validate: the parameter h is a hash errors << "The parameter h is not a hash" unless h.is_a?(Hash) # validate: the paramerer h has a key :name errors << "The parameter h does not have a key :name" unless h.has_key?(:name) # validate: the paramerer h has a key :command errors << "The parameter h does not have a key :commands" unless h.has_key?(:commands) # validate: the parameter h[:name] is a string or a symbol errors << "The parameter h[:name] is not a string" unless h[:name].is_a?(String) # validate: the parameter h[:name] is not 'reboot' because it is a reserved name errors << "The parameter h[:name] is a reserved name (#{h[:name].to_s})" if h[:name] == 'reboot' # validate: the parameter h[:commands] is required errors << "The parameter h[:commands] is required" if h[:commands].nil? # validate: the parametrer h[:commands] is an array errors << "The parameter h[:commands] is not an array" unless h[:commands].is_a?(Array) # validate: the parameter h[:commands] has at least one element errors << "The parameter h[:commands] does not have at least one element" unless h[:commands].size > 0 # validate: each element of the array h[:commands] is a hash h[:commands].each do |c| errors += BlackStack::Deployer::CommandModule.descriptor_errors(c) end # h[:commands].each do |c| errors.uniq end |
Instance Method Details
#initialize(h) ⇒ Object
def self.descriptor_error(h)
121 122 123 124 125 126 127 128 129 |
# File 'lib/blackstack-deployer.rb', line 121 def initialize(h) errors = BlackStack::Deployer::RoutineModule.descriptor_errors(h) raise "The node descriptor is not valid: #{errors.uniq.join(".\n")}" if errors.length > 0 self.name = h[:name] self.commands = [] h[:commands].each do |c| self.commands << BlackStack::Deployer::Command.new(c) end end |
#run(node) ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/blackstack-deployer.rb', line 141 def run(node) ret = [] self.commands.each do |c| BlackStack::Deployer.logger.logs "Running command: #{c.command.to_s}... " h = c.run(node) ret << h #BlackStack::Deployer.logger.logs "Result: " #BlackStack::Deployer.logger.logf h.to_s if h[:errors].size == 0 BlackStack::Deployer.logger.done else BlackStack::Deployer.logger.logf('error: ' + h.to_s) raise "Error running command: #{h.to_s}" end end ret end |
#to_hash ⇒ Object
131 132 133 134 135 136 137 138 139 |
# File 'lib/blackstack-deployer.rb', line 131 def to_hash h = {} h[:name] = self.name h[:commands] = [] self.commands.each do |c| h[:commands] << c.to_hash end h end |