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.
109 110 111 |
# File 'lib/blackstack-deployer.rb', line 109 def commands @commands end |
#name ⇒ Object
Returns the value of attribute name.
109 110 111 |
# File 'lib/blackstack-deployer.rb', line 109 def name @name end |
Class Method Details
.descriptor_errors(h) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/blackstack-deployer.rb', line 111 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)
146 147 148 149 150 151 152 153 154 |
# File 'lib/blackstack-deployer.rb', line 146 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
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/blackstack-deployer.rb', line 166 def run(node) ret = [] self.commands.each do |c| lines = c.command.to_s.strip.split(/\n/) # use this to make log more easy to read. line_to_show = lines[0].size > 25 ? lines[0][0..25] + "..." : lines[0] # use this to make log more easy to read. BlackStack::Deployer.logger.logs "Running command: #{line_to_show.to_s} #{lines.size > 1 ? "(+#{lines.size-1} more lines)" : ''}... " #puts 'b1' h = c.run(node) #puts 'b2' 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:\n#{h[:errors].uniq.join("\n")}" end end ret end |
#to_hash ⇒ Object
156 157 158 159 160 161 162 163 164 |
# File 'lib/blackstack-deployer.rb', line 156 def to_hash h = {} h[:name] = self.name h[:commands] = [] self.commands.each do |c| h[:commands] << c.to_hash end h end |