Class: Api::V2::AnsibleRolesController

Inherits:
BaseController
  • Object
show all
Includes:
Api::Version2, ForemanAnsible::AnsibleRolesDataPreparations
Defined in:
app/controllers/api/v2/ansible_roles_controller.rb

Overview

API controller for Ansible Roles

Constant Summary

Constants included from ForemanAnsible::AnsibleRolesDataPreparations

ForemanAnsible::AnsibleRolesDataPreparations::ROLE_ACTION_NAMES, ForemanAnsible::AnsibleRolesDataPreparations::VARIABLE_ACTION_NAMES

Instance Method Summary collapse

Methods included from ForemanAnsible::AnsibleRolesDataPreparations

#excluded_roles, #get_old_roles_variables, #get_roles_variables, #prepare_ansible_import_rows, #prepare_api_row, #prepare_ui_row, #role_action_name, #role_match_excluded_roles, #variable_action_name, #variables_to_s

Instance Method Details

#destroyObject



32
33
34
# File 'app/controllers/api/v2/ansible_roles_controller.rb', line 32

def destroy
  process_response @ansible_role.destroy
end

#fetchObject



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

def fetch
  fetched =  prepare_ansible_import_rows(@roles_importer.import!, @variables_importer, false)
  respond_to do |format|
    format.json do
      render :json => { :results => { :ansible_roles => fetched } }
    end
  end
end

#importObject



39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/api/v2/ansible_roles_controller.rb', line 39

def import
  Foreman::Deprecation.api_deprecation_warning(_('Use sync instead, to sync roles from Smart Proxy with Ansible feature enabled'))
  new_roles = @roles_importer.import_role_names['new']
  if role_names.present?
    new_roles.select! do |role|
      role_names.include?(role.name)
    end
  end
  new_roles.map(&:save)
  @imported = new_roles
end

#indexObject



26
27
28
# File 'app/controllers/api/v2/ansible_roles_controller.rb', line 26

def index
  @ansible_roles = resource_scope_for_index
end

#obsoleteObject



65
66
67
68
# File 'app/controllers/api/v2/ansible_roles_controller.rb', line 65

def obsolete
  Foreman::Deprecation.api_deprecation_warning(_('Use sync instead, to sync roles from Smart Proxy with Ansible feature enabled'))
  @obsoleted = @importer.obsolete!
end

#showObject



21
# File 'app/controllers/api/v2/ansible_roles_controller.rb', line 21

def show; end

#syncObject



54
55
56
57
58
59
60
61
# File 'app/controllers/api/v2/ansible_roles_controller.rb', line 54

def sync
  params = @importer.import!(role_names)
  if params['changed'].present?
    @task = @importer.confirm_sync(params)
  else
    render_message _('No changes detected in specified Ansible Roles and their variables')
  end
end