ManageIQ/manageiq-providers-azure

View on GitHub
app/models/manageiq/providers/azure/cloud_manager/deployment.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
module ManageIQ::Providers::Azure::CloudManager::Deployment
  extend ActiveSupport::Concern

  def deployment_failed?(deployment)
    deployment.properties.provisioning_state.casecmp('failed').zero?
  end

  # Azure deployment does not contain failure reason. The actual reasons exist in the operations.
  # This method finds the FIRST error message from the operations. It can be used as the failure reason for the stack.
  # Note: There may be multiple failure reasons.
  def deployment_failure_reason(deployment_operations)
    deployment_operations.each do |operation|
      message = operation_status_message(operation)
      return message if message.present?
    end
    nil
  end

  def operation_status_message(operation)
    status_message = operation.properties.try(:status_message)
    return nil unless status_message

    status_message.try(:error).try(:message) || status_message.to_s
  end
end