diff options
author | Silvio Moioli <smoioli@suse.de> | 2016-07-13 09:03:19 +0200 |
---|---|---|
committer | Silvio Moioli <smoioli@suse.de> | 2016-07-13 09:03:19 +0200 |
commit | fa7b60cbff6209175729988b66822d8775226c15 (patch) | |
tree | 2516e2995c475bc18d1afa540b5ea2330b5ccee0 /libvirt/resource_libvirt_volume.go | |
parent | 26fa9e6a5d7e75673bfef8705aa0b8c129cdb93d (diff) | |
download | terraform-provider-libvirt-fa7b60cbff6209175729988b66822d8775226c15.tar terraform-provider-libvirt-fa7b60cbff6209175729988b66822d8775226c15.tar.gz |
Refactor conditions go-style: errors first
Diffstat (limited to 'libvirt/resource_libvirt_volume.go')
-rw-r--r-- | libvirt/resource_libvirt_volume.go | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/libvirt/resource_libvirt_volume.go b/libvirt/resource_libvirt_volume.go index 375335bd..1e2de8a9 100644 --- a/libvirt/resource_libvirt_volume.go +++ b/libvirt/resource_libvirt_volume.go @@ -338,36 +338,36 @@ func resourceLibvirtVolumeRead(d *schema.ResourceData, meta interface{}) error { volume, err := virConn.LookupStorageVolByKey(d.Id()) if err != nil { 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) + if virErr.Code != libvirt.VIR_ERR_NO_STORAGE_VOL { + return fmt.Errorf("Can't retrieve volume %s", d.Id()) + } - 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() + log.Printf("[INFO] Volume %s not found, attempting to start its pool") - active, err := volPool.IsActive() - if err != nil { - return fmt.Errorf("Error retrieving status of pool %s for volume %s: %s", volPoolName, volId, err) - } - if active { - return fmt.Errorf("Can't retrieve volume %s", d.Id()) - } + volId := d.Id() + volPoolName := d.Get("pool").(string) + 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) - } + active, err := volPool.IsActive() + if err != nil { + return fmt.Errorf("Error retrieving status of pool %s for volume %s: %s", volPoolName, volId, err) + } + if active { + return fmt.Errorf("Can't retrieve volume %s", d.Id()) + } - // attempt a new lookup - volume, err = virConn.LookupStorageVolByKey(d.Id()) - if err != nil { - return fmt.Errorf("Can't retrieve volume %s", d.Id()) - } - } else { + 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()) } } |