Skip to content

Commit

Permalink
Turn volume ids to a list of plain strings
Browse files Browse the repository at this point in the history
See dmacvicar#79 for discussion.
  • Loading branch information
moio committed Oct 27, 2016
1 parent 2bb34a0 commit 1fbe94b
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions libvirt/resource_libvirt_domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ func resourceLibvirtDomain() *schema.Resource {
Optional: true,
ForceNew: false,
},
"disk": &schema.Schema{
"volume_ids": &schema.Schema{
Type: schema.TypeList,
Optional: true,
Required: false,
ForceNew: true,
Elem: &schema.Resource{
Schema: diskCommonSchema(),
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
"network_interface": &schema.Schema{
Expand Down Expand Up @@ -148,14 +148,14 @@ func resourceLibvirtDomainCreate(d *schema.ResourceData, meta interface{}) error
domainDef.Memory.Amount = d.Get("memory").(int)
domainDef.VCpu.Amount = d.Get("vcpu").(int)

disksCount := d.Get("disk.#").(int)
disksCount := d.Get("volume_ids.#").(int)
var disks []defDisk
for i := 0; i < disksCount; i++ {
prefix := fmt.Sprintf("disk.%d", i)
disk := newDefDisk()
disk.Target.Dev = fmt.Sprintf("vd%s", DiskLetterForIndex(i))

volumeKey := d.Get(prefix + ".volume_id").(string)
prefix := fmt.Sprintf("volume_ids.%d", i)
volumeKey := d.Get(prefix).(string)
diskVolume, err := virConn.LookupStorageVolByKey(volumeKey)
if err != nil {
return fmt.Errorf("Can't retrieve volume %s", volumeKey)
Expand Down Expand Up @@ -542,7 +542,7 @@ func resourceLibvirtDomainRead(d *schema.ResourceData, meta interface{}) error {
}
d.Set("running", running)

disks := make([]map[string]interface{}, 0)
disks := make([]string, 0)
for _, diskDef := range domainDef.Devices.Disks {
virPool, err := virConn.LookupStoragePoolByName(diskDef.Source.Pool)
if err != nil {
Expand All @@ -561,12 +561,9 @@ func resourceLibvirtDomainRead(d *schema.ResourceData, meta interface{}) error {
return fmt.Errorf("Error retrieving volume for disk: %s", err)
}

disk := map[string]interface{}{
"volume_id": virVolKey,
}
disks = append(disks, disk)
disks = append(disks, virVolKey)
}
d.Set("disks", disks)
d.Set("volume_ids", disks)

// look interfaces with addresses
ifacesWithAddr, err := getDomainInterfaces(&domain)
Expand Down

0 comments on commit 1fbe94b

Please sign in to comment.