Skip to content

Commit

Permalink
adding disk data source
Browse files Browse the repository at this point in the history
  • Loading branch information
Maigard committed Jan 2, 2018
1 parent 4c2312a commit 37b0ea3
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
59 changes: 59 additions & 0 deletions ovirt/data_source_disk.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package ovirt

import (
"strconv"

"github.com/EMSL-MSC/ovirtapi"
"github.com/hashicorp/terraform/helper/schema"
)

func dataSourceDisk() *schema.Resource {
return &schema.Resource{
Read: dataSourceDiskRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},
"format": {
Type: schema.TypeString,
Optional: true,
},
"storage_domain_id": {
Type: schema.TypeString,
Optional: true,
},
"size": {
Type: schema.TypeInt,
Optional: true,
},
"shareable": {
Type: schema.TypeBool,
Optional: true,
},
"sparse": {
Type: schema.TypeBool,
Optional: true,
},
},
}
}

func dataSourceDiskRead(d *schema.ResourceData, meta interface{}) error {
con := meta.(*ovirtapi.Connection)
disk, err := con.GetDisk(d.Id())
if err != nil {
d.SetId("")
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
}
3 changes: 3 additions & 0 deletions ovirt/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ func Provider() terraform.ResourceProvider {
"ovirt_vm": resourceVM(),
"ovirt_disk": resourceDisk(),
},
DataSourcesMap: map[string]*schema.Resource{
"ovirt_disk": dataSourceDisk(),
},
}
}

Expand Down

0 comments on commit 37b0ea3

Please sign in to comment.