forked from abiosoft/colima
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vm.go
60 lines (50 loc) · 1.09 KB
/
vm.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
package environment
import (
"context"
"runtime"
)
// VM is virtual machine.
type VM interface {
GuestActions
Dependencies
Host() HostActions
Teardown(ctx context.Context) error
}
// VM configurations
const (
// ContainerRuntimeKey is the settings key for container runtime.
ContainerRuntimeKey = "runtime"
)
// Arch is the CPU architecture of the VM.
type Arch string
const (
X8664 Arch = "x86_64"
AARCH64 Arch = "aarch64"
)
// HostArch returns the host CPU architecture.
func HostArch() Arch {
return Arch(runtime.GOARCH).Value()
}
// GoArch returns the GOARCH equivalent value for the architecture.
func (a Arch) GoArch() string {
switch a {
case X8664:
return "amd64"
case AARCH64:
return "arm64"
}
return runtime.GOARCH
}
// Value converts the underlying architecture alias value to one of X8664 or AARCH64.
func (a Arch) Value() Arch {
switch a {
case X8664, AARCH64:
return a
// accept amd, amd64, x86, x64, arm, arm64 and m1 values
case "amd", "amd64", "x86", "x64":
return X8664
case "arm", "arm64", "m1":
return AARCH64
}
return Arch(runtime.GOARCH).Value()
}