Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use vm_ems_ref to reconnect events #17145

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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