File: conn-test.py

package info (click to toggle)
libvirt-glib 5.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,592 kB
  • sloc: ansic: 21,146; xml: 591; sh: 471; python: 310; javascript: 30; makefile: 9
file content (50 lines) | stat: -rw-r--r-- 1,252 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3

import gi

gi.require_version('LibvirtGObject', '1.0')
from gi.repository import LibvirtGObject
from gi.repository import Gio
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk

LibvirtGObject.init_object_check(None)

conn = LibvirtGObject.Connection(uri="test:///default")
canc = Gio.Cancellable()

def done(conn, result, data):
    try:
        conn.open_finish(result)

        print("Opened " + conn.get_uri())

        conn.fetch_domains(None)
        print ("Fetched")
        doms = conn.get_domains()
        print ("Got " + str(doms))

        for d in doms:
            print ("One dom: " + str(d))
            print ("Name " + d.get_name())
            conf = d.get_config(0)
            print ("Conf " + str(conf))

            try:
                conf.validate()

                print ("Document is valid according to %s" % conf.get_schema())
            except Exception as e:
                print ("Document is not valid according to %s: %s: %s" % (conf.get_schema(), str(e), str(type(e))))

            xml = conf.to_xml()
            print ("XML " + xml)
            print ("Info " + str(d.get_info().memory))

    finally:
        Gtk.main_quit()


conn.open_async(canc, done, None)

Gtk.main()