Skip to content

Commit

Permalink
Suspend provider workers
Browse files Browse the repository at this point in the history
Initial commit for suspending providers

https://bugzilla.redhat.com/show_bug.cgi?id=1455145
  • Loading branch information
slemrmartin committed May 25, 2018
1 parent 5a4ab9f commit 0d74660
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
9 changes: 9 additions & 0 deletions app/models/ext_management_system.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@ def hostname_format_valid?

default_value_for :enabled, true

def self.enable(ems_id)
ExtManagementSystem.where('id = ? OR parent_ems_id = ?', ems_id, ems_id).update_all(enabled: true)
end

def self.disable(ems_id)
ExtManagementSystem.where('id = ? OR parent_ems_id = ?', ems_id, ems_id).update_all(enabled: false)
end


def self.with_ipaddress(ipaddress)
joins(:endpoints).where(:endpoints => {:ipaddress => ipaddress})
end
Expand Down
17 changes: 17 additions & 0 deletions app/models/miq_queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ def self.put(options)
def self.submit_job(options)
service = options.delete(:service) || "generic"
resource = options.delete(:affinity)

return unless resource_enabled?(resource)

case service
when "automate"
# options[:queue_name] = "generic"
Expand Down Expand Up @@ -206,6 +209,20 @@ def self.submit_job(options)
put(options)
end

# TODO: Array param not seen yet
# @param resource [ExtManagementSystem|Nil|Array<Class,id>] resource for affinity. Typically an ems
def self.resource_enabled?(resource)
if resource.respond_to?(:ext_management_system)
ems = resource.ext_management_system
if ems.present? && !ems.enabled
_log.info("Provider is disabled: #{ems.name}. MiqQueue skipped.")
return false
end
end

true
end

def self.where_queue_name(is_array)
is_array ? "AND queue_name in (?)" : "AND queue_name = ?"
end
Expand Down

0 comments on commit 0d74660

Please sign in to comment.