-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathversion.go
73 lines (59 loc) · 1.94 KB
/
version.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
73
package kuttilib
import (
"encoding/json"
"github.com/kuttiproject/drivercore"
)
// VersionStatus represents the current status of a version.
type VersionStatus drivercore.ImageStatus
// The VersionStatus* constants list valid version statuses.
const (
VersionStatusNotDownloaded = VersionStatus(drivercore.ImageStatusNotDownloaded)
VersionStatusDownloaded = VersionStatus(drivercore.ImageStatusDownloaded)
)
// versiondata is a data-only representation of the Version type,
// used for serialization and output.
type versiondata struct {
K8sVersion string
Status string
}
// Version represents a Kubernetes version that may be
// used to create a cluster.
type Version struct {
image drivercore.Image
}
// K8sVersion returns the Kubernetes version string.
func (v *Version) K8sVersion() string {
return v.image.K8sVersion()
}
// Status returns the local availability of the version.
func (v *Version) Status() VersionStatus {
return VersionStatus(v.image.Status())
}
// MarshalJSON returns the JSON encoding of the version.
func (v *Version) MarshalJSON() ([]byte, error) {
savedata := versiondata{
K8sVersion: v.K8sVersion(),
Status: string(v.Status()),
}
return json.Marshal(savedata)
}
// Fetch downloads this version's image from the Driver
// repository.
func (v *Version) Fetch() error {
return v.image.Fetch()
}
// FetchWithProgress downloads this version's image from the Driver
// repository into the local cache, and reports progress via the
// supplied callback. The callback reports current and total in bytes.
func (v *Version) FetchWithProgress(progress func(current int64, total int64)) error {
return v.image.FetchWithProgress(progress)
}
// FromFile imports this version's image from the specified
// local file.
func (v *Version) FromFile(filename string) error {
return v.image.FromFile(filename)
}
// PurgeLocal removes the local cached copy of a version.
func (v *Version) PurgeLocal() error {
return v.image.PurgeLocal()
}