1Ravada::Domain::KVM(3)User Contributed Perl DocumentationRavada::Domain::KVM(3)
2
3
4
5 NAME
6 Ravada::Domain::KVM - KVM Virtual Machines library for Ravada
7
8 name
9 Returns the name of the domain
10
11 list_disks
12 Returns a list of the disks used by the virtual machine. CDRoms are not
13 included
14
15 my@ disks = $domain->list_disks();
16
17 remove_disks
18 Remove the volume files of the domain
19
20 pre_remove_domain
21 Cleanup operations executed before removing this domain
22
23 $self->pre_remove_domain
24
25 remove
26 Removes this domain. It removes also the disk drives and base images.
27
28 disk_device
29 Returns the file name of the disk of the domain.
30
31 my $file_name = $domain->disk_device();
32
33 sub _create_swap_base {
34 my $self = shift;
35
36 my @swap_img;
37
38 my $base_name = $self->name;
39 for my $base_img ( $self->list_volumes()) {
40
41 next unless $base_img =~ 'SWAP';
42
43 confess "ERROR: missing $base_img"
44 if !-e $base_img;
45 my $swap_img = $base_img;
46
47 $swap_img =~ s{\.\w+$}{\.ro.img};
48
49 push @swap_img,($swap_img);
50
51 my @cmd = ('qemu-img','convert',
52 '-O','raw', $base_img
53 ,$swap_img
54 );
55
56 my ($in, $out, $err);
57 run3(\@cmd,\$in,\$out,\$err);
58 warn $out if $out;
59 warn $err if $err;
60
61 if (! -e $swap_img) {
62 warn "ERROR: Output file $swap_img not created at ".join(" ",@cmd)."\n";
63 exit;
64 }
65
66 chmod 0555,$swap_img;
67 $self->_prepare_base_db($swap_img);
68 }
69 return @swap_img;
70
71 }
72
73 prepare_base
74 Prepares a base virtual machine with this domain disk
75
76 get_xml_base
77 Returns the XML definition for the base, only if prepare_base has been
78 run befor
79
80 display_info
81 Returns the display information as a hashref. The display URI is in the
82 display entry
83
84 is_active
85 Returns whether the domain is running or not
86
87 is_persistent
88 Returns wether the domain has a persistent configuration file
89
90 start
91 Starts the domain
92
93 shutdown
94 Stops the domain
95
96 shutdown_now
97 Shuts down uncleanly the domain
98
99 force_shutdown
100 Shuts down uncleanly the domain
101
102 pause
103 Pauses the domain
104
105 resume
106 Resumes a paused the domain
107
108 is_hibernated
109 Returns if the domain has a managed saved state.
110
111 is_paused
112 Returns if the domain is paused
113
114 can_hybernate
115 Returns true (1) for KVM domains
116
117 can_hybernate
118 Returns true (1) for KVM domains
119
120 hybernate
121 Take a snapshot of the domain's state and save the information to a
122 managed save location. The domain will be automatically restored with
123 this state when it is next started.
124
125 $domain->hybernate();
126
127 hybernate
128 Take a snapshot of the domain's state and save the information to a
129 managed save location. The domain will be automatically restored with
130 this state when it is next started.
131
132 $domain->hybernate();
133
134 add_volume
135 Adds a new volume to the domain
136
137 $domain->add_volume(name => $name, size => $size);
138 $domain->add_volume(name => $name, size => $size, xml => 'definition.xml');
139
140 $domain->add_volume(path => "/var/lib/libvirt/images/path.img");
141
142 list_volumes
143 Returns a list of the disk volumes. Each element of the list is a
144 string with the filename. For KVM it reads from the XML definition of
145 the domain.
146
147 my @volumes = $domain->list_volumes();
148
149 list_volumes_info
150 Returns a list of the disk volumes. Each element of the list is a
151 string with the filename. For KVM it reads from the XML definition of
152 the domain.
153
154 my @volumes = $domain->list_volumes_info();
155
156 screenshot
157 Takes a screenshot, it stores it in file.
158
159 can_screenshot
160 Returns if a screenshot of this domain can be taken.
161
162 storage_refresh
163 Refreshes the internal storage. Used after removing files such as base
164 images.
165
166 get_info
167 This is taken directly from Sys::Virt::Domain.
168
169 Returns a hash reference summarising the execution state of the domain.
170 The elements of the hash are as follows:
171
172 maxMem
173 The maximum memory allowed for this domain, in kilobytes
174
175 memory
176 The current memory allocated to the domain in kilobytes
177
178 cpu_time
179 The amount of CPU time used by the domain
180
181 n_virt_cpu
182 The current number of virtual CPUs enabled in the domain
183
184 state
185 The execution state of the machine, which will be one of the
186 constants &Sys::Virt::Domain::STATE_*.
187
188 set_max_mem
189 Set the maximum memory for the domain
190
191 get_max_mem
192 Get the maximum memory for the domain
193
194 set_memory
195 Sets the current available memory for the domain
196
197 rename
198 Renames the domain
199
200 $domain->rename("new name");
201
202 disk_size
203 Returns the size of the domains disk or disks If an array is expected,
204 it returns the list of disks sizes, if it expects an scalar returns the
205 first disk as it is asumed to be the main one.
206
207 my $size = $domain->disk_size();
208
209 sub rename_volumes {
210 my $self = shift;
211 my $new_dom_name = shift;
212
213 for my $disk ($self->_disk_devices_xml) {
214
215 my ($source) = $disk->findnodes('source');
216 next if !$source;
217
218 my $volume = $source->getAttribute('file') or next;
219
220 confess "ERROR: Domain ".$self->name
221 ." volume '$volume' does not exists"
222 if ! -e $volume;
223
224 $self->domain->create if !$self->is_active;
225 $self->domain->detach_device($disk);
226 $self->domain->shutdown;
227
228 my $cont = 0;
229 my $new_volume;
230 my $new_name = $new_dom_name;
231
232 for (;;) {
233 $new_volume=$volume;
234 $new_volume =~ s{(.*)/.*\.(.*)}{$1/$new_name.$2};
235 last if !-e $new_volume;
236 $cont++;
237 $new_name = "$new_dom_name.$cont";
238 }
239 warn "copy $volume -> $new_volume";
240 copy($volume, $new_volume) or die "$! $volume -> $new_volume";
241 $source->setAttribute(file => $new_volume);
242 unlink $volume or warn "$! removing $volume";
243 $self->storage->refresh();
244 $self->domain->attach_device($disk);
245 }
246 }
247
248 spinoff_volumes
249 Makes volumes indpendent from base
250
251 clean_swap_volumes
252 Clean swap volumes. It actually just creates an empty qcow file from
253 the base
254
255 set_driver
256 Sets the value of a driver
257
258 Argument: name , driver
259
260 my $driver = $domain->set_driver('video','"type="qxl" ram="65536" vram="65536" vgamem="16384" heads="1" primary="yes"');
261
262 pre_remove
263 Code to run before removing the domain. It can be implemented in each
264 domain. It is not expected to run by itself, the remove function calls
265 it before proceeding. In KVM it removes saved images.
266
267 $domain->pre_remove(); # This isn't likely to be necessary
268 $domain->remove(); # Automatically calls the domain pre_remove method
269
270
271
272perl v5.30.0 2019-08-08 Ravada::Domain::KVM(3)