Class: Moose::Inventory::Operations::AddAssociations
- Inherits:
-
Object
- Object
- Moose::Inventory::Operations::AddAssociations
- Includes:
- OperationEventSupport
- Defined in:
- lib/moose_inventory/operations/add_associations.rb
Overview
Adds host/group associations for existing primary entities.
Constant Summary collapse
- AUTOMATIC_GROUP =
'ungrouped'
Instance Method Summary collapse
- #group_to_hosts(group:, group_name:, host_names:, dry_run: false) ⇒ Object
- #host_to_groups(host:, host_name:, group_names:, dry_run: false) ⇒ Object
-
#initialize(context:) ⇒ AddAssociations
constructor
A new instance of AddAssociations.
Constructor Details
#initialize(context:) ⇒ AddAssociations
Returns a new instance of AddAssociations.
13 14 15 |
# File 'lib/moose_inventory/operations/add_associations.rb', line 13 def initialize(context:) @context = context end |
Instance Method Details
#group_to_hosts(group:, group_name:, host_names:, dry_run: false) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/moose_inventory/operations/add_associations.rb', line 34 def group_to_hosts(group:, group_name:, host_names:, dry_run: false) events = [] warning_count = 0 @dry_run = dry_run hosts_dataset = group.hosts_dataset host_names.each do |host_name| next if host_name.nil? || host_name.empty? warning_count += add_host_to_group( group, group_name, host_name, hosts_dataset, events ) end emit(events, :dry_run_summary) if dry_run operation_result(events: events, warning_count: warning_count) end |
#host_to_groups(host:, host_name:, group_names:, dry_run: false) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/moose_inventory/operations/add_associations.rb', line 17 def host_to_groups(host:, host_name:, group_names:, dry_run: false) events = [] warning_count = 0 @dry_run = dry_run group_names.each do |group_name| next if group_name.nil? || group_name.empty? warning_count += add_group_to_host(host, host_name, group_name, events) end remove_automatic_group_from_host(host, host_name, events) emit(events, :dry_run_summary) if dry_run operation_result(events: events, warning_count: warning_count) end |