File: libvirtvms.py

package info (click to toggle)
bumblebee-status 2.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,844 kB
  • sloc: python: 13,430; sh: 68; makefile: 29
file content (32 lines) | stat: -rw-r--r-- 817 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
"""Displays count of running libvirt VMs.

Required the following python packages:
        * libvirt

contributed by `maxpivo <https://github.com/maxpivo>`_ - many thanks!
"""

import sys
import libvirt

import core.module
import core.widget
import core.input
import core.decorators


class Module(core.module.Module):
    @core.decorators.every(seconds=10)
    def __init__(self, config, theme):
        super().__init__(config, theme, core.widget.Widget(self.status))

        core.input.register(self, button=core.input.LEFT_MOUSE, cmd="virt-manager")

    def status(self, _):
        conn = libvirt.openReadOnly(None)
        if conn == None:
            return "Failed to open connection to the hypervisor"
        return "VMs %s" % (conn.numOfDomains())


# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4