Module: Foreman::Controller::Environments

Included in:
EnvironmentsController, PuppetclassesController
Defined in:
lib/foreman/controller/environments.rb

Overview

various methods which gets added to the puppetclasses and environments controllers

Instance Method Summary collapse

Instance Method Details

#import_environmentsObject


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/foreman/controller/environments.rb', line 5

def import_environments
  begin
    opts      = params[:proxy].blank? ? { } : { :url => SmartProxy.find(params[:proxy]).try(:url) }
    @importer = PuppetClassImporter.new(opts)
    @changed  = @importer.changes
  rescue => e
    if e.message =~ /puppet feature/i
      error "We did not find a foreman proxy that can provide the information, ensure that you have at least one Proxy with the puppet feature turned on."
      redirect_to :controller => controller_path and return
    else
      raise e
    end
  end

  if @changed["new"].size > 0 or @changed["obsolete"].size > 0 or @changed["updated"].size > 0
    render "common/_puppetclasses_or_envs_changed"
  else
    notice "No changes to your environments detected"
    redirect_to :controller => controller_path
  end
end

#obsolete_and_newObject


27
28
29
30
31
32
33
34
# File 'lib/foreman/controller/environments.rb', line 27

def obsolete_and_new
  if (errors = ::PuppetClassImporter.new.obsolete_and_new(params[:changed])).empty?
    notice "Successfully updated environments and puppetclasses from the on-disk puppet installation"
  else
    error "Failed to update the environments and puppetclasses from the on-disk puppet installation<br/>" + errors.join("<br>")
  end
  redirect_to :controller => controller_path
end