-
Notifications
You must be signed in to change notification settings - Fork 0
/
driver-image.go
72 lines (58 loc) · 1.59 KB
/
driver-image.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package drivervbox
import (
"fmt"
"github.com/kuttiproject/drivercore"
)
// UpdateImageList fetches the latest list of VM images from the driver source URL.
func (vd *Driver) UpdateImageList() error {
return fetchimagelist()
}
// ValidK8sVersion returns true if the specified Kubernetes version is available.
func (vd *Driver) ValidK8sVersion(k8sversion string) bool {
err := imageconfigmanager.Load()
if err != nil {
return false
}
_, ok := imagedata.images[k8sversion]
return ok
}
// K8sVersions returns all Kubernetes versions currently supported by kutti.
func (vd *Driver) K8sVersions() []string {
err := imageconfigmanager.Load()
if err != nil {
return []string{}
}
result := make([]string, len(imagedata.images))
index := 0
for _, value := range imagedata.images {
result[index] = value.imageK8sVersion
index++
}
return result
}
// ListImages lists the currently available Images.
func (vd *Driver) ListImages() ([]drivercore.Image, error) {
err := imageconfigmanager.Load()
if err != nil {
return []drivercore.Image{}, err
}
result := make([]drivercore.Image, len(imagedata.images))
index := 0
for _, value := range imagedata.images {
result[index] = value
index++
}
return result, nil
}
// GetImage returns an image corresponding to a Kubernetes version, or an error.
func (vd *Driver) GetImage(k8sversion string) (drivercore.Image, error) {
err := imageconfigmanager.Load()
if err != nil {
return nil, err
}
img, ok := imagedata.images[k8sversion]
if !ok {
return img, fmt.Errorf("no image present for K8s version %s", k8sversion)
}
return img, nil
}