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



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

def auto_complete_controller_name
  'foreman_chef_environments'
end

#createObject



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

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

#destroyObject



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

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

#editObject



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

def edit
end

#environments_for_chef_proxyObject



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

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
# 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?)
    process_success :success_redirect => foreman_chef_environments_path, :success_msg => _("Nothing to synchronize")
  end
end

#indexObject



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

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

#newObject



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

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

#synchronizeObject



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

def synchronize
  proxy = SmartProxy.authorized(:view_smart_proxies).find(params[:proxy])
  if (errors = ChefServerImporter.new(:chef_proxy => proxy).obsolete_and_new(params[:changed])).empty?
    process_success :success_redirect => foreman_chef_environments_path, :success_msg => _("Successfully updated environments")
  else
    process_error :redirect => foreman_chef_environments_path, :error_msg => _("Failed to update environments: %s") % errors.to_sentence
  end

end

#updateObject



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

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