Module: HammerCLIForemanAnsible::AssociatedAnsibleRole
- Included in:
- Host::AnsibleRolesCommand::AddAnsibleRoleCommand, Host::AnsibleRolesCommand::RemoveAnsibleRoleCommand, Hostgroup::AnsibleRolesCommand::AddAnsibleRoleCommand, Hostgroup::AnsibleRolesCommand::RemoveAnsibleRoleCommand
- Defined in:
- lib/hammer_cli_foreman_ansible/associated_ansible_role.rb
Instance Method Summary collapse
-
#get_current_ids ⇒ Object
This method fetches all associated resource (ansible roles) ids to send them back via :update endpoint of the main resource (host/hostgroup) We use this array of ids to add or remove direct associations This method is used to ‘reset’ associated ids via HammerCLIForeman::AssociatedCommand.
-
#get_new_ids ⇒ Object
Since there are no option_sources available to deal with such cases (AssociatedCommand) Make sure we get id of the provided role before we try to get already associated ones.
Instance Method Details
#get_current_ids ⇒ Object
This method fetches all associated resource (ansible roles) ids to send them back via :update endpoint of the main resource (host/hostgroup) We use this array of ids to add or remove direct associations This method is used to ‘reset’ associated ids via HammerCLIForeman::AssociatedCommand
7 8 9 10 11 12 |
# File 'lib/hammer_cli_foreman_ansible/associated_ansible_role.rb', line 7 def get_current_ids roles = HammerCLIForeman.record_to_common_format(resource.call(association_name(true), { id: get_identifier })) return ids_to_keep_for_removal(roles) if self.class.command_names.include?('remove') ids_to_keep_for_addition(roles) end |
#get_new_ids ⇒ Object
Since there are no option_sources available to deal with such cases (AssociatedCommand) Make sure we get id of the provided role before we try to get already associated ones
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/hammer_cli_foreman_ansible/associated_ansible_role.rb', line 16 def get_new_ids associated_identifiers = get_associated_identifiers @associated_identifier = get_associated_identifier ids = get_current_ids.map(&:to_s) required_ids = associated_identifiers.nil? ? [] : associated_identifiers.map(&:to_s) required_ids << @associated_identifier.to_s unless @associated_identifier.nil? ids = if self.class.command_names.include?('remove') ids.delete_if { |id| required_ids.include? id } else ids + required_ids end ids.uniq end |