| 1 | |
| 2 | |
| 3 | |
| 4 | package limatype |
| 5 | |
| 6 | import ( |
| 7 | "net" |
| 8 | "runtime" |
| 9 | |
| 10 | "github.com/lima-vm/go-qcow2reader/image" |
| 11 | "github.com/opencontainers/go-digest" |
| 12 | "github.com/sirupsen/logrus" |
| 13 | "golang.org/x/sys/cpu" |
| 14 | ) |
| 15 | |
| 16 | type LimaYAML struct { |
| 17 | Base BaseTemplates `yaml:"base,omitempty" json:"base,omitempty"` |
| 18 | MinimumLimaVersion *string `yaml:"minimumLimaVersion,omitempty" json:"minimumLimaVersion,omitempty" jsonschema:"nullable"` |
| 19 | VMType *VMType `yaml:"vmType,omitempty" json:"vmType,omitempty" jsonschema:"nullable"` |
| 20 | VMOpts VMOpts `yaml:"vmOpts,omitempty" json:"vmOpts,omitempty"` |
| 21 | OS *OS `yaml:"os,omitempty" json:"os,omitempty" jsonschema:"nullable"` |
| 22 | Arch *Arch `yaml:"arch,omitempty" json:"arch,omitempty" jsonschema:"nullable"` |
| 23 | Images []Image `yaml:"images,omitempty" json:"images,omitempty" jsonschema:"nullable"` |
| 24 | |
| 25 | CPUType CPUType `yaml:"cpuType,omitempty" json:"cpuType,omitempty" jsonschema:"nullable"` |
| 26 | CPUs *int `yaml:"cpus,omitempty" json:"cpus,omitempty" jsonschema:"nullable"` |
| 27 | Memory *string `yaml:"memory,omitempty" json:"memory,omitempty" jsonschema:"nullable"` |
| 28 | Disk *string `yaml:"disk,omitempty" json:"disk,omitempty" jsonschema:"nullable"` |
| 29 | AdditionalDisks []Disk `yaml:"additionalDisks,omitempty" json:"additionalDisks,omitempty" jsonschema:"nullable"` |
| 30 | Mounts []Mount `yaml:"mounts,omitempty" json:"mounts,omitempty"` |
| 31 | MountTypesUnsupported []string `yaml:"mountTypesUnsupported,omitempty" json:"mountTypesUnsupported,omitempty" jsonschema:"nullable"` |
| 32 | MountType *MountType `yaml:"mountType,omitempty" json:"mountType,omitempty" jsonschema:"nullable"` |
| 33 | MountInotify *bool `yaml:"mountInotify,omitempty" json:"mountInotify,omitempty" jsonschema:"nullable"` |
| 34 | SSH SSH `yaml:"ssh,omitempty" json:"ssh,omitempty"` |
| 35 | Firmware Firmware `yaml:"firmware,omitempty" json:"firmware,omitempty"` |
| 36 | Audio Audio `yaml:"audio,omitempty" json:"audio,omitempty"` |
| 37 | Video Video `yaml:"video,omitempty" json:"video,omitempty"` |
| 38 | Provision []Provision `yaml:"provision,omitempty" json:"provision,omitempty"` |
| 39 | UpgradePackages *bool `yaml:"upgradePackages,omitempty" json:"upgradePackages,omitempty" jsonschema:"nullable"` |
| 40 | Containerd Containerd `yaml:"containerd,omitempty" json:"containerd,omitempty"` |
| 41 | GuestInstallPrefix *string `yaml:"guestInstallPrefix,omitempty" json:"guestInstallPrefix,omitempty" jsonschema:"nullable"` |
| 42 | Probes []Probe `yaml:"probes,omitempty" json:"probes,omitempty"` |
| 43 | PortForwards []PortForward `yaml:"portForwards,omitempty" json:"portForwards,omitempty"` |
| 44 | CopyToHost []CopyToHost `yaml:"copyToHost,omitempty" json:"copyToHost,omitempty"` |
| 45 | Message string `yaml:"message,omitempty" json:"message,omitempty"` |
| 46 | Networks []Network `yaml:"networks,omitempty" json:"networks,omitempty" jsonschema:"nullable"` |
| 47 | |
| 48 | Env map[string]string `yaml:"env,omitempty" json:"env,omitempty"` |
| 49 | Param map[string]string `yaml:"param,omitempty" json:"param,omitempty"` |
| 50 | DNS []net.IP `yaml:"dns,omitempty" json:"dns,omitempty"` |
| 51 | HostResolver HostResolver `yaml:"hostResolver,omitempty" json:"hostResolver,omitempty"` |
| 52 | |
| 53 | PropagateProxyEnv *bool `yaml:"propagateProxyEnv,omitempty" json:"propagateProxyEnv,omitempty" jsonschema:"nullable"` |
| 54 | CACertificates CACertificates `yaml:"caCerts,omitempty" json:"caCerts,omitempty"` |
| 55 | |
| 56 | Rosetta Rosetta `yaml:"rosetta,omitempty" json:"rosetta,omitempty"` |
| 57 | Plain *bool `yaml:"plain,omitempty" json:"plain,omitempty" jsonschema:"nullable"` |
| 58 | TimeZone *string `yaml:"timezone,omitempty" json:"timezone,omitempty" jsonschema:"nullable"` |
| 59 | NestedVirtualization *bool `yaml:"nestedVirtualization,omitempty" json:"nestedVirtualization,omitempty" jsonschema:"nullable"` |
| 60 | User User `yaml:"user,omitempty" json:"user,omitempty"` |
| 61 | TPM *bool `yaml:"tpm,omitempty" json:"tpm,omitempty" jsonschema:"nullable"` |
| 62 | OsOpts OsOpts `yaml:"osOpts,omitempty" json:"osOpts,omitempty"` |
| 63 | } |
| 64 | |
| 65 | type BaseTemplates []LocatorWithDigest |
| 66 | |
| 67 | type LocatorWithDigest struct { |
| 68 | URL string `yaml:"url" json:"url"` |
| 69 | Digest *string `yaml:"digest,omitempty" json:"digest,omitempty"` |
| 70 | } |
| 71 | |
| 72 | type ( |
| 73 | OS = string |
| 74 | Arch = string |
| 75 | MountType = string |
| 76 | VMType = string |
| 77 | ) |
| 78 | |
| 79 | type CPUType = map[Arch]string |
| 80 | |
| 81 | const ( |
| 82 | LINUX OS = "Linux" |
| 83 | DARWIN OS = "Darwin" |
| 84 | FREEBSD OS = "FreeBSD" |
| 85 | WINDOWS OS = "Windows" |
| 86 | |
| 87 | X8664 Arch = "x86_64" |
| 88 | AARCH64 Arch = "aarch64" |
| 89 | ARMV7L Arch = "armv7l" |
| 90 | PPC64LE Arch = "ppc64le" |
| 91 | RISCV64 Arch = "riscv64" |
| 92 | S390X Arch = "s390x" |
| 93 | |
| 94 | REVSSHFS MountType = "reverse-sshfs" |
| 95 | NINEP MountType = "9p" |
| 96 | VIRTIOFS MountType = "virtiofs" |
| 97 | WSLMount MountType = "wsl2" |
| 98 | |
| 99 | QEMU VMType = "qemu" |
| 100 | VZ VMType = "vz" |
| 101 | WSL2 VMType = "wsl2" |
| 102 | HCS VMType = "hcs" |
| 103 | ) |
| 104 | |
| 105 | var ( |
| 106 | OSTypes = []OS{LINUX, DARWIN, FREEBSD, WINDOWS} |
| 107 | ArchTypes = []Arch{X8664, AARCH64, ARMV7L, PPC64LE, RISCV64, S390X} |
| 108 | MountTypes = []MountType{REVSSHFS, NINEP, VIRTIOFS, WSLMount} |
| 109 | VMTypes = []VMType{QEMU, VZ, WSL2, HCS} |
| 110 | ) |
| 111 | |
| 112 | type User struct { |
| 113 | Name *string `yaml:"name,omitempty" json:"name,omitempty" jsonschema:"nullable"` |
| 114 | Comment *string `yaml:"comment,omitempty" json:"comment,omitempty" jsonschema:"nullable"` |
| 115 | Home *string `yaml:"home,omitempty" json:"home,omitempty" jsonschema:"nullable"` |
| 116 | Shell *string `yaml:"shell,omitempty" json:"shell,omitempty" jsonschema:"nullable"` |
| 117 | UID *uint32 `yaml:"uid,omitempty" json:"uid,omitempty" jsonschema:"nullable"` |
| 118 | PasswordlessSudo *bool `yaml:"passwordlessSudo,omitempty" json:"passwordlessSudo,omitempty" jsonschema:"nullable"` |
| 119 | } |
| 120 | |
| 121 | type VMOpts map[VMType]any |
| 122 | |
| 123 | type QEMUOpts struct { |
| 124 | MinimumVersion *string `yaml:"minimumVersion,omitempty" json:"minimumVersion,omitempty" jsonschema:"nullable"` |
| 125 | CPUType CPUType `yaml:"cpuType,omitempty" json:"cpuType,omitempty" jsonschema:"nullable"` |
| 126 | } |
| 127 | |
| 128 | type VZOpts struct { |
| 129 | Rosetta Rosetta `yaml:"rosetta,omitempty" json:"rosetta,omitempty"` |
| 130 | DiskImageFormat *image.Type `yaml:"diskImageFormat,omitempty" json:"diskImageFormat,omitempty" jsonschema:"nullable"` |
| 131 | } |
| 132 | |
| 133 | type Rosetta struct { |
| 134 | Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty" jsonschema:"nullable"` |
| 135 | BinFmt *bool `yaml:"binfmt,omitempty" json:"binfmt,omitempty" jsonschema:"nullable"` |
| 136 | } |
| 137 | |
| 138 | type File struct { |
| 139 | Location string `yaml:"location" json:"location"` |
| 140 | Arch Arch `yaml:"arch,omitempty" json:"arch,omitempty"` |
| 141 | Digest digest.Digest `yaml:"digest,omitempty" json:"digest,omitempty"` |
| 142 | } |
| 143 | |
| 144 | type FileWithVMType struct { |
| 145 | File `yaml:",inline"` |
| 146 | VMType VMType `yaml:"vmType,omitempty" json:"vmType,omitempty"` |
| 147 | } |
| 148 | |
| 149 | type Kernel struct { |
| 150 | File `yaml:",inline"` |
| 151 | Cmdline string `yaml:"cmdline,omitempty" json:"cmdline,omitempty"` |
| 152 | } |
| 153 | |
| 154 | type Image struct { |
| 155 | File `yaml:",inline"` |
| 156 | Kernel *Kernel `yaml:"kernel,omitempty" json:"kernel,omitempty"` |
| 157 | Initrd *File `yaml:"initrd,omitempty" json:"initrd,omitempty"` |
| 158 | Variant string `yaml:"variant,omitempty" json:"variant,omitempty"` |
| 159 | ArchVariant string `yaml:"archVariant,omitempty" json:"archVariant,omitempty"` |
| 160 | } |
| 161 | |
| 162 | type Disk struct { |
| 163 | Name string `yaml:"name" json:"name"` |
| 164 | Format *bool `yaml:"format,omitempty" json:"format,omitempty"` |
| 165 | FSType *string `yaml:"fsType,omitempty" json:"fsType,omitempty"` |
| 166 | FSArgs []string `yaml:"fsArgs,omitempty" json:"fsArgs,omitempty"` |
| 167 | } |
| 168 | |
| 169 | type Mount struct { |
| 170 | Location string `yaml:"location" json:"location"` |
| 171 | MountPoint *string `yaml:"mountPoint,omitempty" json:"mountPoint,omitempty" jsonschema:"nullable"` |
| 172 | Writable *bool `yaml:"writable,omitempty" json:"writable,omitempty" jsonschema:"nullable"` |
| 173 | SSHFS SSHFS `yaml:"sshfs,omitempty" json:"sshfs,omitempty"` |
| 174 | NineP NineP `yaml:"9p,omitempty" json:"9p,omitempty"` |
| 175 | Virtiofs Virtiofs `yaml:"virtiofs,omitempty" json:"virtiofs,omitempty"` |
| 176 | } |
| 177 | |
| 178 | type SFTPDriver = string |
| 179 | |
| 180 | const ( |
| 181 | SFTPDriverBuiltin = "builtin" |
| 182 | SFTPDriverOpenSSHSFTPServer = "openssh-sftp-server" |
| 183 | ) |
| 184 | |
| 185 | type SSHFS struct { |
| 186 | Cache *bool `yaml:"cache,omitempty" json:"cache,omitempty" jsonschema:"nullable"` |
| 187 | FollowSymlinks *bool `yaml:"followSymlinks,omitempty" json:"followSymlinks,omitempty" jsonschema:"nullable"` |
| 188 | SFTPDriver *SFTPDriver `yaml:"sftpDriver,omitempty" json:"sftpDriver,omitempty" jsonschema:"nullable"` |
| 189 | |
| 190 | ReadonlyNames []string `yaml:"readonlyNames,omitempty" json:"readonlyNames,omitempty"` |
| 191 | } |
| 192 | |
| 193 | type NineP struct { |
| 194 | SecurityModel *string `yaml:"securityModel,omitempty" json:"securityModel,omitempty" jsonschema:"nullable"` |
| 195 | ProtocolVersion *string `yaml:"protocolVersion,omitempty" json:"protocolVersion,omitempty" jsonschema:"nullable"` |
| 196 | Msize *string `yaml:"msize,omitempty" json:"msize,omitempty" jsonschema:"nullable"` |
| 197 | Cache *string `yaml:"cache,omitempty" json:"cache,omitempty" jsonschema:"nullable"` |
| 198 | } |
| 199 | |
| 200 | type Virtiofs struct { |
| 201 | QueueSize *int `yaml:"queueSize,omitempty" json:"queueSize,omitempty"` |
| 202 | } |
| 203 | |
| 204 | type SSH struct { |
| 205 | LocalPort *int `yaml:"localPort,omitempty" json:"localPort,omitempty" jsonschema:"nullable"` |
| 206 | |
| 207 | |
| 208 | LoadDotSSHPubKeys *bool `yaml:"loadDotSSHPubKeys,omitempty" json:"loadDotSSHPubKeys,omitempty" jsonschema:"nullable"` |
| 209 | ForwardAgent *bool `yaml:"forwardAgent,omitempty" json:"forwardAgent,omitempty" jsonschema:"nullable"` |
| 210 | ForwardX11 *bool `yaml:"forwardX11,omitempty" json:"forwardX11,omitempty" jsonschema:"nullable"` |
| 211 | ForwardX11Trusted *bool `yaml:"forwardX11Trusted,omitempty" json:"forwardX11Trusted,omitempty" jsonschema:"nullable"` |
| 212 | |
| 213 | OverVsock *bool `yaml:"overVsock,omitempty" json:"overVsock,omitempty" jsonschema:"nullable"` |
| 214 | } |
| 215 | |
| 216 | type Firmware struct { |
| 217 | |
| 218 | |
| 219 | LegacyBIOS *bool `yaml:"legacyBIOS,omitempty" json:"legacyBIOS,omitempty" jsonschema:"nullable"` |
| 220 | |
| 221 | |
| 222 | |
| 223 | Images []FileWithVMType `yaml:"images,omitempty" json:"images,omitempty"` |
| 224 | } |
| 225 | |
| 226 | type Audio struct { |
| 227 | |
| 228 | Device *string `yaml:"device,omitempty" json:"device,omitempty" jsonschema:"nullable"` |
| 229 | |
| 230 | Interface *string `yaml:"interface,omitempty" json:"interface,omitempty" jsonschema:"nullable"` |
| 231 | |
| 232 | |
| 233 | |
| 234 | Microphone *bool `yaml:"microphone,omitempty" json:"microphone,omitempty" jsonschema:"nullable"` |
| 235 | } |
| 236 | |
| 237 | type VNCOptions struct { |
| 238 | Display *string `yaml:"display,omitempty" json:"display,omitempty" jsonschema:"nullable"` |
| 239 | } |
| 240 | |
| 241 | type Video struct { |
| 242 | |
| 243 | Display *string `yaml:"display,omitempty" json:"display,omitempty" jsonschema:"nullable"` |
| 244 | VNC VNCOptions `yaml:"vnc,omitempty" json:"vnc,omitempty"` |
| 245 | } |
| 246 | |
| 247 | type ProvisionMode = string |
| 248 | |
| 249 | const ( |
| 250 | ProvisionModeSystem ProvisionMode = "system" |
| 251 | ProvisionModeUser ProvisionMode = "user" |
| 252 | ProvisionModeBoot ProvisionMode = "boot" |
| 253 | ProvisionModeDependency ProvisionMode = "dependency" |
| 254 | ProvisionModeAnsible ProvisionMode = "ansible" |
| 255 | ProvisionModeData ProvisionMode = "data" |
| 256 | ProvisionModeYQ ProvisionMode = "yq" |
| 257 | ) |
| 258 | |
| 259 | type Provision struct { |
| 260 | Mode ProvisionMode `yaml:"mode,omitempty" json:"mode,omitempty" jsonschema:"default=system"` |
| 261 | SkipDefaultDependencyResolution *bool `yaml:"skipDefaultDependencyResolution,omitempty" json:"skipDefaultDependencyResolution,omitempty"` |
| 262 | Script *string `yaml:"script,omitempty" json:"script,omitempty"` |
| 263 | File *LocatorWithDigest `yaml:"file,omitempty" json:"file,omitempty" jsonschema:"nullable"` |
| 264 | Playbook string `yaml:"playbook,omitempty" json:"playbook,omitempty"` |
| 265 | |
| 266 | ProvisionData `yaml:",inline"` |
| 267 | |
| 268 | Expression *string `yaml:"expression,omitempty" json:"expression,omitempty" jsonschema:"nullable"` |
| 269 | Format *string `yaml:"format,omitempty" json:"format,omitempty" jsonschema:"nullable"` |
| 270 | } |
| 271 | |
| 272 | type ProvisionData struct { |
| 273 | Content *string `yaml:"content,omitempty" json:"content,omitempty" jsonschema:"nullable"` |
| 274 | Overwrite *bool `yaml:"overwrite,omitempty" json:"overwrite,omitempty" jsonschema:"nullable"` |
| 275 | Owner *string `yaml:"owner,omitempty" json:"owner,omitempty"` |
| 276 | Path *string `yaml:"path,omitempty" json:"path,omitempty"` |
| 277 | Permissions *string `yaml:"permissions,omitempty" json:"permissions,omitempty"` |
| 278 | } |
| 279 | |
| 280 | type Containerd struct { |
| 281 | System *bool `yaml:"system,omitempty" json:"system,omitempty" jsonschema:"nullable"` |
| 282 | User *bool `yaml:"user,omitempty" json:"user,omitempty" jsonschema:"nullable"` |
| 283 | Archives []File `yaml:"archives,omitempty" json:"archives,omitempty"` |
| 284 | } |
| 285 | |
| 286 | type ProbeMode = string |
| 287 | |
| 288 | const ( |
| 289 | ProbeModeReadiness ProbeMode = "readiness" |
| 290 | ) |
| 291 | |
| 292 | type Probe struct { |
| 293 | Mode ProbeMode `yaml:"mode,omitempty" json:"mode,omitempty" jsonschema:"default=readiness"` |
| 294 | Description string `yaml:"description,omitempty" json:"description,omitempty"` |
| 295 | Script *string `yaml:"script,omitempty" json:"script,omitempty"` |
| 296 | File *LocatorWithDigest `yaml:"file,omitempty" json:"file,omitempty" jsonschema:"nullable"` |
| 297 | Hint string `yaml:"hint,omitempty" json:"hint,omitempty"` |
| 298 | } |
| 299 | |
| 300 | type Proto = string |
| 301 | |
| 302 | const ( |
| 303 | ProtoTCP Proto = "tcp" |
| 304 | ProtoUDP Proto = "udp" |
| 305 | ProtoAny Proto = "any" |
| 306 | ) |
| 307 | |
| 308 | type PortForward struct { |
| 309 | GuestIPMustBeZero *bool `yaml:"guestIPMustBeZero,omitempty" json:"guestIPMustBeZero,omitempty"` |
| 310 | GuestIP net.IP `yaml:"guestIP,omitempty" json:"guestIP,omitempty"` |
| 311 | GuestPort int `yaml:"guestPort,omitempty" json:"guestPort,omitempty"` |
| 312 | GuestPortRange [2]int `yaml:"guestPortRange,omitempty" json:"guestPortRange,omitempty"` |
| 313 | GuestSocket string `yaml:"guestSocket,omitempty" json:"guestSocket,omitempty"` |
| 314 | HostIP net.IP `yaml:"hostIP,omitempty" json:"hostIP,omitempty"` |
| 315 | HostPort int `yaml:"hostPort,omitempty" json:"hostPort,omitempty"` |
| 316 | HostPortRange [2]int `yaml:"hostPortRange,omitempty" json:"hostPortRange,omitempty"` |
| 317 | HostSocket string `yaml:"hostSocket,omitempty" json:"hostSocket,omitempty"` |
| 318 | Proto Proto `yaml:"proto,omitempty" json:"proto,omitempty"` |
| 319 | Reverse bool `yaml:"reverse,omitempty" json:"reverse,omitempty"` |
| 320 | Ignore bool `yaml:"ignore,omitempty" json:"ignore,omitempty"` |
| 321 | Static bool `yaml:"static,omitempty" json:"static,omitempty"` |
| 322 | } |
| 323 | |
| 324 | type CopyToHost struct { |
| 325 | GuestFile string `yaml:"guest,omitempty" json:"guest,omitempty"` |
| 326 | HostFile string `yaml:"host,omitempty" json:"host,omitempty"` |
| 327 | SkipIfMissing bool `yaml:"skipIfMissing,omitempty" json:"skipIfMissing,omitempty"` |
| 328 | DeleteOnStop bool `yaml:"deleteOnStop,omitempty" json:"deleteOnStop,omitempty"` |
| 329 | } |
| 330 | |
| 331 | type Network struct { |
| 332 | |
| 333 | Lima string `yaml:"lima,omitempty" json:"lima,omitempty"` |
| 334 | |
| 335 | Socket string `yaml:"socket,omitempty" json:"socket,omitempty"` |
| 336 | |
| 337 | VZNAT *bool `yaml:"vzNAT,omitempty" json:"vzNAT,omitempty"` |
| 338 | |
| 339 | MACAddress string `yaml:"macAddress,omitempty" json:"macAddress,omitempty"` |
| 340 | Interface string `yaml:"interface,omitempty" json:"interface,omitempty"` |
| 341 | Metric *uint32 `yaml:"metric,omitempty" json:"metric,omitempty"` |
| 342 | } |
| 343 | |
| 344 | type HostResolver struct { |
| 345 | Enabled *bool `yaml:"enabled,omitempty" json:"enabled,omitempty" jsonschema:"nullable"` |
| 346 | IPv6 *bool `yaml:"ipv6,omitempty" json:"ipv6,omitempty" jsonschema:"nullable"` |
| 347 | Hosts map[string]string `yaml:"hosts,omitempty" json:"hosts,omitempty" jsonschema:"nullable"` |
| 348 | } |
| 349 | |
| 350 | type CACertificates struct { |
| 351 | RemoveDefaults *bool `yaml:"removeDefaults,omitempty" json:"removeDefaults,omitempty" jsonschema:"nullable"` |
| 352 | Files []string `yaml:"files,omitempty" json:"files,omitempty" jsonschema:"nullable"` |
| 353 | Certs []string `yaml:"certs,omitempty" json:"certs,omitempty" jsonschema:"nullable"` |
| 354 | } |
| 355 | |
| 356 | type OsOpts map[OS]any |
| 357 | |
| 358 | type WindowsOpts struct { |
| 359 | VirtioWin []File `yaml:"virtioWin,omitempty" json:"virtioWin,omitempty"` |
| 360 | } |
| 361 | |
| 362 | type DarwinOpts struct { |
| 363 | |
| 364 | SuppressFirstLoginSetup *bool `yaml:"suppressFirstLoginSetup,omitempty" json:"suppressFirstLoginSetup,omitempty" jsonschema:"nullable"` |
| 365 | |
| 366 | |
| 367 | SuppressFirstLoginSetupPlist *string `yaml:"suppressFirstLoginSetupPlist,omitempty" json:"suppressFirstLoginSetupPlist,omitempty" jsonschema:"nullable"` |
| 368 | } |
| 369 | |
| 370 | func NewOS(osname string) OS { |
| 371 | switch osname { |
| 372 | case "linux": |
| 373 | return LINUX |
| 374 | case "darwin": |
| 375 | return DARWIN |
| 376 | default: |
| 377 | logrus.Warnf("Unknown os: %s", osname) |
| 378 | return osname |
| 379 | } |
| 380 | } |
| 381 | |
| 382 | func Goarm() int { |
| 383 | if runtime.GOOS != "linux" { |
| 384 | return 0 |
| 385 | } |
| 386 | if runtime.GOARCH != "arm" { |
| 387 | return 0 |
| 388 | } |
| 389 | if cpu.ARM.HasVFPv3 { |
| 390 | return 7 |
| 391 | } |
| 392 | if cpu.ARM.HasVFP { |
| 393 | return 6 |
| 394 | } |
| 395 | return 5 |
| 396 | } |
| 397 | |
| 398 | func NewArch(arch string) Arch { |
| 399 | switch arch { |
| 400 | case "amd64": |
| 401 | return X8664 |
| 402 | case "arm64": |
| 403 | return AARCH64 |
| 404 | case "arm": |
| 405 | arm := Goarm() |
| 406 | if arm == 7 { |
| 407 | return ARMV7L |
| 408 | } |
| 409 | logrus.Warnf("Unknown arm: %d", arm) |
| 410 | return arch |
| 411 | case "ppc64le": |
| 412 | return PPC64LE |
| 413 | case "riscv64": |
| 414 | return RISCV64 |
| 415 | case "s390x": |
| 416 | return S390X |
| 417 | default: |
| 418 | logrus.Warnf("Unknown arch: %s", arch) |
| 419 | return arch |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | func IsNativeArch(arch Arch) bool { |
| 424 | nativeX8664 := arch == X8664 && runtime.GOARCH == "amd64" |
| 425 | nativeAARCH64 := arch == AARCH64 && runtime.GOARCH == "arm64" |
| 426 | nativeARMV7L := arch == ARMV7L && runtime.GOARCH == "arm" && Goarm() == 7 |
| 427 | nativePPC64LE := arch == PPC64LE && runtime.GOARCH == "ppc64le" |
| 428 | nativeRISCV64 := arch == RISCV64 && runtime.GOARCH == "riscv64" |
| 429 | nativeS390X := arch == S390X && runtime.GOARCH == "s390x" |
| 430 | return nativeX8664 || nativeAARCH64 || nativeARMV7L || nativePPC64LE || nativeRISCV64 || nativeS390X |
| 431 | } |
| 432 | |
| 433 | func DefaultDriver() VMType { |
| 434 | switch runtime.GOOS { |
| 435 | case "darwin": |
| 436 | return VZ |
| 437 | default: |
| 438 | return QEMU |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | func DefaultNonNativeArchDriver() VMType { |
| 443 | return QEMU |
| 444 | } |