line |
stmt |
code |
1
|
|
# Copyright 2018 SUSE LLC |
2
|
|
# SPDX-License-Identifier: GPL-2.0-or-later |
3
|
|
|
4
|
|
=head3 OpenQA::Qemu::SnapshotConf |
5
|
|
|
6
|
|
Modify and query our snapshot model. Note that adding or reverting to a |
7
|
|
snapshot here needs to be combined with calls to BlockDevConf and QEMU itself |
8
|
|
to actually perform the snapshot operations and keep the entire object model |
9
|
|
consistent. This is done by the Proc class. |
10
|
|
|
11
|
|
=cut |
12
|
|
|
13
|
|
use Mojo::Base 'OpenQA::Qemu::MutParams', -signatures; |
14
|
16
|
|
|
16
|
|
|
16
|
|
15
|
|
use OpenQA::Qemu::Snapshot; |
16
|
16
|
|
|
16
|
|
|
16
|
|
17
|
|
has _sequence => 0; |
18
|
|
has _head => sub ($self) { OpenQA::Qemu::Snapshot->new() }; |
19
|
|
|
20
|
|
$self->_sequence($self->_sequence + 1); |
21
|
88
|
my $new = OpenQA::Qemu::Snapshot->new() |
|
88
|
|
|
88
|
|
|
88
|
|
22
|
88
|
->sequence($self->_sequence) |
23
|
88
|
->name($name); |
24
|
|
|
25
|
|
$new->previous($self->_head); |
26
|
|
$self->_head($new); |
27
|
88
|
|
28
|
88
|
return $new; |
29
|
|
} |
30
|
88
|
|
31
|
|
my $snap = $self->_head; |
32
|
|
|
33
|
164
|
while (defined $snap && $snap->sequence != $nargs{sequence}) { |
|
164
|
|
|
164
|
|
|
164
|
|
34
|
164
|
$snap = $snap->previous; |
35
|
|
} |
36
|
164
|
|
37
|
840
|
die "Could not find snapshot with sequence $nargs{sequence}" |
38
|
|
unless defined $snap; |
39
|
|
|
40
|
164
|
return $snap; |
41
|
|
} |
42
|
|
|
43
|
164
|
my $snap = $self->_head; |
44
|
|
|
45
|
|
while (defined $snap && $snap->name ne $name) { |
46
|
6
|
$snap = $snap->previous; |
|
6
|
|
|
6
|
|
|
6
|
|
47
|
6
|
} |
48
|
|
|
49
|
6
|
die "Could not find snapshot '$name'" unless defined $snap; |
50
|
38
|
$self->_head($snap); |
51
|
|
|
52
|
|
return $snap; |
53
|
6
|
} |
54
|
6
|
|
55
|
|
|
56
|
6
|
my @snapshots = (); |
57
|
|
my $snap = $self->_head; |
58
|
|
|
59
|
37
|
while ($snap->sequence > -1) { |
|
37
|
|
|
37
|
|
|
37
|
|
60
|
|
push(@snapshots, $snap->_to_map()); |
61
|
14
|
$snap = $snap->previous; |
|
14
|
|
|
14
|
|
62
|
14
|
} |
63
|
14
|
|
64
|
|
@snapshots = reverse(@snapshots); |
65
|
14
|
return {snapshots => \@snapshots}; |
66
|
44
|
} |
67
|
44
|
|
68
|
|
for my $s (@{$map->{snapshots}}) { |
69
|
|
my $snap = $self->add_snapshot($s->{name}); |
70
|
14
|
die "Sequence mismatch while loading '$s->{name}' snapshot state: $s->{sequence} != " . $snap->sequence |
71
|
14
|
if $s->{sequence} != $snap->sequence; |
72
|
|
} |
73
|
|
|
74
|
10
|
return $self; |
|
10
|
|
|
10
|
|
|
10
|
|
75
|
10
|
} |
|
10
|
|
76
|
44
|
|
77
|
|
|
78
|
44
|
1; |