forked from ManageIQ/manageiq
-
Notifications
You must be signed in to change notification settings - Fork 1
/
snapshot.rb
160 lines (137 loc) · 5.01 KB
/
snapshot.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
module VmOrTemplate::Operations::Snapshot
extend ActiveSupport::Concern
included do
supports :snapshot_create do
if supports_snapshots?
unless supports_control?
unsupported_reason_add(:snapshot_create, unsupported_reason(:control))
end
else
unsupported_reason_add(:snapshot_create, _("Operation not supported"))
end
end
supports :remove_snapshot do
if supports_snapshots?
if snapshots.size <= 0
unsupported_reason_add(:remove_snapshot, _("No snapshots available for this VM"))
end
unless supports_control?
unsupported_reason_add(:remove_snapshot, unsupported_reason(:control))
end
else
unsupported_reason_add(:remove_snapshot, _("Operation not supported"))
end
end
supports :remove_all_snapshots do
unless supports_remove_snapshot?
unsupported_reason_add(:remove_all_snapshots, unsupported_reason(:remove_snapshot))
end
end
supports :remove_snapshot_by_description do
unless supports_remove_snapshot?
unsupported_reason_add(:remove_snapshot_by_description, unsupported_reason(:remove_snapshot))
end
end
supports :revert_to_snapshot do
unless supports_remove_snapshot?
unsupported_reason_add(:revert_to_snapshot, unsupported_reason(:remove_snapshot))
end
end
end
def raw_create_snapshot(name, desc = nil, memory)
raise NotImplementedError, _("must be implemented in a subclass")
end
def create_snapshot_queue(name, desc = nil, memory)
run_command_via_queue("raw_create_snapshot", :args => [name, desc, memory])
end
def create_snapshot(name, desc = nil, memory = false)
check_policy_prevent(:request_vm_create_snapshot, :create_snapshot_queue, name, desc, memory)
end
def raw_remove_snapshot(snapshot_id)
raise NotImplementedError, _("must be implemented in a subclass")
end
#
# For some types of VMs, the process for removing
# evm stapshots is very different from that of
# removing normal snapshots.
#
# Here, we differentiate between the two, so the
# methods can be overridden by the subclass as needed.
#
def remove_snapshot(snapshot_id)
raw_remove_snapshot(snapshot_id)
end
def remove_evm_snapshot(snapshot_id)
raw_remove_snapshot(snapshot_id)
end
def remove_snapshot_queue(snapshot_id, task_id = nil)
MiqQueue.put_unless_exists(
:class_name => self.class.name,
:instance_id => id,
:method_name => 'remove_snapshot',
:args => [snapshot_id],
:role => "ems_operations",
:zone => my_zone,
:task_id => task_id
)
end
def remove_evm_snapshot_queue(snapshot_id, task_id = nil)
MiqQueue.put_unless_exists(
:class_name => self.class.name,
:instance_id => id,
:method_name => 'remove_evm_snapshot',
:args => [snapshot_id],
:role => "ems_operations",
:zone => my_zone,
:task_id => task_id
)
end
def raw_remove_snapshot_by_description(description, refresh = false)
raise NotImplementedError, _("must be implemented in a subclass")
end
def remove_snapshot_by_description(description, refresh = false, retry_time = nil)
if (ext_management_system.kind_of?(ManageIQ::Providers::Vmware::InfraManager) && ManageIQ::Providers::Vmware::InfraManager.use_vim_broker? && MiqVimBrokerWorker.available?) || host.nil? || host.state == "on"
raw_remove_snapshot_by_description(description, refresh)
else
if retry_time.nil?
raise _("The VM's Host system is unavailable to remove the snapshot. VM id:[%{id}] Snapshot description:[%{description}]") %
{:id => id, :descrption => description}
end
# If the host is off re-queue the action based on the retry_time
MiqQueue.put(:class_name => self.class.name,
:instance_id => id,
:method_name => 'remove_snapshot_by_description',
:args => [description, refresh, retry_time],
:deliver_on => Time.now.utc + retry_time,
:role => "smartstate",
:zone => my_zone)
end
end
def raw_remove_all_snapshots
raise NotImplementedError, _("must be implemented in a subclass")
end
def remove_all_snapshots
raw_remove_all_snapshots
end
def remove_all_snapshots_queue(userid)
task_opts = {
:name => "Removing all snapshots for #{name}",
:userid => userid
}
queue_opts = {
:class_name => self.class.name,
:method_name => 'remove_all_snapshots',
:instance_id => id,
:role => 'ems_operations',
:zone => ext_management_system.my_zone,
:args => []
}
MiqTask.generic_action_with_callback(task_opts, queue_opts)
end
def raw_revert_to_snapshot(snapshot_id)
raise NotImplementedError, _("must be implemented in a subclass")
end
def revert_to_snapshot(snapshot_id)
raw_revert_to_snapshot(snapshot_id)
end
end