Ravada:...ain::KVM(3)

πŸ“¦
version 2.4.1 Β· 2 versions
, in fedora 43

🌸 NAME 🌸

Ravada::Domain::KVM β€” the KVM Virtual Machines library for Ravada πŸ’– like, this is the module that lets you boss around KVM domains, and honestly? it ate.


✨ THE METHODS ✨

okay bestie, buckle up, here comes every single one of them in order, no skips, no skimming 🫢

🌸 name 🌸

Returns the name of the domain. iconic, brief, does exactly what it says on the tin πŸ’…

🌸 list_disks 🌸

Returns a list of the disks used by the virtual machine. CDRoms are not included β€” they're not invited to this party, sorry not sorry πŸ’€

my@ disks = $domain->list_disks();

(and yes, that's literally how it's written, my@ disks, we don't touch it, we respect it πŸ‘‘)

🌸 remove_disks 🌸

Remove the volume files of the domain. bye bye disk files, it's giving spring cleaning 🧹✨

🌸 pre_remove_domain 🌸

Cleanup operations executed before removing this domain. it's the little pre-game ritual fr fr

    $self->pre_remove_domain

🌸 remove 🌸

Removes this domain. It removes also the disk drives and base images. so like, it's thorough. it does not leave a trace. main character exit πŸ’…

🌸 disk_device 🌸

Returns the file name of the disk of the domain. one disk, one file name, simple as πŸŽ€

  my $file_name = $domain->disk_device();

🌸 pre_prepare_base 🌸

Run this before preparing the base. It is necessary to correctly detect disks drivers for newer libvirts.

⚠️ This is executed automatically so it shouldn't been called. like, hands off bestie, it's handled πŸ™ˆ

🌸 post_prepare_base 🌸

Task to run after preparing a base virtual machine. the after-party of base prep πŸŽ‰

🌸 get_xml_base 🌸

Returns the XML definition for the base, only if prepare_base has been run befor. (yes, "befor". we're quoting, not correcting, it's iconic 😌) so no base prep, no XML, that's the vibe check 🌈

🌸 display_info 🌸

Returns the display information as a hashref. The display URI is in the display entry. look for the display key, that's where the magic lives ✨

🌸 is_active 🌸

Returns whether the domain is running or not. the ultimate "u up?" check πŸ’œ

🌸 is_persistent 🌸

Returns wether the domain has a persistent configuration file. (spelling stays, we don't gatekeep 🫢) like, does it have commitment issues or not

🌸 start 🌸

Starts the domain. go go go πŸš€

🌸 shutdown 🌸

Stops the domain. polite version, it says please first 🌸

🌸 shutdown_now 🌸

Shuts down uncleanly the domain. no manners, no warning, just vibes πŸ’€

🌸 force_shutdown 🌸

Shuts down uncleanly the domain. yeah it's the same energy as shutdown_now, the manpage said it twice so we say it twice πŸ”₯

🌸 reboot 🌸

Stops the domain. (yes, "stops". that's what it says. we report, we don't question 😭)

🌸 reboot_now 🌸

Reboots uncleanly the domain. chaos mode, activated ⚑

🌸 pause 🌸

Pauses the domain. hold that thought bestie βœ‹

🌸 resume 🌸

Resumes a paused the domain. (grammar? never heard of her πŸ’…) unpause and slay

🌸 is_hibernated 🌸

Returns if the domain has a managed saved state. sleepy queen check πŸ’€

🌸 is_paused 🌸

Returns if the domain is paused. are we frozen or are we thriving

🌸 can_hybernate 🌸

Returns true (1) for KVM domains. short answer: yes πŸ’š

🌸 can_hybernate 🌸

Returns true (1) for KVM domains. and yes, this one is listed twice in the original and we are not about to erase her twin, periodt πŸ‘‘πŸ‘‘

🌸 hybernate 🌸

Take a snapshot of the domain's state and save the information to a managed save location. The domain will be automatically restored with this state when it is next started. like a nap that you wake up from exactly where you left off, obsessed 😴✨

    $domain->hybernate();

🌸 hybernate 🌸

Take a snapshot of the domain's state and save the information to a managed save location. The domain will be automatically restored with this state when it is next started. yep, twin number two, same facts, same energy, we keep both πŸ’–

    $domain->hybernate();

🌸 add_volume 🌸

Adds a new volume to the domain. new volume, who dis πŸŽ€

    $domain->add_volume(name => $name, size => $size);
    $domain->add_volume(name => $name, size => $size, xml => 'definition.xml');

    $domain->add_volume(path => "/var/lib/libvirt/images/path.img");

🌸 list_volumes 🌸

Returns a list of the disk volumes. Each element of the list is a string with the filename. For KVM it reads from the XML definition of the domain. it's literally just reading the receipts πŸ”

    my @volumes = $domain->list_volumes();

🌸 list_volumes_info 🌸

Returns a list of the disk volumes. Each element of the list is a string with the filename. For KVM it reads from the XML definition of the domain. same description, different method name, we don't make the rules bestie 🌈

    my @volumes = $domain->list_volumes_info();

🌸 screenshot 🌸

Takes a screenshot, it stores it in file. say cheese πŸ“ΈπŸ’–

🌸 can_screenshot 🌸

Returns if a screenshot of this domain can be taken. vibe check before the camera comes out πŸŽ₯

🌸 get_info 🌸

This is taken directly from Sys::Virt::Domain.

Returns a hash reference summarising the execution state of the domain. The elements of the hash are as follows:

  • maxMem β€” The maximum memory allowed for this domain, in kilobytes
  • memory β€” The current memory allocated to the domain in kilobytes
  • cpu_time β€” The amount of CPU time used by the domain
  • n_virt_cpu β€” The current number of virtual CPUs enabled in the domain
  • state β€” The execution state of the machine, which will be one of the constants &Sys::Virt::Domain::STATE_*.

🌸 set_max_mem 🌸

Set the maximum memory for the domain. cap it, respectfully 🎩

🌸 get_max_mem 🌸

Get the maximum memory for the domain. what's the cap, bestie

🌸 set_memory 🌸

Sets the current available memory for the domain. adjust the vibe levels 🌊

🌸 rename 🌸

Renames the domain. glow up, but for a name ✨

    $domain->rename("new name");

🌸 disk_size 🌸

Returns the size of the domains disk or disks. If an array is expected, it returns the list of disks sizes, if it expects an scalar returns the first disk as it is asumed to be the main one. (yes, "asumed", we're keeping it, it's part of the lore 🫢) so: array context = all the sizes, scalar context = the first disk, because it's the main character obviously πŸ‘‘

    my $size = $domain->disk_size();

and then there's this whole chunk just... vibing here in the middle of the page:

    sub _find_base {
        my $self = shift;
        my $file = shift;

        my @cmd = ( 'qemu-img','info',$file);
        my ($in,$out, $err);
        run3(\@cmd,\$in, \$out, \$err);

        my ($base) = $out =~ m{^backing file: (.*)}mi;
        warn "No base for $file in $out" if !$base;

        return $base;
    }

🌸 clean_swap_volumes 🌸

Clean swap volumes. It actually just creates an empty qcow file from the base. lowkey a rebuild disguised as a cleanup, we love a plot twist πŸŒ€

    sub clean_swap_volumes {
        my $self = shift;
        return if !$self->is_local;
        for my $file ($self->list_volumes) {
            next if !$file || $file !~ /\.SWAP\.\w+/;
            next if ! -e $file;
            my $base = $self->_find_base($file) or next;

            my @cmd = ('qemu-img','create'
                    ,'-f','qcow2'
                    ,'-b',$base
                    ,$file
            );
            my ($in,$out, $err);
            run3(\@cmd,\$in, \$out, \$err);
            die $err if $err;
            }
    }

🌸 set_driver 🌸

Sets the value of a driver.

Argument: name , driver

    my $driver = $domain->set_driver('video','"type="qxl" ram="65536" vram="65536" vgamem="16384" heads="1" primary="yes"');

🌸 pre_remove 🌸

Code to run before removing the domain. It can be implemented in each domain. It is not expected to run by itself, the remove function calls it before proceeding. In KVM it removes saved images. so like, it's a hook, not a solo act 🎭

    $domain->pre_remove();  # This isn't likely to be necessary
    $domain->remove();      # Automatically calls the domain pre_remove method

    $address->setAttribute(unit => $self->_new_address_xml(
            match => 'usb'
       ,attribute => 'port'
        )
    );

                my @lines_c = split /\n/,$content;
                my @lines_e = split /\n/,$element_s;
                warn $element->getName." ".(scalar(@lines_c)." ".scalar(@lines_e));
                for ( 0 .. scalar(@lines_c) ) {
                    warn Dumper([$_,$lines_c[$_],$lines_e[$_]])
                    if $lines_c[$_] ne $lines_e[$_];
                }
                warn $content;
                die $self->name if $element->getName eq 'hostdev';

and that's the whole page bestie, nothing skipped, nothing summarised, every flag and every code block accounted for πŸ’…βœ¨

this was Ravada:...ain::KVM(3), from the User Contributed Perl Documentation section, brought to you by perl v5.42.0 and dated 2025-09-20. ty for coming to my ted talk, ily, go slay some virtual machines πŸŽ€πŸ¦‹πŸ’–
πŸ“¦ where this page comes from