mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 01:16:10 +00:00
refactor(vrtManager): a new VM's copy of a template is made by clone_volume
clone_from_template wrote its own copy XML next to wvmStorage.clone_volume, which the volume and VM clones use. clone_volume now takes the volume to copy, of its pool or another, so the template's copy goes through it too; it leaves metadata unallocated in a pool of no files, as the template copy did. A qcow2 template's copy in a file pool is now named <vm>.qcow2, like a new empty disk, not <vm>.img.
This commit is contained in:
parent
0d68888510
commit
dd258888d2
6 changed files with 19 additions and 36 deletions
|
|
@ -5,7 +5,7 @@ import string
|
|||
import pycdlib
|
||||
from vrtManager import util
|
||||
from vrtManager.connection import wvmConnect
|
||||
from vrtManager.storage import FILE_POOL_TYPES, rbd_source_children, wvmStorage
|
||||
from vrtManager.storage import rbd_source_children, wvmStorage
|
||||
|
||||
# libvirt's CPU modes a new VM can have; any other value is a CPU model's name (mode custom)
|
||||
CPU_MODES = ("host-model", "host-passthrough", "maximum")
|
||||
|
|
@ -62,35 +62,11 @@ class wvmCreate(wvmConnect):
|
|||
return vol.storagePoolLookupByVolume()
|
||||
|
||||
def clone_from_template(self, clone, template, storage=None, metadata=False, disk_owner_uid=0, disk_owner_gid=0):
|
||||
"""A copy of the template volume (its path) as the new VM's disk, in the pool storage or the template's; its path."""
|
||||
vol = self.get_volume_by_path(template)
|
||||
stg = self.get_storage(storage) if storage else vol.storagePoolLookupByVolume()
|
||||
|
||||
storage_type = util.get_xml_path(stg.XMLDesc(0), "/pool/@type")
|
||||
format = util.get_xml_path(vol.XMLDesc(0), "/volume/target/format/@type")
|
||||
if storage_type in FILE_POOL_TYPES:
|
||||
clone += ".img"
|
||||
else:
|
||||
metadata = False
|
||||
options = "<compat>1.1</compat><features><lazy_refcounts/></features>" if format == "qcow2" else ""
|
||||
xml = f"""
|
||||
<volume>
|
||||
<name>{clone}</name>
|
||||
<capacity>0</capacity>
|
||||
<allocation>0</allocation>
|
||||
<target>
|
||||
<format type='{format}'/>
|
||||
<permissions>
|
||||
<owner>{disk_owner_uid}</owner>
|
||||
<group>{disk_owner_gid}</group>
|
||||
<mode>0644</mode>
|
||||
<label>virt_image_t</label>
|
||||
</permissions>
|
||||
{options}
|
||||
</target>
|
||||
</volume>"""
|
||||
stg.createXMLFrom(xml, vol, metadata)
|
||||
clone_vol = stg.storageVolLookupByName(clone)
|
||||
return clone_vol.path()
|
||||
stg = wvmStorage(self.host, self.login, self.passwd, self.conn, storage or vol.storagePoolLookupByVolume().name())
|
||||
name = stg.clone_volume(vol, clone, metadata=metadata, disk_owner_uid=disk_owner_uid, disk_owner_gid=disk_owner_gid)
|
||||
return stg.get_volume(name).path()
|
||||
|
||||
def _defineXML(self, xml):
|
||||
self.wvm.defineXML(xml)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue