Skip to content

Commit

Permalink
Merge pull request ManageIQ#19551 from agrare/remove_miq_vim_vm_from_…
Browse files Browse the repository at this point in the history
…snpashot

Don't require VMwareWebService/MiqVimVm in Snapshot
  • Loading branch information
Fryguy authored Nov 25, 2019
2 parents 052d9c8 + 5d7aa6b commit 27c2ebf
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 24 deletions.
19 changes: 2 additions & 17 deletions app/models/miq_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -616,8 +616,7 @@ def action_delete_snapshots_by_age(action, rec, _inputs)
age_threshold = (Time.now.utc - action.options[:age])
has_ch = false
snaps_to_delete = rec.snapshots.each_with_object([]) do |s, arr|
has_ch = true if s.is_a_type?(:consolidate_helper)
next if s.is_a_type?(:evm_snapshot) || s.is_a_type?(:vcb_snapshot)
next if s.is_a_type?(:evm_snapshot)

arr << s if s.create_time < age_threshold
end
Expand All @@ -627,11 +626,6 @@ def action_delete_snapshots_by_age(action, rec, _inputs)
return
end

if has_ch
MiqPolicy.logger.warn("#{log_prefix} has a Consolidate Helper snapshot, no shanpshots will be deleted")
return
end

task_id = "action_#{action.id}_vm_#{rec.id}"
snaps_to_delete.sort_by(&:create_time).reverse_each do |s| # Delete newest to oldest
MiqPolicy.logger.info("#{log_prefix} Deleting Snapshot: Name: [#{s.name}] Id: [#{s.id}] Create Time: [#{s.create_time}]")
Expand All @@ -650,11 +644,7 @@ def action_delete_most_recent_snapshot(action, rec, _inputs)
has_ch = false
snap = nil
rec.snapshots.order("create_time DESC").each do |s|
if s.is_a_type?(:consolidate_helper)
has_ch = true
next
end
next if s.is_a_type?(:evm_snapshot) || s.is_a_type?(:vcb_snapshot)
next if s.is_a_type?(:evm_snapshot)

snap ||= s # Take the first eligable snapshot
end
Expand All @@ -664,11 +654,6 @@ def action_delete_most_recent_snapshot(action, rec, _inputs)
return
end

if has_ch
MiqPolicy.logger.warn("#{log_prefix} has a Consolidate Helper snapshot, no shanpshot will be deleted")
return
end

MiqPolicy.logger.info("#{log_prefix} Deleting Snapshot: Name: [#{snap.name}] Id: [#{snap.id}] Create Time: [#{snap.create_time}]")
rec.remove_snapshot_queue(snap.id)
end
Expand Down
12 changes: 5 additions & 7 deletions app/models/snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class Snapshot < ApplicationRecord

after_create :after_create_callback

EVM_SNAPSHOT_NAME = "EvmSnapshot".freeze

def after_create_callback
MiqEvent.raise_evm_event_queue(vm_or_template, "vm_snapshot_complete", attributes) unless self.is_a_type?(:system_snapshot) || self.not_recently_created?
end
Expand Down Expand Up @@ -40,23 +42,19 @@ def get_current_snapshot

def self.find_all_evm_snapshots(zone = nil)
zone ||= MiqServer.my_server.zone
require 'VMwareWebService/MiqVimVm'
Snapshot.where(:vm_or_template_id => zone.vm_or_template_ids, :name => MiqVimVm::EVM_SNAPSHOT_NAME).includes(:vm_or_template).to_a
Snapshot.where(:vm_or_template_id => zone.vm_or_template_ids, :name => EVM_SNAPSHOT_NAME).includes(:vm_or_template).to_a
end

def is_a_type?(stype)
require 'VMwareWebService/MiqVimVm'
value = case stype.to_sym
when :evm_snapshot then MiqVimVm.const_get("EVM_SNAPSHOT_NAME")
when :consolidate_helper then MiqVimVm.const_get("CH_SNAPSHOT_NAME")
when :vcb_snapshot then MiqVimVm.const_get("VCB_SNAPSHOT_NAME")
when :evm_snapshot then EVM_SNAPSHOT_NAME
when :system_snapshot then :system_snapshot
else
raise "Unknown snapshot type '#{stype}' for #{self.class.name}.is_a_type?"
end

if value == :system_snapshot
return self.is_a_type?(:evm_snapshot) || self.is_a_type?(:consolidate_helper) || self.is_a_type?(:vcb_snapshot)
return self.is_a_type?(:evm_snapshot)
elsif value.kind_of?(Regexp)
return !!(value =~ name)
else
Expand Down

0 comments on commit 27c2ebf

Please sign in to comment.