Sha256: 454002f0b367cd4e2c62ba59bed550270e21aae88ea856d30ceb000b4a8086ee

Contents?: true

Size: 1.77 KB

Versions: 3

Compression:

Stored size: 1.77 KB

Contents

module ForemanRemoteExecution
  module HostExtensions
    extend ActiveSupport::Concern

    included do
      alias_method_chain :build_required_interfaces, :remote_execution
      alias_method_chain :reload, :remote_execution
      alias_method_chain :becomes, :remote_execution

      has_many :targeting_hosts, :dependent => :destroy, :foreign_key => 'host_id'
    end

    def execution_interface
      get_interface_by_flag(:execution)
    end

    def remote_execution_proxies(provider)
      proxies = {}
      proxies[:subnet]   = execution_interface.subnet.remote_execution_proxies.with_features(provider) if execution_interface && execution_interface.subnet
      proxies[:fallback] = smart_proxies.with_features(provider) if Setting[:remote_execution_fallback_proxy]

      if Setting[:remote_execution_global_proxy]
        proxy_scope = if Taxonomy.enabled_taxonomies.any?
                        ::SmartProxy.with_taxonomy_scope_override(location, organization)
                      else
                        proxy_scope = ::SmartProxy
                      end

        proxies[:global] = proxy_scope.authorized.with_features(provider)
      end

      proxies
    end

    def drop_execution_interface_cache
      @execution_interface = nil
    end

    def becomes_with_remote_execution(*args)
      became = becomes_without_remote_execution(*args)
      became.drop_execution_interface_cache
      became
    end

    def reload_with_remote_execution(*args)
      drop_execution_interface_cache
      reload_without_remote_execution(*args)
    end

    private

    def build_required_interfaces_with_remote_execution(attrs = {})
      build_required_interfaces_without_remote_execution(attrs)
      self.primary_interface.execution = true if self.execution_interface.nil?
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
foreman_remote_execution-0.0.10 app/models/concerns/foreman_remote_execution/host_extensions.rb
foreman_remote_execution-0.0.8 app/models/concerns/foreman_remote_execution/host_extensions.rb
foreman_remote_execution-0.0.7 app/models/concerns/foreman_remote_execution/host_extensions.rb