forked from ManageIQ/manageiq-providers-openstack
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add class for parsing refresh targets from EmsEvents
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
app/models/manageiq/providers/openstack/cloud_manager/event_target_parser.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
class ManageIQ::Providers::Openstack::CloudManager::EventTargetParser | ||
attr_reader :ems_event | ||
|
||
# @param ems_event [EmsEvent] EmsEvent object to be parsed to derive an object to be refreshed | ||
def initialize(ems_event) | ||
@ems_event = ems_event | ||
end | ||
|
||
# Parses all targets present in the EmsEvent givin in the initializer | ||
# @return [Array] Array of ManagerRefresh::Target objects | ||
def parse | ||
parse_ems_event_targets(ems_event) | ||
end | ||
|
||
private | ||
|
||
# Parses list of ManagerRefresh::Target(s) out of the given EmsEvent | ||
# | ||
# @param ems_event [EmsEvent] EmsEvent object | ||
# @return [Array] Array of ManagerRefresh::Target objects | ||
def parse_ems_event_targets(ems_event) | ||
target_collection = ManagerRefresh::TargetCollection.new(:manager => ems_event.ext_management_system, :event => ems_event) | ||
if ems_event.event_type.start_with?("compute.instance") | ||
collect_compute_instance_references!(target_collection, ems_event) | ||
end | ||
|
||
target_collection.targets | ||
end | ||
|
||
def parsed_targets(target_collection = {}) | ||
target_collection.select { |_target_class, references| references[:manager_ref].present? } | ||
end | ||
|
||
def add_target(target_collection, association, ref) | ||
target_collection.add_target(:association => association, :manager_ref => {:ems_ref => ref}) | ||
end | ||
|
||
def collect_compute_instance_references!(target_collection, ems_event) | ||
instance_id = ems_event.full_data.fetch_path(:payload, 'instance_id') | ||
add_target(target_collection, :vms, instance_id) if instance_id | ||
end | ||
end |