From 653b575affed28a293680a9b860c82d98664bb8e Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Mon, 7 Mar 2016 17:02:20 +0100 Subject: add backing store for volumes --- libvirt/resource_libvirt_volume.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'libvirt/resource_libvirt_volume.go') diff --git a/libvirt/resource_libvirt_volume.go b/libvirt/resource_libvirt_volume.go index 7e7173ed..b37a2867 100644 --- a/libvirt/resource_libvirt_volume.go +++ b/libvirt/resource_libvirt_volume.go @@ -101,6 +101,20 @@ func resourceLibvirtVolumeCreate(d *schema.ResourceData, meta interface{}) error volumeDef.Capacity.Amount = d.Get("size").(int) } + if baseVolumeId, ok := d.GetOk("base_volume"); ok { + volumeDef.BackingStore = new(defBackingStore) + volumeDef.BackingStore.Format.Type = "qcow2" + baseVolume, err := virConn.LookupStorageVolByKey(baseVolumeId.(string)) + if err != nil { + return fmt.Errorf("Can't retrieve volume %s", baseVolumeId.(string)) + } + baseVolPath, err := baseVolume.GetPath() + if err != nil { + return fmt.Errorf("can't get name for base image '%s'", baseVolumeId) + } + volumeDef.BackingStore.Path = baseVolPath + } + volumeDefXml, err := xml.Marshal(volumeDef) if err != nil { return fmt.Errorf("Error serializing libvirt volume: %s", err) -- cgit v1.2.3