1Ravada::Domain(3) User Contributed Perl Documentation Ravada::Domain(3)
2
3
4
6 Ravada::Domain - Domains ( Virtual Machines ) library for Ravada
7
8 pre_prepare_base
9 Run this before preparing the base. By default does nothing and may be
10 implemented in the object.
11
12 This is executed automatically so it shouldn't been called.
13
14 prepare_base
15 Prepares the virtual machine as a base:
16
17 · shuts it down
18
19 · creates read only volumes based on this base
20
21 · locks it so it won't get started
22
23 · stores the virtual machine template for the clones
24
25 post_prepare_base
26 Placeholder for optional method implemented in subclasses. This will
27 run after preparing the base files.
28
29 spinoff
30 Makes volumes indpendent from base
31
32 sub _check_disk_modified {
33 my $self = shift;
34
35 if ( !$self->is_base() ) {
36 return;
37 }
38
39 my $last_stat_base = 0;
40 for my $file_base ( $self->list_files_base ) {
41 my @stat_base = stat($file_base);
42 $last_stat_base = $stat_base[9] if$stat_base[9] > $last_stat_base;
43 # warn $last_stat_base;
44 }
45
46 my $files_updated = 0;
47 for my $file ( $self->disk_device ) {
48 my @stat = stat($file) or next;
49 $files_updated++ if $stat[9] > $last_stat_base;
50 # warn "\ncheck\t$file ".$stat[9]."\n vs \tfile_base $last_stat_base $files_updated\n";
51 }
52 die "Base already created and no disk images updated"
53 if !$files_updated;
54 }
55
56 id Returns the id of the domain my $id = $domain->id();
57 open
58 Open a domain
59
60 Argument: id Arguments: id => $id , [ readonly => {0|1} ]
61
62 Returns: Domain object
63
64 check_status
65 Checks if a virtual machine known status is in sync.
66
67 · Checks it is already started
68
69 · Performs shutdown cleaning procedures if down
70
71 is_known
72 Returns if the domain is known in Ravada.
73
74 is_known_extra
75 Returns if the domain has extra fields information known in Ravada.
76
77 start_time
78 Returns the last time (epoch format in seconds) the domain was started.
79
80 spice_password
81 Returns the password defined for the spice viewers
82
83 display_file
84 Returns a file with the display information. Defaults to spice.
85
86 display_file_tls
87 Returns a file with the display information in TLS connections.
88 Defaults to spice.
89
90 display
91 Returns the display information.
92
93 info
94 Return information about the domain.
95
96 pre_remove
97 Code to run before removing the domain. It can be implemented in each
98 domain. It is not expected to run by itself, the remove function calls
99 it before proceeding.
100
101 $domain->pre_remove(); # This isn't likely to be necessary
102 $domain->remove(); # Automatically calls the domain pre_remove method
103
104 restore
105 Returns the clone to an initial state.
106
107 Depending of the type of volumes added to the virtual machines all the
108 information stored there is removed. Only data volumes are kept
109 untouched.
110
111 · system : cleaned to the initial state
112
113 · tmp/swap : cleaned to the initial state
114
115 · data : nothing gets removed
116
117 is_base Returns true or false if the domain is a prepared base
118 is_locked Shows if the domain has running or pending requests. It could be
119 considered too as the domain is busy doing something like starting,
120 shutdown or prepare base. Returns true if locked.
121 id_owner Returns the id of the user that created this domain
122 id_base Returns the id from the base this domain is based on, if any.
123 vm Returns a string with the name of the VM ( Virtual Machine ) this domain
124 was created on
125 clones Returns a list of clones from this virtual machine my @clones =
126 $domain->clones
127 has_clones Returns the number of clones from this virtual machine my
128 $has_clones = $domain->has_clones
129 list_files_base Returns a list of the filenames of this base-type domain
130 list_files_base_target
131 Returns a list of the filenames and targets of this base-type domain
132
133 can_screenshot Returns wether this domain can take an screenshot.
134 remove_base Makes the domain a regular, non-base virtual machine and
135 removes the base files.
136 clone
137 Clones a domain
138
139 arguments
140
141 user => $user : The user that owns the clone
142 name => $name : Name of the new clone
143
144 can_hybernate
145 Returns wether a domain supports hybernation
146
147 can_hibernate
148 Returns wether a domain supports hibernation
149
150 add_volume_swap
151 Adds a swap volume to the virtual machine
152
153 Arguments:
154
155 size => $kb
156 name => $name (optional)
157
158 expose
159 Expose a TCP port from the domain
160
161 Arguments:
162 - number of the port
163 - optional name
164
165 Returns: public ip and port
166
167 exposed_port
168 Returns all the data from an exposed port.
169
170 Argument: number or name description of the port permission.
171
172 my $port_data = $domain->exposed_port(80);
173
174 my $port_data = $domain->exposed_port('web');
175
176 open_exposed_ports
177 Performs an iptables open of all the exposed ports of the domain
178
179 remove_expose
180 Remove exposed port
181
182 Argument: virtual machine exposed port [ optional ]
183
184 If no port is passed all the exposed ports are removed.
185
186 list_ports
187 List of exposed TCP ports
188
189 post_resume_aux
190 Method after resume
191
192 open_iptables
193 Open iptables for a remote client
194
195 user
196 remote_ip
197
198 is_public
199 Sets or get the domain public
200
201 $domain->is_public(1);
202
203 if ($domain->is_public()) {
204 ...
205 }
206
207 is_volatile
208 Returns if the domain is volatile, so it will be removed on shutdown
209
210 is_persistent
211 Returns true if the virtual machine is persistent. So it is not removed
212 after shut down.
213
214 run_timeout
215 Sets or get the domain run timeout. When it expires it is shut down.
216
217 $domain->run_timeout(60 * 60); # 60 minutes
218
219 clean_swap_volumes
220 Check if the domain has swap volumes defined, and clean them
221
222 $domain->clean_swap_volumes();
223
224 get_controller
225 Calls the method to get the specified controller info
226
227 Attributes:
228 name -> name of the controller type
229
230 get_controllers
231 Returns a hashref of the hardware controllers for this virtual machine
232
233 drivers
234 List the drivers available for a domain. It may filter for a given
235 type.
236
237 my @drivers = $domain->drivers();
238 my @video_drivers = $domain->drivers('video');
239
240 set_driver_id
241 Sets the driver of a domain given it id. The id must be one from the
242 table domain_drivers_options
243
244 $domain->set_driver_id($id_driver);
245
246 last_vm
247 Returns the last virtual machine manager on which this domain was
248 launched.
249
250 my $vm = $domain->last_vm();
251
252 list_requests
253 Returns a list of pending requests from the domain. It won't show those
254 requests scheduled for later.
255
256 list_all_requests
257 Returns a list of pending requests from the domain including those
258 scheduled for later
259
260 get_driver
261 Returns the driver from a domain
262
263 Argument: name of the device [ optional ] Returns all the drivers if
264 not passwed
265
266 my $driver = $domain->get_driver('video');
267
268 get_driver_id
269 Gets the value of a driver
270
271 Argument: name
272
273 my $driver = $domain->get_driver('video');
274
275 set_option
276 Sets a domain option:
277
278 · description
279
280 · run_timeout
281
282 $domain->set_option(description => 'Virtual Machine for ...');
283
284 type
285 Returns the virtual machine type as a string.
286
287 rsync
288 Synchronizes the volume data to a remote node.
289
290 Arguments: ( node => $node, request => $request, files => \@files )
291
292 · node => Ravada::VM
293
294 · request => Ravada::Request ( optional )
295
296 · files => listref of files ( optional )
297
298 When files is not specified it syncs the volumes and base volumes if
299 any
300
301 set_base_vm
302 Prepares or removes a base in a virtual manager.
303
304 $domain->set_base_vm(
305 id_vm => $id_vm # you can pass the id_vm
306 ,vm => $vm # or the vm
307 ,user => $user
308 ,value => $value # if it is 0, it removes the base
309 ,request => $req
310 );
311
312 migrate_base
313 Migrates a base to a virtual manager node.
314
315 Alias for set_base_vm.
316
317 remove_base_vm
318 Removes a base in a Virtual Machine Manager node.
319
320 $domain->remove_base_vm($vm, $user);
321
322 file_screenshot
323 Returns the file name where the domain screenshot has been stored
324
325 list_vms
326 Returns a list for virtual machine managers where this domain is base
327
328 base_in_vm
329 Returns if this domain has a base prepared in this virtual manager
330
331 if ($domain->base_in_vm($id_vm)) { ...
332
333 is_local
334 Returns wether this domain is in the local host
335
336 pools
337 Enables or disables pools of clones for this virtual machine
338
339 pool_clones
340 Number of clones of this virtual machine that belong to the pool
341
342 pool_start
343 Number of clones of this virtual machine that are pre-started
344
345 is_pool
346 Return if the virtual machine belongs to a pool of clones
347
348 internal_id
349 Returns the internal id of this domain as found in its Virtual Manager
350 connection
351
352 volatile_clones
353 Enables or disables a domain volatile clones feature. Volatile clones
354 are removed when shut down
355
356 status
357 Sets or gets the status of a virtual machine
358
359 $machine->status('active');
360
361 Valid values are:
362
363 · active
364
365 · down
366
367 · hibernated
368
369 client_status
370 Returns the status of the viewer connection. The virtual machine must
371 be active, and the remote ip must be known.
372
373 Possible results:
374
375 · connecting : set at the start of the virtual machine
376
377 · IP : known remote ip from the current connection
378
379 · disconnected : the remote client has been closed
380
381 This method is used from higher level commands, for example, you can
382 shut down or hibernate all the disconnected virtual machines like this:
383
384 # rvd_back --hibernate --disconnected
385 # rvd_back --shutdown --disconnected
386
387 You could also set this command on a cron entry to run nightly, hourly
388 or whenever you find suitable.
389
390 needs_restart
391 Returns true or false if the virtual machine needs to be restarted so
392 some hardware change can be applied.
393
394 Access restrictions
395 These methods implement access restrictions to clone a domain
396
397 allow_ldap_access
398 If specified, only the LDAP users with that attribute value can clone
399 these virtual machines.
400
401 $base->allow_ldap_attribute( attribute => 'value' );
402
403 Example:
404
405 $base->allow_ldap_attribute( tipology => 'student' );
406
407 default_access
408 Sets the default access value
409
410 grant_access
411 Grant access to a virtual machine
412
413 Arguments is a named list
414
415 · attribute
416
417 · value
418
419 · type
420
421 · allowed ( true / false ) defaults to true
422
423 · last : if this grant matches it stops looking
424
425 access_allowed
426 Returns if a client is granted access to a virtual machine
427
428 Arguments: expects a named vars list of client attributes retrieved
429 from the web connection.
430
431 list_access
432 Returns a list of access grants
433
434 Argument: optionally pass the type of grant.
435
436 delete_access
437 Deletes a list of access grants from the database
438
439 delete_ldap_access
440 Deletes a granted ldap access setting
441
442 Argument: id of the access from the table access_ldap_attribute
443
444 list_ldap_access
445 List granted ldap access settings
446
447 deny_ldap_access
448 If specified, only the LDAP users with that attribute value can clone
449 these virtual machines.
450
451 $base->deny_ldap_attribute( attribute => 'value' );
452
453 Example:
454
455 $base->deny_ldap_attribute( tipology => 'student' );
456
457 move_ldap_access
458 Moves an access access grant up or down
459
460 Arguments:
461
462 · id_ldap_access
463
464 · position: +1/-1
465
466 move_access
467 Moves an access access grant up or down
468
469 Arguments:
470
471 · id_access
472
473 · position: +1/-1
474
475 set_ldap_access
476 Changes access grant allowed and last states
477
478 Arguments:
479
480 · id_access
481
482 · allowed
483
484 · last
485
486 set_access
487 Changes access grant allowed and last states
488
489 · id_access
490
491 · allowed
492
493 · last
494
495 rebase
496 Rebases the virtual machine to another one
497
498 If it is a base it rebases all the clones.
499
500 list_instances
501 Returns a list of instances of the virtual machine in all the physical
502 nodes
503
504 has_non_shared_storage
505 Return wether this virtual machine has non shared storage volumes
506
508 Hey! The above document had some coding errors, which are explained
509 below:
510
511 Around line 812:
512 You forgot a '=back' before '=head2'
513
514 Around line 1963:
515 You forgot a '=back' before '=head2'
516
517 Around line 4785:
518 You forgot a '=back' before '=head2'
519
520
521
522perl v5.32.0 2020-12-26 Ravada::Domain(3)