Debian Codegraph @

lib/Sys/Virt/DomainSnapshot.pm

raw
1 # -*- perl -*-
2 #
3 # Copyright (C) 2006 Red Hat
4 # Copyright (C) 2006-2007 Daniel P. Berrange
5 #
6 # This program is free software; You can redistribute it and/or modify
7 # it under either:
8 #
9 # a) the GNU General Public License as published by the Free
10 # Software Foundation; either version 2, or (at your option) any
11 # later version,
12 #
13 # or
14 #
15 # b) the "Artistic License"
16 #
17 # The file "LICENSE" distributed along with this file provides full
18 # details of the terms and conditions of the two licenses.
19
20 =pod
21
22 =head1 NAME
23
24 Sys::Virt::DomainSnapshot - Represent & manage a libvirt guest domain
25
26 =head1 DESCRIPTION
27
28 The C<Sys::Virt::DomainSnapshot> module represents a guest domain managed
29 by the virtual machine monitor.
30
31 =head1 METHODS
32
33 =over 4
34
35 =cut
36
37 package Sys::Virt::DomainSnapshot;
38
39 use strict;
40 use warnings;
41
42
43 sub _new {
44 my $proto = shift;
45 my $class = ref($proto) || $proto;
46 my %params = @_;
47
48 my $dom = exists $params{domain} ? $params{domain} : die "domain parameter is required";
49 my $self;
50 if (exists $params{name}) {
51 $self = Sys::Virt::DomainSnapshot::_lookup_by_name($dom, $params{name});
52 } elsif (exists $params{xml}) {
53 $self = Sys::Virt::DomainSnapshot::_create_xml($dom, $params{xml}, $params{flags} ? $params{flags} : 0);
54 } else {
55 die "name or xml parameters are required";
56 }
57
58 bless $self, $class;
59
60 return $self;
61 }
62
63 =item my $str = $domss->get_name()
64
65 Return the name of the snapshot
66
67 =item my $xml = $domss->get_xml_description($flags)
68
69 Returns an XML document containing a complete description of
70 the domain snapshot's configuration. The C<$flags> parameter
71 accepts the following constants
72
73 =over 4
74
75 =item Sys::Virt::DomainSnapshot::XML_SECURE
76
77 Include security sensitive information in the XML dump, such as
78 passwords.
79
80 =back
81
82 =item $domss->delete($flags)
83
84 Deletes this snapshot object & its data. The optional C<$flags> parameter controls
85 what should be deleted via the C<Sys::Virt::DomainSnapshot::DELETE_*>
86 constants.
87
88 =item $domss->revert_to($flags)
89
90 Revert the domain to the state associated with this snapshot. The optional
91 C<$flags> control the state of the VM after the revert via the
92 C<Sys::Virt::DomainSnapshot::REVERT_*> constants.
93
94 =item $parentss = $domss->get_parent();
95
96 Return the parent of the snapshot, if any
97
98 =item $res = $domss->is_current()
99
100 Returns a true value if this is the current snapshot. False otherwise.
101
102 =item $res = $domss->has_metadata()
103
104 Returns a true value if this snapshot has metadata associated with
105 it.
106
107 =item $count = $domss->num_of_child_snapshots()
108
109 Return the number of saved snapshots which are children of this snapshot
110
111 =item @names = $domss->list_child_snapshot_names()
112
113 List the names of all saved snapshots which are children of this
114 snapshot . The names can be used with the C<lookup_snapshot_by_name>
115
116 =item @snapshots = $domss->list_child_snapshots()
117
118 Return a list of all snapshots that are children of this snapshot. The elements
119 in the returned list are instances of the L<Sys::Virt::DomainSnapshot> class.
120 This method requires O(n) RPC calls, so the C<list_all_children> method is
121 recommended as a more efficient alternative.
122
123 =cut
124
125
126 sub list_child_snapshots {
127 my $self = shift;
128
129 my $nnames = $self->num_of_child_snapshots();
130 my @names = $self->list_child_snapshot_names($nnames);
131
132 my @snapshots;
133 foreach my $name (@names) {
134 eval {
135 push @snapshots, Sys::Virt::DomainSnapshot->_new(domain => $self, name => $name);
136 };
137 if ($@) {
138 # nada - snapshot went away before we could look it up
139 };
140 }
141 return @snapshots;
142 }
143
144 =item my @snapshots = $domss->list_all_children($flags)
145
146 Return a list of all domain snapshots that are children of this
147 snapshot. The elements in the returned list are instances of the
148 L<Sys::Virt::DomainSnapshot> class. The C<$flags> parameter can be
149 used to filter the list of return domain snapshots.
150
151 =back
152
153 =head1 CONSTANTS
154
155 =head2 SNAPSHOT CREATION
156
157 The following constants are useful when creating snapshots
158
159 =over 4
160
161 =item Sys::Virt::DomainSnapshot::CREATE_CURRENT
162
163 Set the defined snapshot to be the current snapshot
164
165 =item Sys::Virt::DomainSnapshot::CREATE_DISK_ONLY
166
167 Only snapshot the disk, not the memory state
168
169 =item Sys::Virt::DomainSnapshot::CREATE_HALT
170
171 Stop the guest after creating the snapshot
172
173 =item Sys::Virt::DomainSnapshot::CREATE_NO_METADATA
174
175 Do not save any metadata for the snapshot
176
177 =item Sys::Virt::DomainSnapshot::CREATE_REDEFINE
178
179 Replace/set the metadata with the snapshot
180
181 =item Sys::Virt::DomainSnapshot::CREATE_QUIESCE
182
183 Quiesce the guest disks while taking the snapshot
184
185 =item Sys::Virt::DomainSnapshot::CREATE_REUSE_EXT
186
187 Reuse the existing snapshot data files (if any)
188
189 =item Sys::Virt::DomainSnapshot::CREATE_ATOMIC
190
191 Create multiple disk snapshots atomically
192
193 =item Sys::Virt::DomainSnapshot::CREATE_LIVE
194
195 Create snapshot while the guest is running
196
197 =item Sys::Virt::DomainSnapshot::CREATE_VALIDATE
198
199 Validate the XML document against the schema
200
201 =back
202
203 =head2 SNAPSHOT DELETION
204
205 The following constants are useful when deleting snapshots
206
207 =over 4
208
209 =item Sys::Virt::DomainSnapshot::DELETE_CHILDREN
210
211 Recursively delete any child snapshots
212
213 =item Sys::Virt::DomainSnapshot::DELETE_CHILDREN_ONLY
214
215 Only delete the child snapshots
216
217 =item Sys::Virt::DomainSnapshot::DELETE_METADATA_ONLY
218
219 Only delete the snapshot metadata
220
221 =back
222
223 =head2 SNAPSHOT LIST
224
225 The following constants are useful when listing snapshots
226
227 =over 4
228
229 =item Sys::Virt::DomainSnapshot::LIST_METADATA
230
231 Only list snapshots which have metadata
232
233 =item Sys::Virt::DomainSnapshot::LIST_ROOTS
234
235 Only list snapshots which are root nodes in the tree
236
237 =item Sys::Virt::DomainSnapshot::LIST_DESCENDANTS
238
239 Only list snapshots which are descendants of the current
240 snapshot
241
242 =item Sys::Virt::DomainSnapshot::LIST_LEAVES
243
244 Only list leaf nodes in the snapshot tree
245
246 =item Sys::Virt::DomainSnapshot::LIST_NO_LEAVES
247
248 Only list non-leaf nodes in the snapshot tree
249
250 =item Sys::Virt::DomainSnapshot::LIST_NO_METADATA
251
252 Only list snapshots without metadata
253
254 =item Sys::Virt::DomainSnapshot::LIST_ACTIVE
255
256 Only list snapshots taken while the guest was running
257
258 =item Sys::Virt::DomainSnapshot::LIST_INACTIVE
259
260 Only list snapshots taken while the guest was inactive
261
262 =item Sys::Virt::DomainSnapshot::LIST_EXTERNAL
263
264 Only list snapshots stored in external disk images
265
266 =item Sys::Virt::DomainSnapshot::LIST_INTERNAL
267
268 Only list snapshots stored in internal disk images
269
270 =item Sys::Virt::DomainSnapshot::LIST_DISK_ONLY
271
272 Only list snapshots taken while the guest was running,
273 which did not include memory state.
274
275 =item Sys::Virt::DomainSnapshot::LIST_TOPOLOGICAL
276
277 Sort list in topological order wrt to parent/child
278 relationships.
279
280 =back
281
282
283 =head2 SNAPSHOT REVERT
284
285 The following constants are useful when reverting snapshots
286
287 =over 4
288
289 =item Sys::Virt::DomainSnapshot::REVERT_PAUSED
290
291 Leave the guest CPUs paused after reverting to the snapshot state
292
293 =item Sys::Virt::DomainSnapshot::REVERT_RUNNING
294
295 Start the guest CPUs after reverting to the snapshot state
296
297 =item Sys::Virt::DomainSnapshot::REVERT_FORCE
298
299 Force the snapshot to revert, even if it is risky to do so
300
301 =item Sys::Virt::DomainSnapshot::REVERT_RESET_NVRAM
302
303 Reset the firmware NVRAM state from its original template
304
305 =back
306
307 =over 4
308
309 =cut
310
311 1;
312
313 =back
314
315 =head1 AUTHORS
316
317 Daniel P. Berrange <[email protected]>
318
319 =head1 COPYRIGHT
320
321 Copyright (C) 2006 Red Hat
322 Copyright (C) 2006-2007 Daniel P. Berrange
323
324 =head1 LICENSE
325
326 This program is free software; you can redistribute it and/or modify
327 it under the terms of either the GNU General Public License as published
328 by the Free Software Foundation (either version 2 of the License, or at
329 your option any later version), or, the Artistic License, as specified
330 in the Perl README file.
331
332 =head1 SEE ALSO
333
334 L<Sys::Virt>, L<Sys::Virt::Error>, C<http://libvirt.org>
335
336 =cut