Skip to content

Commit

Permalink
Merge pull request #17145 from agrare/bz_1428797_use_vm_ems_ref_for_r…
Browse files Browse the repository at this point in the history
…econnect_events

Use vm_ems_ref to reconnect events
  • Loading branch information
kbrock authored Mar 19, 2018
2 parents 9b589fb + 1cfd5eb commit 8246d91
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
9 changes: 8 additions & 1 deletion app/models/ems_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,13 @@ def manager_refresh_targets

private

def self.event_allowed_ems_ref_keys
%w(vm_ems_ref dest_vm_ems_ref)
end
private_class_method :event_allowed_ems_ref_keys

def self.create_event(event)
event.delete_if { |k,| k.to_s.ends_with?("_ems_ref") }
event.delete_if { |k,| k.to_s.ends_with?("_ems_ref") && !event_allowed_ems_ref_keys.include?(k.to_s) }

new_event = EmsEvent.create(event) unless EmsEvent.exists?(
:event_type => event[:event_type],
Expand Down Expand Up @@ -270,6 +275,7 @@ def self.create_completed_event(event, orig_task = nil)
:host_id => source_event.host_id,
:vm_name => source_event.vm_name,
:vm_location => source_event.vm_location,
:vm_ems_ref => source_event.vm_ems_ref,
:vm_or_template_id => source_event.vm_or_template_id
}
new_event[:username] = event.username unless event.username.blank?
Expand All @@ -284,6 +290,7 @@ def self.create_completed_event(event, orig_task = nil)
:dest_host_id => dest_event.host_id,
:dest_vm_name => dest_event.send("#{dest_key}vm_name"),
:dest_vm_location => dest_event.send("#{dest_key}vm_location"),
:dest_vm_ems_ref => dest_event.send("#{dest_key}vm_ems_ref"),
:dest_vm_or_template_id => dest_event.send("#{dest_key}vm_or_template_id")
)
end
Expand Down
6 changes: 3 additions & 3 deletions app/models/vm_or_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -823,19 +823,19 @@ def ems_host_list
end

def reconnect_events
events = EmsEvent.where("(vm_location = ? AND vm_or_template_id IS NULL) OR (dest_vm_location = ? AND dest_vm_or_template_id IS NULL)", path, path)
events = EmsEvent.where("ems_id = ? AND ((vm_ems_ref = ? AND vm_or_template_id IS NULL) OR (dest_vm_ems_ref = ? AND dest_vm_or_template_id IS NULL))", ext_management_system.id, ems_ref, ems_ref)
events.each do |e|
do_save = false

src_vm = e.src_vm_or_template
if src_vm.nil? && e.vm_location == path
if src_vm.nil? && e.vm_ems_ref == ems_ref
src_vm = self
e.vm_or_template_id = src_vm.id
do_save = true
end

dest_vm = e.dest_vm_or_template
if dest_vm.nil? && e.dest_vm_location == path
if dest_vm.nil? && e.dest_vm_ems_ref == ems_ref
dest_vm = self
e.dest_vm_or_template_id = dest_vm.id
do_save = true
Expand Down

0 comments on commit 8246d91

Please sign in to comment.