diff --git a/app/models/vm_or_template.rb b/app/models/vm_or_template.rb index 66731b7eb2f..a2d278cc99f 100644 --- a/app/models/vm_or_template.rb +++ b/app/models/vm_or_template.rb @@ -1855,6 +1855,14 @@ def check_feature_support(message_prefix) [true, nil] end + def create_notification(type, options) + Notification.create!( + :type => type, + :subject => self, + :options => options + ) + end + # this is verbose, helper for generating arel def self.arel_coalesce(values) Arel::Nodes::NamedFunction.new('COALESCE', values) diff --git a/app/models/vm_or_template/operations/snapshot.rb b/app/models/vm_or_template/operations/snapshot.rb index cbaf1c1ecf0..c9e78d02ac1 100644 --- a/app/models/vm_or_template/operations/snapshot.rb +++ b/app/models/vm_or_template/operations/snapshot.rb @@ -49,6 +49,9 @@ module VmOrTemplate::Operations::Snapshot def raw_create_snapshot(name, desc = nil, memory) run_command_via_parent(:vm_create_snapshot, :name => name, :desc => desc, :memory => memory) + rescue => err + create_notification(:vm_snapshot_failure, :error => err.to_s, :snapshot_op => "create") + raise MiqVmSnapshotError, err.to_s end def create_snapshot(name, desc = nil, memory = false) diff --git a/db/fixtures/notification_types.yml b/db/fixtures/notification_types.yml index 46394f4e759..ae0bf015842 100644 --- a/db/fixtures/notification_types.yml +++ b/db/fixtures/notification_types.yml @@ -149,3 +149,8 @@ :expires_in: 24.hours :level: :success :audience: global +- :name: vm_snapshot_failure + :message: 'Failed to %{snapshot_op} snapshot of %{subject}: %{error}' + :expires_in: 24.hours + :level: :warning + :audience: global