Class: Moose::Inventory::Operations::RemoveAssociations
- Inherits:
-
Object
- Object
- Moose::Inventory::Operations::RemoveAssociations
- Defined in:
- lib/moose_inventory/operations/remove_associations.rb
Overview
Removes host/group associations for existing primary entities.
Defined Under Namespace
Constant Summary collapse
- AUTOMATIC_GROUP =
'ungrouped'
Instance Method Summary collapse
- #group_from_hosts(group:, group_name:, host_names:) ⇒ Object
- #host_from_groups(host:, host_name:, group_names:) ⇒ Object
-
#initialize(context:) ⇒ RemoveAssociations
constructor
A new instance of RemoveAssociations.
Constructor Details
#initialize(context:) ⇒ RemoveAssociations
Returns a new instance of RemoveAssociations.
12 13 14 |
# File 'lib/moose_inventory/operations/remove_associations.rb', line 12 def initialize(context:) @context = context end |
Instance Method Details
#group_from_hosts(group:, group_name:, host_names:) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/moose_inventory/operations/remove_associations.rb', line 31 def group_from_hosts(group:, group_name:, host_names:) events = [] warning_count = 0 hosts_dataset = group.hosts_dataset host_names.each do |host_name| next if host_name.nil? || host_name.empty? warning_count += remove_host_from_group(group, group_name, host_name, hosts_dataset, events) end Result.new(events: events, warning_count: warning_count) end |
#host_from_groups(host:, host_name:, group_names:) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/moose_inventory/operations/remove_associations.rb', line 16 def host_from_groups(host:, host_name:, group_names:) events = [] warning_count = 0 group_names.each do |group_name| next if group_name.nil? || group_name.empty? warning_count += remove_group_from_host(host, host_name, group_name, events) end add_automatic_group_if_needed(host, host_name, events) Result.new(events: events, warning_count: warning_count) end |