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
81 Returns the display URI
82
83 is_active
84 Returns whether the domain is running or not
85
86 is_persistent
87 Returns wether the domain has a persistent configuration file
88
89 start
90 Starts the domain
91
92 shutdown
93 Stops the domain
94
95 shutdown_now
96 Shuts down uncleanly the domain
97
98 force_shutdown
99 Shuts down uncleanly the domain
100
101 pause
102 Pauses the domain
103
104 resume
105 Resumes a paused the domain
106
107 is_hibernated
108 Returns if the domain has a managed saved state.
109
110 is_paused
111 Returns if the domain is paused
112
113 can_hybernate
114 Returns true (1) for KVM domains
115
116 can_hybernate
117 Returns true (1) for KVM domains
118
119 hybernate
120 Take a snapshot of the domain's state and save the information to a
121 managed save location. The domain will be automatically restored with
122 this state when it is next started.
123
124 $domain->hybernate();
125
126 hybernate
127 Take a snapshot of the domain's state and save the information to a
128 managed save location. The domain will be automatically restored with
129 this state when it is next started.
130
131 $domain->hybernate();
132
133 add_volume
134 Adds a new volume to the domain
135
136 $domain->add_volume(name => $name, size => $size);
137 $domain->add_volume(name => $name, size => $size, xml => 'definition.xml');
138
139 $domain->add_volume(path => "/var/lib/libvirt/images/path.img");
140
141 list_volumes
142 Returns a list of the disk volumes. Each element of the list is a
143 string with the filename. For KVM it reads from the XML definition of
144 the domain.
145
146 my @volumes = $domain->list_volumes();
147
148 list_volumes_target
149 Returns a list of the disk volumes. Each element of the list is a
150 string with the filename. For KVM it reads from the XML definition of
151 the domain.
152
153 my @volumes = $domain->list_volumes_target();
154
155 screenshot
156 Takes a screenshot, it stores it in file.
157
158 can_screenshot
159 Returns if a screenshot of this domain can be taken.
160
161 storage_refresh
162 Refreshes the internal storage. Used after removing files such as base
163 images.
164
165 get_info
166 This is taken directly from Sys::Virt::Domain.
167
168 Returns a hash reference summarising the execution state of the domain.
169 The elements of the hash are as follows:
170
171 maxMem
172 The maximum memory allowed for this domain, in kilobytes
173
174 memory
175 The current memory allocated to the domain in kilobytes
176
177 cpu_time
178 The amount of CPU time used by the domain
179
180 n_virt_cpu
181 The current number of virtual CPUs enabled in the domain
182
183 state
184 The execution state of the machine, which will be one of the
185 constants &Sys::Virt::Domain::STATE_*.
186
187 set_max_mem
188 Set the maximum memory for the domain
189
190 get_max_mem
191 Get the maximum memory for the domain
192
193 set_memory
194 Sets the current available memory for the domain
195
196 rename
197 Renames the domain
198
199 $domain->rename("new name");
200
201 disk_size
202 Returns the size of the domains disk or disks If an array is expected,
203 it returns the list of disks sizes, if it expects an scalar returns the
204 first disk as it is asumed to be the main one.
205
206 my $size = $domain->disk_size();
207
208 sub rename_volumes {
209 my $self = shift;
210 my $new_dom_name = shift;
211
212 for my $disk ($self->_disk_devices_xml) {
213
214 my ($source) = $disk->findnodes('source');
215 next if !$source;
216
217 my $volume = $source->getAttribute('file') or next;
218
219 confess "ERROR: Domain ".$self->name
220 ." volume '$volume' does not exists"
221 if ! -e $volume;
222
223 $self->domain->create if !$self->is_active;
224 $self->domain->detach_device($disk);
225 $self->domain->shutdown;
226
227 my $cont = 0;
228 my $new_volume;
229 my $new_name = $new_dom_name;
230
231 for (;;) {
232 $new_volume=$volume;
233 $new_volume =~ s{(.*)/.*\.(.*)}{$1/$new_name.$2};
234 last if !-e $new_volume;
235 $cont++;
236 $new_name = "$new_dom_name.$cont";
237 }
238 warn "copy $volume -> $new_volume";
239 copy($volume, $new_volume) or die "$! $volume -> $new_volume";
240 $source->setAttribute(file => $new_volume);
241 unlink $volume or warn "$! removing $volume";
242 $self->storage->refresh();
243 $self->domain->attach_device($disk);
244 }
245 }
246
247 spinoff_volumes
248 Makes volumes indpendent from base
249
250 clean_swap_volumes
251 Clean swap volumes. It actually just creates an empty qcow file from
252 the base
253
254 set_driver
255 Sets the value of a driver
256
257 Argument: name , driver
258
259 my $driver = $domain->set_driver('video','"type="qxl" ram="65536" vram="65536" vgamem="16384" heads="1" primary="yes"');
260
261 pre_remove
262 Code to run before removing the domain. It can be implemented in each
263 domain. It is not expected to run by itself, the remove function calls
264 it before proceeding. In KVM it removes saved images.
265
266 $domain->pre_remove(); # This isn't likely to be necessary
267 $domain->remove(); # Automatically calls the domain pre_remove method
268
269
270
271perl v5.28.1 2019-04-12 Ravada::Domain::KVM(3)