-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathimage_get.go
41 lines (35 loc) · 838 Bytes
/
image_get.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package vm
import (
"os"
"path/filepath"
"strings"
)
// ImageGet downloads rawurl and prepares it for use as a backing disk image. If
// newName is not empty, the image is renamed to newName. If quiet is true, no
// progress is printed to stdout.
func ImageGet(rawurl string, newName string, quiet bool) error {
var err error
var filePath string
if strings.HasPrefix(rawurl, "http") {
filePath, err = download(rawurl, quiet)
if err != nil {
return err
}
} else {
filePath, err = transfer(rawurl, quiet)
if err != nil {
return err
}
}
finalFilePath, err := inspect(filePath, quiet)
if err != nil {
return err
}
if newName != "" {
newpath := filepath.Join(filepath.Dir(finalFilePath), newName) + ".qcow2"
if err := os.Rename(finalFilePath, newpath); err != nil {
return err
}
}
return nil
}