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   pre_prepare_base
34       Run this before preparing the base. It is necessary to correctly detect
35       disks drivers for newer libvirts.
36
37       This is executed automatically so it shouldn't been called.
38
39   post_prepare_base
40       Task to run after preparing a base virtual machine
41
42   get_xml_base
43       Returns the XML definition for the base, only if prepare_base has been
44       run befor
45
46   display_info
47       Returns the display information as a hashref. The display URI is in the
48       display entry
49
50   is_active
51       Returns whether the domain is running or not
52
53   is_persistent
54       Returns wether the domain has a persistent configuration file
55
56   start
57       Starts the domain
58
59   shutdown
60       Stops the domain
61
62   shutdown_now
63       Shuts down uncleanly the domain
64
65   force_shutdown
66       Shuts down uncleanly the domain
67
68   reboot
69       Stops the domain
70
71   reboot_now
72       Reboots uncleanly the domain
73
74   pause
75       Pauses the domain
76
77   resume
78       Resumes a paused the domain
79
80   is_hibernated
81       Returns if the domain has a managed saved state.
82
83   is_paused
84       Returns if the domain is paused
85
86   can_hybernate
87       Returns true (1) for KVM domains
88
89   can_hybernate
90       Returns true (1) for KVM domains
91
92   hybernate
93       Take a snapshot of the domain's state and save the information to a
94       managed save location. The domain will be automatically restored with
95       this state when it is next started.
96
97           $domain->hybernate();
98
99   hybernate
100       Take a snapshot of the domain's state and save the information to a
101       managed save location. The domain will be automatically restored with
102       this state when it is next started.
103
104           $domain->hybernate();
105
106   add_volume
107       Adds a new volume to the domain
108
109           $domain->add_volume(name => $name, size => $size);
110           $domain->add_volume(name => $name, size => $size, xml => 'definition.xml');
111
112           $domain->add_volume(path => "/var/lib/libvirt/images/path.img");
113
114   list_volumes
115       Returns a list of the disk volumes. Each element of the list is a
116       string with the filename.  For KVM it reads from the XML definition of
117       the domain.
118
119           my @volumes = $domain->list_volumes();
120
121   list_volumes_info
122       Returns a list of the disk volumes. Each element of the list is a
123       string with the filename.  For KVM it reads from the XML definition of
124       the domain.
125
126           my @volumes = $domain->list_volumes_info();
127
128   screenshot
129       Takes a screenshot, it stores it in file.
130
131   can_screenshot
132       Returns if a screenshot of this domain can be taken.
133
134   storage_refresh
135       Refreshes the internal storage. Used after removing files such as base
136       images.
137
138   get_info
139       This is taken directly from Sys::Virt::Domain.
140
141       Returns a hash reference summarising the execution state of the domain.
142       The elements of the hash are as follows:
143
144       maxMem
145           The maximum memory allowed for this domain, in kilobytes
146
147       memory
148           The current memory allocated to the domain in kilobytes
149
150       cpu_time
151           The amount of CPU time used by the domain
152
153       n_virt_cpu
154           The current number of virtual CPUs enabled in the domain
155
156       state
157           The execution state of the machine, which will be one of the
158           constants &Sys::Virt::Domain::STATE_*.
159
160   set_max_mem
161       Set the maximum memory for the domain
162
163   get_max_mem
164       Get the maximum memory for the domain
165
166   set_memory
167       Sets the current available memory for the domain
168
169   rename
170       Renames the domain
171
172           $domain->rename("new name");
173
174   disk_size
175       Returns the size of the domains disk or disks If an array is expected,
176       it returns the list of disks sizes, if it expects an scalar returns the
177       first disk as it is asumed to be the main one.
178
179           my $size = $domain->disk_size();
180
181       sub _find_base {
182           my $self = shift;
183           my $file = shift;
184
185           my @cmd = ( 'qemu-img','info',$file);
186           my ($in,$out, $err);
187           run3(\@cmd,\$in, \$out, \$err);
188
189           my ($base) = $out =~ m{^backing file: (.*)}mi;
190           warn "No base for $file in $out" if !$base;
191
192           return $base;
193       }
194
195   clean_swap_volumes
196       Clean swap volumes. It actually just creates an empty qcow file from
197       the base
198
199       sub clean_swap_volumes {
200           my $self = shift;
201           return if !$self->is_local;
202           for my $file ($self->list_volumes) {
203               next if !$file || $file !~ /\.SWAP\.\w+/;
204               next if ! -e $file;
205               my $base = $self->_find_base($file) or next;
206
207               my @cmd = ('qemu-img','create'
208                       ,'-f','qcow2'
209                       ,'-b',$base
210                       ,$file
211               );
212               my ($in,$out, $err);
213               run3(\@cmd,\$in, \$out, \$err);
214               die $err if $err;
215               }
216       }
217
218   set_driver
219       Sets the value of a driver
220
221       Argument: name , driver
222
223           my $driver = $domain->set_driver('video','"type="qxl" ram="65536" vram="65536" vgamem="16384" heads="1" primary="yes"');
224
225   pre_remove
226       Code to run before removing the domain. It can be implemented in each
227       domain.  It is not expected to run by itself, the remove function calls
228       it before proceeding.  In KVM it removes saved images.
229
230           $domain->pre_remove();  # This isn't likely to be necessary
231           $domain->remove();      # Automatically calls the domain pre_remove method
232
233           $address->setAttribute(unit => $self->_new_address_xml(
234                   match => 'usb'
235              ,attribute => 'port'
236               )
237           );
238
239
240
241perl v5.36.0                      2023-03-19            Ravada::Domain::KVM(3)
Impressum