diff --git a/functions/fdisks.py b/functions/fdisks.py
index 0014525..95e32f3 100644
--- a/functions/fdisks.py
+++ b/functions/fdisks.py
@@ -51,17 +51,50 @@ def get_disks_info(vm_name):
return disks
def create_attached_disk(vm_name,disk_name,disk_size,disk_id):
- cmd = "qemu-img create -f qcow2 "+str(disk_path)+str(disk_name)+".qcow2 "+str(disk_size)+"G"
- subprocess.call(cmd, shell=True)
+ pool = conn.storagePoolLookupByName('disks')
+ disk_full = disk_path+disk_name+".qcow2"
+ xml_desc = f"""
+
+ {disk_name}.qcow2
+ {disk_size}
+ {disk_size}
+
+
+ {disk_full}
+
+
+ """
+ pool.createXML(xml_desc, 0)
+
dom = conn.lookupByName(vm_name)
if not dom.isActive():
dom.create()
disk_full = disk_path+disk_name+".qcow2"
- cmd = "virsh attach-disk --domain "+vm_name+" "+disk_full+" --target "+disk_id+" --persistent --config --live"
- subprocess.call(cmd, shell=True)
+ flags = (libvirt.VIR_DOMAIN_AFFECT_CONFIG |
+ libvirt.VIR_DOMAIN_AFFECT_LIVE |
+ libvirt.VIR_DOMAIN_AFFECT_CURRENT)
+ disk_xml = """
+
+
+
+
+
+ """.format(source=disk_full, target=disk_id)
+ dom.attachDeviceFlags(disk_xml, flags)
refresh_pool()
def resize_disk(disk_file,actual_size,new_size,vm_name,disk_id):
+ dom = conn.lookupByName(vm_name)
+ flags = (libvirt.VIR_DOMAIN_AFFECT_CONFIG |
+ libvirt.VIR_DOMAIN_AFFECT_LIVE |
+ libvirt.VIR_DOMAIN_AFFECT_CURRENT)
+ disk_xml = """
+
+
+
+
+
+ """.format(source=disk_file, target=disk_id)
cmd = "virsh detach-disk '"+vm_name+"' "+disk_file+" --persistent --config --live"
subprocess.call(cmd, shell=True)
if int(actual_size) < int(new_size):
@@ -70,8 +103,7 @@ def resize_disk(disk_file,actual_size,new_size,vm_name,disk_id):
else:
cmd = "qemu-img resize -f qcow2 --shrink "+str(disk_file)+" "+str(new_size)+"G"
subprocess.call(cmd, shell=True)
- cmd = "virsh attach-disk '"+str(vm_name)+"' "+str(disk_file)+" "+str(disk_id)+" --cache none --persistent --config --live"
- subprocess.call(cmd, shell=True)
+ dom.attachDeviceFlags(disk_xml, flags)
refresh_pool()
def detach_disk(vm_name,diskfile):
diff --git a/templates/edit.html b/templates/edit.html
index 48e45fe..e896f2b 100644
--- a/templates/edit.html
+++ b/templates/edit.html
@@ -47,6 +47,7 @@
Disk(s) of {{ vm_name }}
+ Actual disks
{% for disk in disks %}
@@ -60,6 +61,7 @@
{% endfor %}
+
Be aware that detached disks, still exist ! You should clean unused disks on Pool tab.
Shrinking a disk size, can corrupt or delete your data