Skip to content

Commit

Permalink
changing disk data source to use name for serch instead of ID
Browse files Browse the repository at this point in the history
  • Loading branch information
Maigard committed Jan 28, 2018
1 parent cc3ebfb commit dc743d4
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions ovirt/data_source_disk.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ovirt

import (
"fmt"
"strconv"

"github.com/EMSL-MSC/ovirtapi"
Expand Down Expand Up @@ -41,19 +42,23 @@ func dataSourceDisk() *schema.Resource {

func dataSourceDiskRead(d *schema.ResourceData, meta interface{}) error {
con := meta.(*ovirtapi.Connection)
disk, err := con.GetDisk(d.Id())
disks, err := con.GetAllDisks()
if err != nil {
d.SetId("")
return nil
return err
}
for _, disk := range disks {
if disk.Name == d.Get("name") {
d.Set("size", disk.ProvisionedSize)
d.Set("format", disk.Format)
d.Set("storage_domain_id", disk.StorageDomains.StorageDomain[0].ID)
shareable, _ := strconv.ParseBool(disk.Shareable)
d.Set("shareable", shareable)
sparse, _ := strconv.ParseBool(disk.Sparse)
d.Set("sparse", sparse)
return nil
}
}

d.Set("name", disk.Name)
d.Set("size", disk.ProvisionedSize)
d.Set("format", disk.Format)
d.Set("storage_domain_id", disk.StorageDomains.StorageDomain[0].ID)
shareable, _ := strconv.ParseBool(disk.Shareable)
d.Set("shareable", shareable)
sparse, _ := strconv.ParseBool(disk.Sparse)
d.Set("sparse", sparse)
return nil
return fmt.Errorf("Disk %s not found", d.Get("name"))
}

0 comments on commit dc743d4

Please sign in to comment.