Class: Api::V2::HostgroupsController

Inherits:
BaseController show all
Includes:
Api::Version2, Foreman::Controller::Parameters::Hostgroup, ParameterAttributes
Defined in:
app/controllers/api/v2/hostgroups_controller.rb

Instance Method Summary collapse

Methods included from ParameterAttributes

#process_parameter_attributes

Methods included from Api::Version2

#api_version

Methods inherited from BaseController

#append_array_of_ids, #check_media_type, #metadata_by, #metadata_order, #metadata_page, #metadata_per_page, #metadata_search, #metadata_subtotal, #metadata_total, #render_error, #root_node_name, #setup_has_many_params

Methods inherited from BaseController

#api_request?, #controller_permission, #get_resource, parameter_filter_context, #parent_scope, #resource_class_join, #resource_scope, #resource_scope_for_index

Methods included from Foreman::Controller::BruteforceProtection

#bruteforce_attempt?

Methods included from ApplicationShared

#current_permission, #find_default_taxonomy, #find_session_taxonomy, #scope_by_resource_id, #set_current_taxonomy, #set_current_user, #set_taxonomy, #store_default_taxonomy, #store_taxonomy

Methods included from FindCommon

#controller_permission, #find_resource, #resource_class, #resource_class_for, #resource_finder, #resource_name, #resource_scope, #scope_for

Methods included from Foreman::ThreadSession::Cleaner

#clear_thread

Methods included from Foreman::Controller::Timezone

#set_timezone

Methods included from Foreman::Controller::TopbarSweeper

#set_topbar_sweeper_controller

Methods included from Foreman::Controller::Session

#backup_session_content, #expire_session, #ignore_api_request?, #session_expiry, #set_activity_time, #update_activity_time

Methods included from Foreman::Controller::Authentication

#authenticate, #authorized, #available_sso, #check_user_enabled, #is_admin?, #path_to_authenticate, #require_login

Methods included from Foreman::Controller::MigrationChecker

needs_migration?

Instance Method Details

#cloneObject


103
104
105
106
# File 'app/controllers/api/v2/hostgroups_controller.rb', line 103

def clone
  @hostgroup = @hostgroup.clone(params[:name])
  process_response @hostgroup.save
end

#createObject


74
75
76
77
78
79
# File 'app/controllers/api/v2/hostgroups_controller.rb', line 74

def create
  @hostgroup = Hostgroup.new(hostgroup_params)
  @hostgroup.suggest_default_pxe_loader if params[:hostgroup] && params[:hostgroup][:pxe_loader].nil?

  process_response @hostgroup.save
end

#destroyObject


92
93
94
95
96
97
98
# File 'app/controllers/api/v2/hostgroups_controller.rb', line 92

def destroy
  if @hostgroup.has_children?
    render_message(_("Cannot delete group %{current} because it has nested host groups.") % { :current => @hostgroup.title }, :status => :conflict)
  else
    process_response @hostgroup.destroy
  end
end

#indexObject


23
24
25
26
27
28
29
# File 'app/controllers/api/v2/hostgroups_controller.rb', line 23

def index
  @hostgroups = resource_scope_for_index

  if params[:include].present?
    @parameters = params[:include].include?('parameters')
  end
end

#rebuild_configObject


112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'app/controllers/api/v2/hostgroups_controller.rb', line 112

def rebuild_config
  results = @hostgroup.recreate_hosts_config(params[:only], params[:children_hosts])
  failures = []
  results.each_pair do |host, result|
    host_failures = result.reject { |key, value| value }.keys.map { |k| _(k) }
    failures << "#{host}(#{host_failures.to_sentence})" unless host_failures.empty?
  end
  if failures.empty?
    render_message _("Configuration successfully rebuilt."), :status => :ok
  else
    render_error :custom_error, :status => :unprocessable_entity,
                 :locals => { :message => _("Configuration rebuild failed for: %s." % failures.to_sentence) }
  end
end

#showObject


35
36
# File 'app/controllers/api/v2/hostgroups_controller.rb', line 35

def show
end

#updateObject


85
86
87
# File 'app/controllers/api/v2/hostgroups_controller.rb', line 85

def update
  process_response @hostgroup.update(hostgroup_params)
end