diff --git a/app/models/miq_action.rb b/app/models/miq_action.rb index d06fa7e1ba0..17c7803df42 100644 --- a/app/models/miq_action.rb +++ b/app/models/miq_action.rb @@ -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 @@ -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}]") @@ -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 @@ -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 diff --git a/app/models/snapshot.rb b/app/models/snapshot.rb index 92e4bfbad07..17c85323715 100644 --- a/app/models/snapshot.rb +++ b/app/models/snapshot.rb @@ -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 @@ -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