-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCreate.vm.py
More file actions
35 lines (27 loc) · 799 Bytes
/
Copy pathCreate.vm.py
File metadata and controls
35 lines (27 loc) · 799 Bytes
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
import libvirt
pool = "default"
conn = libvirt.open("qemu+ssh://username@hostname/system")
if not conn:
raise SystemExit("Failed to open connection to qemu:///system")
pool = conn.storagePoolLookupByName(pool)
if not pool:
raise SystemExit("Failed to locate any StoragePool objects.")
stgvol_xml = """
<volume>
<name>{}</name>
<allocation>{}</allocation>
<capacity unit="M">{}</capacity>
<target>
<path>/var/lib/libvirt/images/sparse.img</path>
<permissions>
<owner>107</owner>
<group>107</group>
<mode>0744</mode>
<label>virt_image_t</label>
</permissions>
</target>
</volume>""".format("hello","0","20")
stgvol = pool.createXML(stgvol_xml, 0)
if not stgvol:
raise SystemExit("Failed to create a StorageVol objects.")
conn.close()