diff options
author | J. Eduardo <j.eduardo@gmail.com> | 2017-06-29 23:57:44 +0200 |
---|---|---|
committer | Flavio Castelli <flavio@castelli.me> | 2017-07-02 22:16:19 +0200 |
commit | 5513886108680f22a03b0bac79121e270e6a0065 (patch) | |
tree | d0d8e47a9701f5d7bb2ca993e274fe335e036003 /libvirt/resource_libvirt_volume.go | |
parent | 65bc2689d50f3238a052389e30d81730ad2c601d (diff) | |
download | terraform-provider-libvirt-5513886108680f22a03b0bac79121e270e6a0065.tar terraform-provider-libvirt-5513886108680f22a03b0bac79121e270e6a0065.tar.gz |
Added autodetection of base volume format, eliminating the need for explicit configuration.
Diffstat (limited to 'libvirt/resource_libvirt_volume.go')
-rw-r--r-- | libvirt/resource_libvirt_volume.go | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/libvirt/resource_libvirt_volume.go b/libvirt/resource_libvirt_volume.go index a25d157d..c7809e61 100644 --- a/libvirt/resource_libvirt_volume.go +++ b/libvirt/resource_libvirt_volume.go @@ -55,11 +55,6 @@ func volumeCommonSchema() map[string]*schema.Schema { Optional: true, ForceNew: true, }, - "base_volume_format": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, } } @@ -187,12 +182,6 @@ func resourceLibvirtVolumeCreate(d *schema.ResourceData, meta interface{}) error volume = nil volumeDef.BackingStore = new(defBackingStore) - - baseVolumeFormat := "qcow2" - if _, ok := d.GetOk("base_volume_format"); ok { - baseVolumeFormat = d.Get("base_volume_format").(string) - } - volumeDef.BackingStore.Format.Type = baseVolumeFormat baseVolume, err := virConn.LookupStorageVolByKey(baseVolumeId.(string)) if err != nil { return fmt.Errorf("Can't retrieve volume %s", baseVolumeId.(string)) @@ -202,6 +191,16 @@ func resourceLibvirtVolumeCreate(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("can't get name for base image '%s'", baseVolumeId) } volumeDef.BackingStore.Path = baseVolPath + backingStoreXml, err := baseVolume.GetXMLDesc(0) + if err != nil { + return fmt.Errorf("can't get definitions for base image '%s'", baseVolumeId) + } + backingStore, err := newDefVolumeFromXML(backingStoreXml) + if err != nil { + return fmt.Errorf("can't parse definitions for base image '%s'", baseVolumeId) + } + log.Printf("[DEBUG] base volume format is %s", backingStore.Target.Format.Type) + volumeDef.BackingStore.Format.Type = backingStore.Target.Format.Type } if baseVolumeName, ok := d.GetOk("base_volume_name"); ok { @@ -221,7 +220,6 @@ func resourceLibvirtVolumeCreate(d *schema.ResourceData, meta interface{}) error } volumeDef.BackingStore = new(defBackingStore) - volumeDef.BackingStore.Format.Type = "qcow2" baseVolume, err := baseVolumePool.LookupStorageVolByName(baseVolumeName.(string)) if err != nil { return fmt.Errorf("Can't retrieve volume %s", baseVolumeName.(string)) @@ -231,6 +229,16 @@ func resourceLibvirtVolumeCreate(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("can't get name for base image '%s'", baseVolumeName) } volumeDef.BackingStore.Path = baseVolPath + backingStoreXml, err := baseVolume.GetXMLDesc(0) + if err != nil { + return fmt.Errorf("can't get definitions for base image '%s'", baseVolumeName) + } + backingStore, err := newDefVolumeFromXML(backingStoreXml) + if err != nil { + return fmt.Errorf("can't parse definitions for base image '%s'", baseVolumeName) + } + log.Printf("[DEBUG] base volume format is %s", backingStore.Target.Format.Type) + volumeDef.BackingStore.Format.Type = backingStore.Target.Format.Type } if volume == nil { |