File: demo.py

package info (click to toggle)
libvirt-sandbox 0.5.1%2Bgit20160404-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 3,104 kB
  • ctags: 1,964
  • sloc: ansic: 12,696; python: 2,110; makefile: 447; sh: 302; xml: 151; perl: 110
file content (55 lines) | stat: -rwxr-xr-x 1,148 bytes parent folder | download
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
51
52
53
54
55
#!/usr/bin/python

from gi.repository import LibvirtGObject
from gi.repository import LibvirtSandbox
from gi.repository import GLib
from gi.repository import Gtk

LibvirtGObject.init_object_check(None)

config = LibvirtSandbox.Config.new("sandbox")
config.set_tty(True)
net = LibvirtSandbox.ConfigNetwork().new()
net.set_dhcp(True)
config.add_network(net)
config.set_command(["/sbin/httpd", "-some", "-arg"])

# Assuming '/tmp/privatestuff' contains a fake /etc for the
# guest

tmp = LibvirtSandbox.ConfigMount.new("/tmp")
# This is a host path
tmp.set_root("/tmp/privatestuff")
config.add_host_mount(tmp)

etc = LibvirtSandbox.ConfigMount.new("/etc")
# This is a guest path
etc.set_root("/tmp/etc")
config.add_bind_mount(etc)


#conn=LibvirtGObject.Connection.new("qemu:///session")
conn=LibvirtGObject.Connection.new("lxc:///")
conn.open(None)

context = LibvirtSandbox.Context.new(conn, config)
context.start()

def closed(obj, error):
    Gtk.main_quit()


console = context.get_console()
console.connect("closed", closed)
console.attach_stdio()

Gtk.main()

try:
    console.detach()
except:
    pass
try:
    context.stop()
except:
    pass