Class: ForemanChef::EnvironmentsController

Inherits:
ApplicationController show all
Includes:
Foreman::Controller::AutoCompleteSearch, Concerns::EnvironmentParameters
Defined in:
app/controllers/foreman_chef/environments_controller.rb

Instance Method Summary collapse

Methods included from Concerns::EnvironmentParameters

#environment_params

Methods inherited from ApplicationController

#resource_class

Instance Method Details

#auto_complete_controller_nameObject



66
67
68
# File 'app/controllers/foreman_chef/environments_controller.rb', line 66

def auto_complete_controller_name
  'foreman_chef_environments'
end

#createObject



38
39
40
41
42
43
44
45
# File 'app/controllers/foreman_chef/environments_controller.rb', line 38

def create
  @environment = ForemanChef::Environment.new(environment_params)
  if @environment.save
    process_success
  else
    process_error
  end
end

#destroyObject



58
59
60
61
62
63
64
# File 'app/controllers/foreman_chef/environments_controller.rb', line 58

def destroy
  if @environment.destroy
    process_success
  else
    process_error
  end
end

#editObject



47
48
# File 'app/controllers/foreman_chef/environments_controller.rb', line 47

def edit
end

#environments_for_chef_proxyObject



70
71
72
73
74
75
# File 'app/controllers/foreman_chef/environments_controller.rb', line 70

def environments_for_chef_proxy
  @chef_proxy = SmartProxy.authorized(:view_smart_proxies).with_features('Chef').find_by_id(params[:chef_proxy_id])
  @environments = @chef_proxy.present? ? @chef_proxy.chef_environments : []
  @type = params[:type]
  render :layout => false
end

#importObject



8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/foreman_chef/environments_controller.rb', line 8

def import
  proxy = SmartProxy.authorized(:view_smart_proxies).find(params[:proxy])
  opts = params[:proxy].blank? ? {} : { :url => proxy.url, :chef_proxy => proxy }
  opts[:env] = params[:env] unless params[:env].blank?
  @importer = ChefServerImporter.new(opts)
  @changed = @importer.changes
  if @changed.values.all?(&:empty?)
    notice _("Nothing to synchronize")
    redirect_to foreman_chef_environments_path
  end
end

#indexObject



30
31
32
# File 'app/controllers/foreman_chef/environments_controller.rb', line 30

def index
  @environments = resource_base.includes(:chef_proxy).search_for(params[:search], :order => params[:order]).paginate(:page => params[:page])
end

#newObject



34
35
36
# File 'app/controllers/foreman_chef/environments_controller.rb', line 34

def new
  @environment = ForemanChef::Environment.new
end

#synchronizeObject



20
21
22
23
24
25
26
27
28
# File 'app/controllers/foreman_chef/environments_controller.rb', line 20

def synchronize
  proxy = SmartProxy.authorized(:view_smart_proxies).find(params[:proxy])
  if (errors = ChefServerImporter.new(:chef_proxy => proxy).obsolete_and_new(params[:changed])).empty?
    notice _("Successfully updated environments")
  else
    error _("Failed to update environments: %s") % errors.to_sentence
  end
  redirect_to foreman_chef_environments_path
end

#updateObject



50
51
52
53
54
55
56
# File 'app/controllers/foreman_chef/environments_controller.rb', line 50

def update
  if @environment.update_attributes(environment_params)
    process_success
  else
    process_error
  end
end