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   pause
69       Pauses the domain
70
71   resume
72       Resumes a paused the domain
73
74   is_hibernated
75       Returns if the domain has a managed saved state.
76
77   is_paused
78       Returns if the domain is paused
79
80   can_hybernate
81       Returns true (1) for KVM domains
82
83   can_hybernate
84       Returns true (1) for KVM domains
85
86   hybernate
87       Take a snapshot of the domain's state and save the information to a
88       managed save location. The domain will be automatically restored with
89       this state when it is next started.
90
91           $domain->hybernate();
92
93   hybernate
94       Take a snapshot of the domain's state and save the information to a
95       managed save location. The domain will be automatically restored with
96       this state when it is next started.
97
98           $domain->hybernate();
99
100   add_volume
101       Adds a new volume to the domain
102
103           $domain->add_volume(name => $name, size => $size);
104           $domain->add_volume(name => $name, size => $size, xml => 'definition.xml');
105
106           $domain->add_volume(path => "/var/lib/libvirt/images/path.img");
107
108   list_volumes
109       Returns a list of the disk volumes. Each element of the list is a
110       string with the filename.  For KVM it reads from the XML definition of
111       the domain.
112
113           my @volumes = $domain->list_volumes();
114
115   list_volumes_info
116       Returns a list of the disk volumes. Each element of the list is a
117       string with the filename.  For KVM it reads from the XML definition of
118       the domain.
119
120           my @volumes = $domain->list_volumes_info();
121
122   screenshot
123       Takes a screenshot, it stores it in file.
124
125   can_screenshot
126       Returns if a screenshot of this domain can be taken.
127
128   storage_refresh
129       Refreshes the internal storage. Used after removing files such as base
130       images.
131
132   get_info
133       This is taken directly from Sys::Virt::Domain.
134
135       Returns a hash reference summarising the execution state of the domain.
136       The elements of the hash are as follows:
137
138       maxMem
139           The maximum memory allowed for this domain, in kilobytes
140
141       memory
142           The current memory allocated to the domain in kilobytes
143
144       cpu_time
145           The amount of CPU time used by the domain
146
147       n_virt_cpu
148           The current number of virtual CPUs enabled in the domain
149
150       state
151           The execution state of the machine, which will be one of the
152           constants &Sys::Virt::Domain::STATE_*.
153
154   set_max_mem
155       Set the maximum memory for the domain
156
157   get_max_mem
158       Get the maximum memory for the domain
159
160   set_memory
161       Sets the current available memory for the domain
162
163   rename
164       Renames the domain
165
166           $domain->rename("new name");
167
168   disk_size
169       Returns the size of the domains disk or disks If an array is expected,
170       it returns the list of disks sizes, if it expects an scalar returns the
171       first disk as it is asumed to be the main one.
172
173           my $size = $domain->disk_size();
174
175       sub _find_base {
176           my $self = shift;
177           my $file = shift;
178
179           my @cmd = ( 'qemu-img','info',$file);
180           my ($in,$out, $err);
181           run3(\@cmd,\$in, \$out, \$err);
182
183           my ($base) = $out =~ m{^backing file: (.*)}mi;
184           warn "No base for $file in $out" if !$base;
185
186           return $base;
187       }
188
189   clean_swap_volumes
190       Clean swap volumes. It actually just creates an empty qcow file from
191       the base
192
193       sub clean_swap_volumes {
194           my $self = shift;
195           return if !$self->is_local;
196           for my $file ($self->list_volumes) {
197               next if !$file || $file !~ /\.SWAP\.\w+/;
198               next if ! -e $file;
199               my $base = $self->_find_base($file) or next;
200
201               my @cmd = ('qemu-img','create'
202                       ,'-f','qcow2'
203                       ,'-b',$base
204                       ,$file
205               );
206               my ($in,$out, $err);
207               run3(\@cmd,\$in, \$out, \$err);
208               die $err if $err;
209               }
210       }
211
212   set_driver
213       Sets the value of a driver
214
215       Argument: name , driver
216
217           my $driver = $domain->set_driver('video','"type="qxl" ram="65536" vram="65536" vgamem="16384" heads="1" primary="yes"');
218
219   pre_remove
220       Code to run before removing the domain. It can be implemented in each
221       domain.  It is not expected to run by itself, the remove function calls
222       it before proceeding.  In KVM it removes saved images.
223
224           $domain->pre_remove();  # This isn't likely to be necessary
225           $domain->remove();      # Automatically calls the domain pre_remove method
226
227
228
229perl v5.32.1                      2021-05-24            Ravada::Domain::KVM(3)
Impressum