Sha256: bd420f95eacdf22f2569e5b292876f4c2bd4f5306ee9e0410c3508cca8f1bdeb

Contents?: true

Size: 1.79 KB

Versions: 9

Compression:

Stored size: 1.79 KB

Contents

module Actions
  module Katello
    module System
      class ActivationKeys < Actions::Base
        def plan(system, activation_keys)
          activation_keys ||= []

          set_environment_and_content_view(system, activation_keys)
          set_host_collections(system, activation_keys)
          set_association(system, activation_keys)
        end

        def set_association(system, activation_keys)
          system.activation_keys = activation_keys
        end

        def set_environment_and_content_view(system, activation_keys)
          return if system.content_view

          activation_key = activation_keys.reverse.detect do |act_key|
            act_key.environment && act_key.content_view
          end
          if activation_key
            system.environment = activation_key.environment
            system.content_view = activation_key.content_view
          else
            fail _('At least one activation key must have a lifecycle environment and content view assigned to it')
          end
        end

        def set_host_collections(system, activation_keys)
          host_collection_ids = activation_keys.flat_map(&:host_collection_ids).compact.uniq

          host_collection_ids.each do |host_collection_id|
            host_collection = ::Katello::HostCollection.find(host_collection_id)
            if !host_collection.unlimited_content_hosts && host_collection.max_content_hosts >= 0 &&
               host_collection.systems.length >= host_collection.max_content_hosts
              fail _("Host collection '%{name}' exceeds maximum usage limit of '%{limit}'") %
                       {:limit => host_collection.max_content_hosts, :name => host_collection.name}
            end
          end
          system.host_collection_ids = host_collection_ids
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
katello-2.4.5 app/lib/actions/katello/system/activation_keys.rb
katello-2.4.4 app/lib/actions/katello/system/activation_keys.rb
katello-2.4.3 app/lib/actions/katello/system/activation_keys.rb
katello-2.4.2 app/lib/actions/katello/system/activation_keys.rb
katello-2.4.1 app/lib/actions/katello/system/activation_keys.rb
katello-2.4.0 app/lib/actions/katello/system/activation_keys.rb
katello-2.4.0.rc3 app/lib/actions/katello/system/activation_keys.rb
katello-2.4.0.rc2 app/lib/actions/katello/system/activation_keys.rb
katello-2.4.0.rc1 app/lib/actions/katello/system/activation_keys.rb