Module: Miasma::Models::Orchestration::Terraform::Boule
- Defined in:
- lib/miasma/contrib/terraform/orchestration.rb
Instance Method Summary collapse
-
#event_all(stack, marker = nil) ⇒ Array<Models::Orchestration::Stack::Event>
Return all events for stack.
-
#event_all_new(events) ⇒ Array<Models::Orchestration::Stack::Event>
Return all new events for event collection.
-
#event_reload(event) ⇒ Models::Orchestration::Event
Reload the stack event data from the API.
-
#resource_all(stack) ⇒ Array<Models::Orchestration::Stack::Resource>
Return all resources for stack.
-
#resource_reload(resource) ⇒ Models::Orchestration::Resource
Reload the stack resource data from the API.
-
#stack_all(options = {}) ⇒ Array<Models::Orchestration::Stack>
Return all stacks.
-
#stack_destroy(stack) ⇒ TrueClass, FalseClass
Delete the stack.
-
#stack_reload(stack) ⇒ Models::Orchestration::Stack
Reload the stack data from the API.
-
#stack_save(stack) ⇒ Models::Orchestration::Stack
Save the stack.
-
#stack_template_load(stack) ⇒ Smash
Fetch stack template.
-
#stack_template_validate(stack) ⇒ NilClass, String
Validate stack template.
Instance Method Details
#event_all(stack, marker = nil) ⇒ Array<Models::Orchestration::Stack::Event>
Return all events for stack
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 |
# File 'lib/miasma/contrib/terraform/orchestration.rb', line 398 def event_all(stack, marker = nil) params = marker ? {:marker => marker} : {} result = request( :path => "/terraform/events/#{stack.name}", :method => :get, :params => params ) result.fetch(:body, :events, []).map do |event| Stack::Event.new( stack, :id => event[:id], :resource_id => event[:physical_resource_id], :resource_name => event[:resource_name], :resource_logical_id => event[:resource_name], :resource_state => event[:resource_status].downcase.to_sym, :resource_status => event[:resource_status], :resource_status_reason => event[:resource_status_reason], :time => Time.at(event[:timestamp] / 1000.0) ).valid_state end end |
#event_all_new(events) ⇒ Array<Models::Orchestration::Stack::Event>
Return all new events for event collection
424 425 426 |
# File 'lib/miasma/contrib/terraform/orchestration.rb', line 424 def event_all_new(events) event_all(events.stack, events.all.first.id) end |
#event_reload(event) ⇒ Models::Orchestration::Event
Reload the stack event data from the API
432 433 434 435 |
# File 'lib/miasma/contrib/terraform/orchestration.rb', line 432 def event_reload(event) event.stack.events.reload event.stack.events.get(event.id) end |
#resource_all(stack) ⇒ Array<Models::Orchestration::Stack::Resource>
Return all resources for stack
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 |
# File 'lib/miasma/contrib/terraform/orchestration.rb', line 365 def resource_all(stack) result = request( :method => :get, :path => "/terraform/resources/#{stack.name}" ) result.fetch(:body, :resources, []).map do |resource| Stack::Resource.new( stack, :id => resource[:physical_id], :name => resource[:name], :type => resource[:type], :logical_id => resource[:name], :state => resource[:status].downcase.to_sym, :status => resource[:status], :status_reason => resource[:resource_status_reason], :updated => resource[:updated_time].to_s.empty? ? Time.now : Time.parse(resource[:updated_time]) ).valid_state end end |
#resource_reload(resource) ⇒ Models::Orchestration::Resource
Reload the stack resource data from the API
389 390 391 392 |
# File 'lib/miasma/contrib/terraform/orchestration.rb', line 389 def resource_reload(resource) resource.stack.resources.reload resource.stack.resources.get(resource.id) end |
#stack_all(options = {}) ⇒ Array<Models::Orchestration::Stack>
TODO:
check if we need any mappings on state set
Return all stacks
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
# File 'lib/miasma/contrib/terraform/orchestration.rb', line 341 def stack_all(={}) result = request( :method => :get, :path => '/terraform/stacks' ) result.fetch(:body, :stacks, []).map do |s| Stack.new( self, :id => s[:id], :created => s[:creation_time].to_s.empty? ? nil : Time.at(s[:creation_time].to_i / 1000.0), :description => s[:description], :name => s[:name], :state => s[:status].downcase.to_sym, :status => s[:status], :status_reason => s[:stack_status_reason], :updated => s[:updated_time].to_s.empty? ? nil : Time.at(s[:updated_time].to_i / 1000.0) ).valid_state end end |
#stack_destroy(stack) ⇒ TrueClass, FalseClass
Delete the stack
289 290 291 292 293 294 295 296 297 298 299 |
# File 'lib/miasma/contrib/terraform/orchestration.rb', line 289 def stack_destroy(stack) if(stack.persisted?) request( :method => :delete, :path => "/terraform/stack/#{stack.name}" ) true else false end end |
#stack_reload(stack) ⇒ Models::Orchestration::Stack
Reload the stack data from the API
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 |
# File 'lib/miasma/contrib/terraform/orchestration.rb', line 263 def stack_reload(stack) if(stack.persisted?) result = request( :method => :get, :path => "/terraform/stack/#{stack.name}" ) s = result.get(:body, :stack) stack.load_data( :id => s[:id], :created => s[:creation_time].to_s.empty? ? nil : Time.at(s[:creation_time].to_i / 1000.0), :description => s[:description], :name => s[:name], :state => s[:status].downcase.to_sym, :status => s[:status], :status_reason => s[:stack_status_reason], :updated => s[:updated_time].to_s.empty? ? nil : Time.at(s[:updated_time].to_i / 1000.0), :outputs => s[:outputs].map{|k,v| {:key => k, :value => v}} ).valid_state end stack end |
#stack_save(stack) ⇒ Models::Orchestration::Stack
Save the stack
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/miasma/contrib/terraform/orchestration.rb', line 232 def stack_save(stack) if(stack.persisted?) stack.load_data(stack.attributes) result = request( :method => :put, :path => "/terraform/stack/#{stack.name}", :json => { :template => MultiJson.dump(stack.template), :parameters => stack.parameters || {} } ) stack.valid_state else stack.load_data(stack.attributes) result = request( :method => :post, :path => "/terraform/stack/#{stack.name}", :json => { :template => MultiJson.dump(stack.template), :parameters => stack.parameters || {} } ) stack.id = result.get(:body, :stack, :id) stack.valid_state end end |
#stack_template_load(stack) ⇒ Smash
Fetch stack template
305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/miasma/contrib/terraform/orchestration.rb', line 305 def stack_template_load(stack) if(stack.persisted?) result = request( :method => :get, :path => "/terraform/template/#{stack.name}" ) result.fetch(:body, Smash.new) else Smash.new end end |
#stack_template_validate(stack) ⇒ NilClass, String
Validate stack template
321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
# File 'lib/miasma/contrib/terraform/orchestration.rb', line 321 def stack_template_validate(stack) begin result = request( :method => :post, :path => '/terraform/validate', :json => Smash.new( :template => stack.template ) ) nil rescue Error::ApiError::RequestError => e MultiJson.load(e.response.body.to_s).to_smash.get(:error, :message) end end |