aboutsummaryrefslogtreecommitdiff
path: root/libvirt
diff options
context:
space:
mode:
authorSilvio Moioli <smoioli@suse.de>2016-07-12 16:14:09 +0200
committerSilvio Moioli <smoioli@suse.de>2016-07-12 16:15:21 +0200
commit3dc63b446a3598062bb349e0227d8756000f9bdd (patch)
tree300abfad007707bbd76cc8b8731557c46a7a66a7 /libvirt
parent80172117bcff270c7c066ad0819231423fa26848 (diff)
downloadterraform-provider-libvirt-3dc63b446a3598062bb349e0227d8756000f9bdd.tar
terraform-provider-libvirt-3dc63b446a3598062bb349e0227d8756000f9bdd.tar.gz
Start storage pool if volume was not found
Diffstat (limited to 'libvirt')
-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()