-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprova_libvirt.py
76 lines (67 loc) · 1.95 KB
/
prova_libvirt.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
image_name = 'test.qcow2'
iso_path = '/home/antonio/SLE-15-Installer-DVD-x86_64-GM-DVD1.iso'
xml = """
<domain type='kvm'>
<name>demo</name>
<uuid>c7a5fdbd-cdaf-9455-926a-d65c16db1809</uuid>
<memory unit='KiB'>2097152</memory>
<vcpu>1</vcpu>
<os>
<type arch='x86_64' machine='pc'>hvm</type>
<boot dev='hd'/>
<boot dev='cdrom'/>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/qemu-kvm</emulator>
<disk type='file' device='disk'>
<source file='/var/lib/libvirt/images/{image_name}'/>
<driver name='qemu' type='qcow2'/>
<target dev='hda'/>
</disk>
<disk type='file' device='cdrom'>
<source file='{iso_path}'/>
<target dev='hdc' bus='ide'/>
</disk>
<interface type='network'>
<mac address='52:54:00:94:f0:a4'/>
<source network='default'/>
<model type='virtio'/>
<address type='pci' domain='0x0000' bus='0x00' slot='0x03' function='0x0'/>
</interface>
<input type='mouse' bus='ps2'/>
<graphics type='vnc' port='8888' listen='127.0.0.1'/>
</devices>
</domain>
""".format(image_name=image_name, iso_path=iso_path)
from mylibvirt.connection import Connection
from mylibvirt.installer import Installer
from mylibvirt.storage import Volume
url_hypervisor = 'qemu:///system'
c = Connection(url_hypervisor)
stgvol_xml = """
<volume>
<name>{image_name}</name>
<allocation>0</allocation>
<capacity unit="G">10</capacity>
<target>
<format type='qcow2'/>
<path>/var/lib/virt/images/{image_name}</path>
<permissions>
<owner>107</owner>
<group>107</group>
<mode>0744</mode>
<label>virt_image_t</label>
</permissions>
</target>
</volume>""".format(image_name=image_name)
v = Volume(c.conn, 'default')
v.list_volumes()
#new_volume = v.create_volume(stgvol_xml)
import pdb
pdb.set_trace()
i = Installer(c.conn)
i.install(xml)