Class: Biosphere::CLI::TerraformPlanning::TerraformPlan
- Inherits:
-
Object
- Object
- Biosphere::CLI::TerraformPlanning::TerraformPlan
- Defined in:
- lib/biosphere/cli/terraformplanning.rb
Instance Attribute Summary collapse
-
#items ⇒ Object
Returns the value of attribute items.
Instance Method Summary collapse
- #get_resources ⇒ Object
- #has_unpicked_resources ⇒ Object
-
#initialize ⇒ TerraformPlan
constructor
A new instance of TerraformPlan.
- #length ⇒ Object
- #print(out = STDOUT) ⇒ Object
Constructor Details
#initialize ⇒ TerraformPlan
Returns a new instance of TerraformPlan.
240 241 242 243 |
# File 'lib/biosphere/cli/terraformplanning.rb', line 240 def initialize() @items = [] @graph = nil end |
Instance Attribute Details
#items ⇒ Object
Returns the value of attribute items.
239 240 241 |
# File 'lib/biosphere/cli/terraformplanning.rb', line 239 def items @items end |
Instance Method Details
#get_resources ⇒ Object
289 290 291 |
# File 'lib/biosphere/cli/terraformplanning.rb', line 289 def get_resources() @items.select { |x| x[:action] != :not_picked }.collect { |x| x[:resource_name] } end |
#has_unpicked_resources ⇒ Object
285 286 287 |
# File 'lib/biosphere/cli/terraformplanning.rb', line 285 def has_unpicked_resources() @items.find_index { |x| x[:action] == :not_picked } != nil end |
#length ⇒ Object
245 246 247 |
# File 'lib/biosphere/cli/terraformplanning.rb', line 245 def length @items.length end |
#print(out = STDOUT) ⇒ Object
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/biosphere/cli/terraformplanning.rb', line 249 def print(out = STDOUT) last_target_group = nil @items.sort_by { |a| a[:target_group] }.each do |item| if last_target_group != item[:target_group] if item[:target_group] != "" out.write "\nTarget group: #{item[:target_group]}\n" else out.write "\nNot in any target groups:\n" end last_target_group = item[:target_group] end out.write "\t" out.write "#{item[:resource_name]} " if item[:action] == :create out.write "(#{item[:reason]})".colorize(:green) elsif item[:action] == :relaunch out.write "(#{item[:reason]})".colorize(:yellow) elsif item[:action] == :destroy out.write "(#{item[:reason]})".colorize(:red) elsif item[:action] == :change out.write "(#{item[:reason]})".colorize(:yellow) elsif item[:action] == :not_picked out.write "(#{item[:reason]})".colorize(:yellow) else out.write "(#{item[:reason]}) unknown action: #{item[:action]}".colorize(:red) end out.write "\n" end if has_unpicked_resources() out.write "\nWARNING: Not all resource changes will be applied!".colorize(:yellow) out.write "\nYou need to do \"biosphere commit\" again when you have verified that it is safe to do so!".colorize(:yellow) end end |