summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlavio Castelli <fcastelli@suse.com>2017-05-26 23:46:05 +0200
committerFlavio Castelli <fcastelli@suse.com>2017-05-26 23:46:05 +0200
commit2817006523fead9169dbbdf06212df620b72aad8 (patch)
treeef176e6062a9cd5f648ed837ccceca416e4d9653
parent8aab6118f495e72905a6961672156d49221679aa (diff)
downloadterraform-provider-libvirt-2817006523fead9169dbbdf06212df620b72aad8.tar
terraform-provider-libvirt-2817006523fead9169dbbdf06212df620b72aad8.tar.gz
Fix code broken accidentally by merge of PR 116
Some of the code being used by CoreOS ignition was accidentally broken by a recent merge. Signed-off-by: Flavio Castelli <fcastelli@suse.com>
-rw-r--r--libvirt/coreos_ignition_def.go35
1 files changed, 21 insertions, 14 deletions
diff --git a/libvirt/coreos_ignition_def.go b/libvirt/coreos_ignition_def.go
index 216075f2..e0f786e3 100644
--- a/libvirt/coreos_ignition_def.go
+++ b/libvirt/coreos_ignition_def.go
@@ -1,8 +1,8 @@
package libvirt
import (
- "encoding/xml"
"encoding/json"
+ "encoding/xml"
"fmt"
"io"
"io/ioutil"
@@ -15,9 +15,9 @@ import (
)
type defIgnition struct {
- Name string
- PoolName string
- Content string
+ Name string
+ PoolName string
+ Content string
}
// Creates a new cloudinit with the defaults
@@ -88,14 +88,24 @@ func (ign *defIgnition) CreateAndUpload(virConn *libvirt.VirConnection) (string,
defer volume.Free()
// upload ignition file
- stream, err := libvirt.NewVirStream(virConn, 0)
- if err != nil {
- return "", err
+ copier := func(src io.Reader) error {
+ stream, err := libvirt.NewVirStream(virConn, 0)
+ if err != nil {
+ return err
+ }
+ defer stream.Close()
+
+ volume.Upload(stream, 0, volumeDef.Capacity.Amount, 0)
+
+ n, err := io.Copy(stream, src)
+ if err != nil {
+ return fmt.Errorf("Error while downloading %s: %s", img.String(), err)
+ }
+ log.Printf("%d bytes uploaded\n", n)
+ return nil
}
- defer stream.Close()
- volume.Upload(stream, 0, uint64(volumeDef.Capacity.Amount), 0)
- err = img.WriteToStream(stream)
+ err = img.Import(copier, volumeDef)
if err != nil {
return "", err
}
@@ -123,7 +133,6 @@ func getIgnitionVolumeKeyFromTerraformID(id string) (string, error) {
return s[0], nil
}
-
// Dumps the Ignition object - either generated by Terraform or supplied as a file -
// to a temporary ignition file
func (ign *defIgnition) createFile() (string, error) {
@@ -148,7 +157,7 @@ func (ign *defIgnition) createFile() (string, error) {
if !file {
if _, err := tempFile.WriteString(ign.Content); err != nil {
- return "", fmt.Errorf("Cannot write Ignition object to temporary "+
+ return "", fmt.Errorf("Cannot write Ignition object to temporary " +
"ignition file")
}
} else if file {
@@ -196,7 +205,5 @@ func newIgnitionDefFromRemoteVol(virConn *libvirt.VirConnection, id string) (def
return ign, fmt.Errorf("Error retrieving pool name: %s", err)
}
-
return ign, nil
}
-