From 6486c201681a356874a3bf7f1e5fc102860166cd Mon Sep 17 00:00:00 2001 From: "Ing. Jan KRCMAR" Date: Tue, 4 Sep 2018 15:40:47 +0200 Subject: [PATCH] patch for cloning rbd images --- instances/templates/instance.html | 2 ++ vrtManager/instance.py | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/instances/templates/instance.html b/instances/templates/instance.html index f42c050..557c3dc 100644 --- a/instances/templates/instance.html +++ b/instances/templates/instance.html @@ -1279,6 +1279,8 @@ image = new_vname + "-" + disk_minus_suffix; } else if (disk_name.lastIndexOf('.') > -1 && disk_dot_suffix.length <= 7) { image = new_vname + "." + disk_dot_suffix + } else if (new_vname != disk_name) { + image = new_vname } else { image = new_vname + '-clone'; } diff --git a/vrtManager/instance.py b/vrtManager/instance.py index ae04b4a..b27baa0 100644 --- a/vrtManager/instance.py +++ b/vrtManager/instance.py @@ -245,7 +245,10 @@ class wvmInstance(wvmConnect): try: dev = disk.xpath('target/@dev')[0] src_fl = disk.xpath('source/@file|source/@dev|source/@name|source/@volume')[0] - disk_format = disk.xpath('driver/@type')[0] + try: + disk_format = disk.xpath('driver/@type')[0] + except: + pass try: vol = self.get_volume_by_path(src_fl) volume = vol.name() @@ -719,6 +722,28 @@ class wvmInstance(wvmConnect): stg = vol.storagePoolLookupByVolume() stg.createXMLFrom(vol_clone_xml, vol, meta_prealloc) + source_protocol = elm.get('protocol') + if source_protocol == 'rbd': + source_name = elm.get('name') + clone_name = "%s/%s" % (os.path.dirname(source_name), target_file) + elm.set('name', clone_name) + + vol = self.get_volume_by_path(source_name) + vol_format = util.get_xml_path(vol.XMLDesc(0), + "/volume/target/format/@type") + + vol_clone_xml = """ + + %s + 0 + 0 + + + + """ % (target_file, vol_format) + stg = vol.storagePoolLookupByVolume() + stg.createXMLFrom(vol_clone_xml, vol, meta_prealloc) + source_dev = elm.get('dev') if source_dev: clone_path = os.path.join(os.path.dirname(source_dev), target_file)