summaryrefslogtreecommitdiff
path: root/libvirt/resource_libvirt_volume.go
diff options
context:
space:
mode:
Diffstat (limited to 'libvirt/resource_libvirt_volume.go')
-rw-r--r--libvirt/resource_libvirt_volume.go26
1 files changed, 25 insertions, 1 deletions
diff --git a/libvirt/resource_libvirt_volume.go b/libvirt/resource_libvirt_volume.go
index e125e75e..3979db1d 100644
--- a/libvirt/resource_libvirt_volume.go
+++ b/libvirt/resource_libvirt_volume.go
@@ -337,7 +337,31 @@ func resourceLibvirtVolumeRead(d *schema.ResourceData, meta interface{}) error {
volume, err := virConn.LookupStorageVolByKey(d.Id())
if err != nil {
- return fmt.Errorf("Can't retrieve volume %s", d.Id())
+ virErr := err.(libvirt.VirError)
+ if virErr.Code == libvirt.VIR_ERR_NO_STORAGE_VOL {
+ volId := d.Id()
+ volPoolName := d.Get("pool").(string)
+ log.Printf("[INFO] Volume %s not found, attempting to start pool %s", volId, volPoolName)
+
+ volPool, err := virConn.LookupStoragePoolByName(volPoolName)
+ if err != nil {
+ return fmt.Errorf("Error retrieving pool %s for volume %s: %s", volPoolName, volId, err)
+ }
+ defer volPool.Free()
+
+ err = volPool.Create(0)
+ if err != nil {
+ return fmt.Errorf("Error starting pool %s: %s", volPoolName, err)
+ }
+
+ // attempt a new lookup
+ volume, err = virConn.LookupStorageVolByKey(d.Id())
+ if err != nil {
+ return fmt.Errorf("Can't retrieve volume %s", d.Id())
+ }
+ } else {
+ return fmt.Errorf("Can't retrieve volume %s", d.Id())
+ }
}
defer volume.Free()