-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathqemu_vm.ts
90 lines (74 loc) · 2.35 KB
/
qemu_vm.ts
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import * as fs from 'fs'
import * as architecture from './architecture'
import {getOrDefaultOrThrow} from './utility'
import * as vm from './vm'
export abstract class Vm extends vm.Vm {
static readonly sshPort = 2847
constructor(
hypervisorDirectory: fs.PathLike,
resourcesDirectory: fs.PathLike,
architecture: architecture.Architecture,
configuration: vm.Configuration
) {
super(
hypervisorDirectory,
resourcesDirectory,
'qemu',
architecture,
configuration
)
}
protected override async getIpAddress(): Promise<string> {
return 'localhost'
}
override get command(): string[] {
const accel = vm.Accelerator[this.configuration.accelerator]
// prettier-ignore
return [
this.hypervisorPath.toString(),
'-machine', `type=${this.configuration.machineType},accel=${accel}`,
'-cpu', this.configuration.cpu,
'-smp', this.configuration.cpuCount.toString(),
'-m', this.configuration.memory,
'-device', `${this.netDevive},netdev=user.0`,
'-netdev', this.netdev,
'-display', 'none',
'-monitor', 'none',
// '-nographic',
'-boot', 'strict=off',
/* eslint-disable @typescript-eslint/no-non-null-assertion */
'-bios', this.configuration.firmware!.toString()
/* eslint-enable @typescript-eslint/no-non-null-assertion */
].concat(this.hardDriverFlags)
}
protected abstract get hardDriverFlags(): string[]
protected get defaultHardDriveFlags(): string[] {
// prettier-ignore
return [
'-device', 'virtio-scsi-pci',
'-device', 'scsi-hd,drive=drive0,bootindex=0',
'-drive', `if=none,file=${this.configuration.diskImage},id=drive0,cache=writeback,discard=ignore,format=raw`,
'-device', 'scsi-hd,drive=drive1,bootindex=1',
'-drive', `if=none,file=${this.configuration.resourcesDiskImage},id=drive1,cache=writeback,discard=ignore,format=raw`,
]
}
protected get netDevive(): string {
return 'virtio-net'
}
protected get ipv6(): string {
return ''
}
private get netdev(): string {
return [
'user',
'id=user.0',
`hostfwd=tcp::${this.configuration.ssHostPort}-:22`,
this.ipv6
]
.filter(e => e !== '')
.join(',')
}
}
export function resolve<T>(implementation: Record<string, T>): T {
return getOrDefaultOrThrow(implementation, 'qemu')
}