Class: Moose::Inventory::Operations::AddHosts
- Inherits:
-
Object
- Object
- Moose::Inventory::Operations::AddHosts
- Includes:
- OperationEventSupport
- Defined in:
- lib/moose_inventory/operations/add_hosts.rb
Overview
Adds hosts and their optional group associations.
The operation mutates inventory state and returns structured events for the CLI adapter to render. Keeping output out of this class makes the inventory behavior easier to exercise without binding every domain test to progress text.
Constant Summary collapse
- AUTOMATIC_GROUP =
'ungrouped'
Instance Method Summary collapse
- #call(names:, groups:, dry_run: false) ⇒ Object
-
#initialize(context:) ⇒ AddHosts
constructor
A new instance of AddHosts.
Constructor Details
#initialize(context:) ⇒ AddHosts
Returns a new instance of AddHosts.
19 20 21 |
# File 'lib/moose_inventory/operations/add_hosts.rb', line 19 def initialize(context:) @context = context end |
Instance Method Details
#call(names:, groups:, dry_run: false) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/moose_inventory/operations/add_hosts.rb', line 23 def call(names:, groups:, dry_run: false) events = [] @dry_run = dry_run if dry_run names.each do |name| add_host(name, groups, events) end emit(events, :dry_run_summary) return operation_result(events: events) end context.transaction do names.each do |name| add_host(name, groups, events) end end operation_result(events: events) end |