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   post_prepare_base
74       Task to run after preparing a base virtual machine
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   spinoff_volumes
210       Makes volumes indpendent from base
211
212       sub _find_base {
213           my $self = shift;
214           my $file = shift;
215
216           my @cmd = ( 'qemu-img','info',$file);
217           my ($in,$out, $err);
218           run3(\@cmd,\$in, \$out, \$err);
219
220           my ($base) = $out =~ m{^backing file: (.*)}mi;
221           warn "No base for $file in $out" if !$base;
222
223           return $base;
224       }
225
226   clean_swap_volumes
227       Clean swap volumes. It actually just creates an empty qcow file from
228       the base
229
230       sub clean_swap_volumes {
231           my $self = shift;
232           return if !$self->is_local;
233           for my $file ($self->list_volumes) {
234               next if !$file || $file !~ /\.SWAP\.\w+/;
235               next if ! -e $file;
236               my $base = $self->_find_base($file) or next;
237
238               my @cmd = ('qemu-img','create'
239                       ,'-f','qcow2'
240                       ,'-b',$base
241                       ,$file
242               );
243               my ($in,$out, $err);
244               run3(\@cmd,\$in, \$out, \$err);
245               die $err if $err;
246               }
247       }
248
249   set_driver
250       Sets the value of a driver
251
252       Argument: name , driver
253
254           my $driver = $domain->set_driver('video','"type="qxl" ram="65536" vram="65536" vgamem="16384" heads="1" primary="yes"');
255
256   pre_remove
257       Code to run before removing the domain. It can be implemented in each
258       domain.  It is not expected to run by itself, the remove function calls
259       it before proceeding.  In KVM it removes saved images.
260
261           $domain->pre_remove();  # This isn't likely to be necessary
262           $domain->remove();      # Automatically calls the domain pre_remove method
263

POD ERRORS

265       Hey! The above document had some coding errors, which are explained
266       below:
267
268       Around line 1541:
269           =cut found outside a pod block.  Skipping to next block.
270
271
272
273perl v5.30.1                      2020-02-21            Ravada::Domain::KVM(3)
Impressum