Module: ForemanPuppet::Extensions::ApiSmartProxiesController

Extended by:
ActiveSupport::Concern, Apipie::DSL::Concern
Defined in:
app/controllers/concerns/foreman_puppet/extensions/api_smart_proxies_controller.rb

Defined Under Namespace

Classes: NewEnvironment

Instance Method Summary collapse

Instance Method Details

#import_puppetclassesObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/controllers/concerns/foreman_puppet/extensions/api_smart_proxies_controller.rb', line 27

def import_puppetclasses
  return unless changed_environments
  # @changed is returned from the method above changed_environments
  # Limit actions by setting @changed[kind] to empty hash {} (no action)
  # if :except parameter is passed with comma deliminator import_puppetclasses?except=new,obsolete
  if params[:except].present?
    kinds = params[:except].split(',')
    kinds.each do |kind|
      @changed[kind] = {} if PuppetClassImporter::CHANGE_KINDS.include?(kind)
    end
  end

  # DRYRUN - /import_puppetclasses?dryrun - do not run PuppetClassImporter
  rabl_template = @environment ? 'show' : 'index'
  if params.key?('dryrun') && ['false', false].exclude?(params['dryrun'])
    render("foreman_puppet/api/v#{api_version}/import_puppetclasses/#{rabl_template}", layout: 'api/layouts/import_puppetclasses_layout')
    return
  end

  # RUN PuppetClassImporter
  if (errors = PuppetClassImporter.new.obsolete_and_new(@changed)).empty?
    render("foreman_puppet/api/v#{api_version}/import_puppetclasses/#{rabl_template}", layout: 'api/layouts/import_puppetclasses_layout')
  else
    render json: {
      message: _('Failed to update the environments and Puppet classes from the on-disk puppet installation: %s') % errors.join(', '),
    }, status: :internal_server_error
  end
end