@hmharness/domain-harmony 0.13.5 → 0.13.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +2 -0
- package/dist/vmenv.d.ts +44 -0
- package/dist/vmenv.js +347 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -406,6 +406,7 @@ export const harmonyUninstall = {
|
|
|
406
406
|
return { output: r.out, isError: !r.ok };
|
|
407
407
|
},
|
|
408
408
|
};
|
|
409
|
+
import { vmTools } from "./vmenv.js";
|
|
409
410
|
export const harmonyTools = [
|
|
410
411
|
harmonyDevices,
|
|
411
412
|
harmonyToolchainCheck,
|
|
@@ -426,6 +427,7 @@ export const harmonyTools = [
|
|
|
426
427
|
harmonyApiLookup,
|
|
427
428
|
harmonyUiRegression,
|
|
428
429
|
...emulatorTools,
|
|
430
|
+
...vmTools,
|
|
429
431
|
];
|
|
430
432
|
export { harmonyProjectCreate, scaffoldProject, solidPng, sdkVersion } from "./project.js";
|
|
431
433
|
export { harmonyCjpmBuild, harmonyCjpmTest, findCjpm } from "./cangjie.js";
|
package/dist/vmenv.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { type Tool } from '@hmharness/kernel';
|
|
2
|
+
export interface VmQemuConfig {
|
|
3
|
+
dir?: string;
|
|
4
|
+
launch?: string;
|
|
5
|
+
hdcPort?: number;
|
|
6
|
+
vncDisplay?: number;
|
|
7
|
+
}
|
|
8
|
+
export interface VmVmwareConfig {
|
|
9
|
+
vmrun?: string;
|
|
10
|
+
vmDirs?: string[];
|
|
11
|
+
}
|
|
12
|
+
export interface VmConfig {
|
|
13
|
+
qemu?: VmQemuConfig;
|
|
14
|
+
vmware?: VmVmwareConfig;
|
|
15
|
+
}
|
|
16
|
+
/** extra hdc resolver candidate: the 5.0.2 SDK shipped beside the image */
|
|
17
|
+
export declare const QEMU_SDK_HDC = "D:/OHOS-QEMU/sdk-5.0.2/14/toolchains/hdc.exe";
|
|
18
|
+
export declare const VM_DEFAULTS: {
|
|
19
|
+
qemuDir: string;
|
|
20
|
+
qemuLaunch: string;
|
|
21
|
+
qemuHdcPort: number;
|
|
22
|
+
qemuVncDisplay: number;
|
|
23
|
+
vmrun: string;
|
|
24
|
+
vmDirs: string[];
|
|
25
|
+
};
|
|
26
|
+
export declare function resolveQemu(cfg?: VmQemuConfig): {
|
|
27
|
+
dir: string;
|
|
28
|
+
launch: string;
|
|
29
|
+
launchPath: string;
|
|
30
|
+
hdcPort: number;
|
|
31
|
+
vncDisplay: number;
|
|
32
|
+
};
|
|
33
|
+
export declare function resolveVmrun(cfg?: VmVmwareConfig): {
|
|
34
|
+
vmrun: string;
|
|
35
|
+
vmDirs: string[];
|
|
36
|
+
};
|
|
37
|
+
/** Parse the guest hdc forward port out of a launch .cmd (hostfwd line).
|
|
38
|
+
* Pure - testable. Falls back to the default when absent. */
|
|
39
|
+
export declare function parseHostfwd(script: string, fallback?: number): number;
|
|
40
|
+
export declare const harmonyVmQemuTool: Tool;
|
|
41
|
+
/** Parse `vmrun list` output into vmx paths. Pure - testable. */
|
|
42
|
+
export declare function parseVmrunList(out: string): string[];
|
|
43
|
+
export declare const vmwareVmsTool: Tool;
|
|
44
|
+
export declare const vmTools: Tool[];
|
package/dist/vmenv.js
ADDED
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @hmharness/domain-harmony - vmenv (VM development environments)
|
|
3
|
+
* Two VM families this machine uses for hmharness development, unified as
|
|
4
|
+
* first-class tools so the agent can drive them without shell gymnastics:
|
|
5
|
+
*
|
|
6
|
+
* 1. KaihongOS 5.0 QEMU image (D:\OHOS-QEMU\KaihongOS): OpenHarmony-family
|
|
7
|
+
* guest booted via qemu-system-x86_64 with user-mode networking that
|
|
8
|
+
* forwards host 127.0.0.1:15566 -> guest hdcd (10178), so it becomes a
|
|
9
|
+
* normal `hdc tconn 127.0.0.1:15565` target - same pipeline as the
|
|
10
|
+
* DevEco emulator. QMP(22472)/HMP(22471)/serial(22473) are there for
|
|
11
|
+
* lifecycle + diagnostics.
|
|
12
|
+
*
|
|
13
|
+
* 2. VMware Workstation VMs (D:\VMs: Ubuntu 26.04 / Kali 2026.2 / Win11):
|
|
14
|
+
* general dev environments. Lifecycle via vmrun; remote access is the
|
|
15
|
+
* existing sshHosts config (the web SSH panel) - this module never
|
|
16
|
+
* shells into guests itself.
|
|
17
|
+
*
|
|
18
|
+
* Config (config.json `vm` block, all optional - defaults auto-discover):
|
|
19
|
+
* vm.qemu = { dir, launch, hdcPort, vncDisplay }
|
|
20
|
+
* vm.vmware = { vmrun, vmDirs: string[] }
|
|
21
|
+
*
|
|
22
|
+
* Safety: start/stop/change VM state = approval-gated tools; status/list
|
|
23
|
+
* are read-only. Zero runtime deps.
|
|
24
|
+
*/
|
|
25
|
+
import { execFile, spawn } from 'node:child_process';
|
|
26
|
+
import { existsSync } from 'node:fs';
|
|
27
|
+
import { readdir } from 'node:fs/promises';
|
|
28
|
+
import { join } from 'node:path';
|
|
29
|
+
import { promisify } from 'node:util';
|
|
30
|
+
import * as net from 'node:net';
|
|
31
|
+
import { loadConfig } from '@hmharness/kernel';
|
|
32
|
+
const execCb = promisify(execFile);
|
|
33
|
+
async function vmConfig() {
|
|
34
|
+
try {
|
|
35
|
+
const cfg = (await loadConfig());
|
|
36
|
+
return cfg.vm ?? {};
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return {};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** extra hdc resolver candidate: the 5.0.2 SDK shipped beside the image */
|
|
43
|
+
export const QEMU_SDK_HDC = 'D:/OHOS-QEMU/sdk-5.0.2/14/toolchains/hdc.exe';
|
|
44
|
+
export const VM_DEFAULTS = {
|
|
45
|
+
qemuDir: 'D:/OHOS-QEMU/KaihongOS',
|
|
46
|
+
qemuLaunch: 'launch_qemu_vnc.cmd',
|
|
47
|
+
qemuHdcPort: 15566,
|
|
48
|
+
qemuVncDisplay: 5,
|
|
49
|
+
vmrun: 'C:/Program Files/VMware/VMware Workstation/vmrun.exe',
|
|
50
|
+
vmDirs: ['D:/VMs'],
|
|
51
|
+
};
|
|
52
|
+
export function resolveQemu(cfg) {
|
|
53
|
+
const dir = cfg?.dir ?? VM_DEFAULTS.qemuDir;
|
|
54
|
+
return {
|
|
55
|
+
dir,
|
|
56
|
+
launch: cfg?.launch ?? VM_DEFAULTS.qemuLaunch,
|
|
57
|
+
launchPath: join(dir, cfg?.launch ?? VM_DEFAULTS.qemuLaunch),
|
|
58
|
+
hdcPort: cfg?.hdcPort ?? VM_DEFAULTS.qemuHdcPort,
|
|
59
|
+
vncDisplay: cfg?.vncDisplay ?? VM_DEFAULTS.qemuVncDisplay,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
export function resolveVmrun(cfg) {
|
|
63
|
+
return {
|
|
64
|
+
vmrun: cfg?.vmrun ?? VM_DEFAULTS.vmrun,
|
|
65
|
+
vmDirs: cfg?.vmDirs?.length ? cfg.vmDirs : VM_DEFAULTS.vmDirs,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/** Parse the guest hdc forward port out of a launch .cmd (hostfwd line).
|
|
69
|
+
* Pure - testable. Falls back to the default when absent. */
|
|
70
|
+
export function parseHostfwd(script, fallback = VM_DEFAULTS.qemuHdcPort) {
|
|
71
|
+
const m = /hostfwd=tcp:127\.0\.0\.1:(\d+)-:5555/.exec(script);
|
|
72
|
+
return m ? Number(m[1]) : fallback;
|
|
73
|
+
}
|
|
74
|
+
/* ---------------- KaihongOS QEMU tool ---------------- */
|
|
75
|
+
export const harmonyVmQemuTool = {
|
|
76
|
+
name: 'harmony_vm_qemu',
|
|
77
|
+
description: 'KaihongOS 5.0 QEMU image lifecycle: status (qemu process + hdc target + VNC), start (launch cmd, then hdc tconn), stop (QMP quit), hdc-connect. The image forwards host 127.0.0.1:15565 -> guest hdcd 5555, so after start it is a normal hdc target for install/launch/logs tools. Actions: status (default) | start | stop | connect.',
|
|
78
|
+
parameters: {
|
|
79
|
+
type: 'object',
|
|
80
|
+
properties: {
|
|
81
|
+
action: { type: 'string', description: 'status | start | stop | connect' },
|
|
82
|
+
},
|
|
83
|
+
required: [],
|
|
84
|
+
},
|
|
85
|
+
needsApproval(args) {
|
|
86
|
+
return args?.action === 'start' || args?.action === 'stop';
|
|
87
|
+
},
|
|
88
|
+
async execute(args) {
|
|
89
|
+
const action = String(args?.action ?? 'status');
|
|
90
|
+
const cfg = await vmConfig();
|
|
91
|
+
const q = resolveQemu(cfg.qemu);
|
|
92
|
+
// local hdc resolver (same chain as index.ts: PATH -> DevEco toolchains)
|
|
93
|
+
const findHdcLocal = async () => {
|
|
94
|
+
const deveco = process.env.HM_DEVECO_HOME ?? 'C:/Program Files/Huawei/DevEco Studio';
|
|
95
|
+
const toolchainsHdc = join(deveco, 'sdk/default/openharmony/toolchains/hdc.exe');
|
|
96
|
+
try {
|
|
97
|
+
await execCb('hdc', ['--version'], { timeout: 8000, windowsHide: true });
|
|
98
|
+
return 'hdc';
|
|
99
|
+
}
|
|
100
|
+
catch { /* not on PATH */ }
|
|
101
|
+
if (existsSync(toolchainsHdc))
|
|
102
|
+
return toolchainsHdc;
|
|
103
|
+
return existsSync(QEMU_SDK_HDC) ? QEMU_SDK_HDC : '';
|
|
104
|
+
};
|
|
105
|
+
const hdc = await findHdcLocal();
|
|
106
|
+
const target = `127.0.0.1:${q.hdcPort}`;
|
|
107
|
+
const hdcTargets = async () => {
|
|
108
|
+
if (!hdc)
|
|
109
|
+
return '(hdc not found)';
|
|
110
|
+
try {
|
|
111
|
+
const r = await execCb(hdc, ['list', 'targets'], { timeout: 5000, windowsHide: true });
|
|
112
|
+
return String(r.stdout).trim() || '(empty)';
|
|
113
|
+
}
|
|
114
|
+
catch (e) {
|
|
115
|
+
return '(hdc error: ' + String(e).slice(0, 60) + ')';
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
if (action === 'status') {
|
|
119
|
+
const launchExists = existsSync(q.launchPath);
|
|
120
|
+
const qemuRunning = await (async () => {
|
|
121
|
+
try {
|
|
122
|
+
const out = await execCb('powershell.exe', ['-NoProfile', '-Command', `(Get-CimInstance Win32_Process -Filter "Name='qemu-system-x86_64.exe'" | Measure-Object).Count`], { timeout: 10000, windowsHide: true });
|
|
123
|
+
return Number(String(out.stdout).trim()) > 0;
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
})();
|
|
129
|
+
const targets = await hdcTargets();
|
|
130
|
+
const connected = targets.includes(target);
|
|
131
|
+
return {
|
|
132
|
+
output: [
|
|
133
|
+
`KaihongOS QEMU @ ${q.dir}`,
|
|
134
|
+
` launch script: ${q.launchPath} ${launchExists ? '(present)' : '(MISSING)'}`,
|
|
135
|
+
` qemu process: ${qemuRunning ? 'RUNNING' : 'stopped'}`,
|
|
136
|
+
` hdc target ${target}: ${connected ? 'CONNECTED' : 'not connected'} (all targets: ${targets.split('\n').filter(Boolean).join(', ') || 'none'})`,
|
|
137
|
+
` vnc: 127.0.0.1:${5900 + q.vncDisplay} · qmp: 22472 · hmp: 22471 · serial log: ${join(q.dir, 'kaihong-serial.log')}`,
|
|
138
|
+
qemuRunning && !connected ? ' next: action=connect' : !qemuRunning ? ' next: action=start' : '',
|
|
139
|
+
].filter(Boolean).join('\n'),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
if (action === 'start') {
|
|
143
|
+
if (!existsSync(q.launchPath)) {
|
|
144
|
+
return { output: `launch script not found: ${q.launchPath}`, isError: true };
|
|
145
|
+
}
|
|
146
|
+
// detach: the cmd blocks until QEMU exits - spawn, never await it
|
|
147
|
+
const child = spawn('cmd.exe', ['/c', q.launchPath], { cwd: q.dir, detached: true, stdio: 'ignore', windowsHide: false });
|
|
148
|
+
child.unref();
|
|
149
|
+
// wait for the forward port to accept, then hdc tconn
|
|
150
|
+
let up = false;
|
|
151
|
+
for (let i = 0; i < 60 && !up; i++) {
|
|
152
|
+
await new Promise((r) => setTimeout(r, 2000));
|
|
153
|
+
up = await new Promise((resolve) => {
|
|
154
|
+
const s = net.connect({ host: '127.0.0.1', port: q.hdcPort, timeout: 1200 }, () => { s.destroy(); resolve(true); });
|
|
155
|
+
s.on('error', () => resolve(false));
|
|
156
|
+
s.on('timeout', () => { s.destroy(); resolve(false); });
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
if (!up) {
|
|
160
|
+
return { output: `QEMU started but port ${q.hdcPort} never opened (guest hdcd may be down - watch the serial log: ${join(q.dir, 'kaihong-serial.log')})`, isError: true };
|
|
161
|
+
}
|
|
162
|
+
if (!hdc)
|
|
163
|
+
return { output: `QEMU up, port ${q.hdcPort} open - but hdc not found; connect manually: hdc tconn ${target}` };
|
|
164
|
+
try {
|
|
165
|
+
await execCb(hdc, ['tconn', target], { timeout: 15000, windowsHide: true });
|
|
166
|
+
return { output: `QEMU started and hdc connected: ${target}. Verify with harmony_devices.` };
|
|
167
|
+
}
|
|
168
|
+
catch (e) {
|
|
169
|
+
return { output: `QEMU up but hdc tconn failed: ${String(e).slice(0, 120)}`, isError: true };
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (action === 'stop') {
|
|
173
|
+
// graceful: QMP quit via telnet-ish raw socket (qmp is a telnet server)
|
|
174
|
+
const stopped = await new Promise((resolve) => {
|
|
175
|
+
const s = net.connect({ host: '127.0.0.1', port: 22472, timeout: 4000 }, () => {
|
|
176
|
+
s.write(JSON.stringify({ execute: 'qmp_capabilities' }) + '\r\n');
|
|
177
|
+
setTimeout(() => s.write(JSON.stringify({ execute: 'quit' }) + '\r\n'), 400);
|
|
178
|
+
setTimeout(() => { s.destroy(); resolve(true); }, 2500);
|
|
179
|
+
});
|
|
180
|
+
s.on('error', () => resolve(false));
|
|
181
|
+
s.on('timeout', () => { s.destroy(); resolve(false); });
|
|
182
|
+
});
|
|
183
|
+
if (stopped) {
|
|
184
|
+
// also drop the hdc target so status is honest
|
|
185
|
+
if (hdc)
|
|
186
|
+
await execCb(hdc, ['tdisconn', target], { timeout: 8000, windowsHide: true }).catch(() => undefined);
|
|
187
|
+
return { output: 'QMP quit sent - QEMU stopping (graceful).' };
|
|
188
|
+
}
|
|
189
|
+
return { output: 'QMP not reachable (QEMU not running or port 22472 closed). Nothing to stop.', isError: true };
|
|
190
|
+
}
|
|
191
|
+
if (action === 'connect') {
|
|
192
|
+
if (!hdc)
|
|
193
|
+
return { output: 'hdc not found', isError: true };
|
|
194
|
+
try {
|
|
195
|
+
await execCb(hdc, ['tconn', target], { timeout: 15000, windowsHide: true });
|
|
196
|
+
return { output: `hdc connected: ${target}` };
|
|
197
|
+
}
|
|
198
|
+
catch (e) {
|
|
199
|
+
return { output: `hdc tconn failed (is QEMU running? action=start first): ${String(e).slice(0, 120)}`, isError: true };
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return { output: 'action must be status | start | stop | connect', isError: true };
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
/* ---------------- VMware tool ---------------- */
|
|
206
|
+
/** Parse `vmrun list` output into vmx paths. Pure - testable. */
|
|
207
|
+
export function parseVmrunList(out) {
|
|
208
|
+
return out.split(/\r?\n/).map((l) => l.trim()).filter((l) => l.toLowerCase().endsWith('.vmx'));
|
|
209
|
+
}
|
|
210
|
+
export const vmwareVmsTool = {
|
|
211
|
+
name: 'vmware_vms',
|
|
212
|
+
description: 'VMware Workstation VM lifecycle via vmrun: list (running + registered), start/stop/suspend a VM by name or .vmx path, ip (getGuestIPAddress), run a program in the guest. Actions: list (default) | start | stop | suspend | ip | guest-run. Remote shell access to guests is the sshHosts config (web SSH panel), not this tool.',
|
|
213
|
+
parameters: {
|
|
214
|
+
type: 'object',
|
|
215
|
+
properties: {
|
|
216
|
+
action: { type: 'string', description: 'list | start | stop | suspend | ip | guest-run' },
|
|
217
|
+
vm: { type: 'string', description: 'VM name or absolute .vmx path (list under D:/VMs)' },
|
|
218
|
+
guestCmd: { type: 'string', description: 'for guest-run: command line to run inside the guest (requires VMware Tools)' },
|
|
219
|
+
sshKey: { type: 'string', description: 'for check: path to the SSH key (default ~/.ssh/vm_maintenance_ed25519)' },
|
|
220
|
+
},
|
|
221
|
+
required: [],
|
|
222
|
+
},
|
|
223
|
+
needsApproval(args) {
|
|
224
|
+
const a = String(args?.action ?? 'list');
|
|
225
|
+
return a === 'start' || a === 'stop' || a === 'suspend' || a === 'guest-run';
|
|
226
|
+
},
|
|
227
|
+
async execute(args) {
|
|
228
|
+
const action = String(args?.action ?? 'list');
|
|
229
|
+
const raw = (await import('@hmharness/kernel')).loadConfig;
|
|
230
|
+
const cfg = await raw().catch(() => ({}));
|
|
231
|
+
const { vmrun, vmDirs } = resolveVmrun(cfg.vm?.vmware);
|
|
232
|
+
if (!existsSync(vmrun)) {
|
|
233
|
+
return { output: `vmrun not found at ${vmrun} - set vm.vmware.vmrun in config.json`, isError: true };
|
|
234
|
+
}
|
|
235
|
+
const runVm = async (vmArgs) => {
|
|
236
|
+
const r = await execCb(vmrun, vmArgs, { timeout: 120000, windowsHide: true, maxBuffer: 4 * 1024 * 1024 });
|
|
237
|
+
return (String(r.stdout) + (r.stderr ? '\n[stderr]\n' + r.stderr : '')).trim() || '(no output)';
|
|
238
|
+
};
|
|
239
|
+
const listAll = async () => {
|
|
240
|
+
const out = await runVm(['list']);
|
|
241
|
+
const running = parseVmrunList(out);
|
|
242
|
+
const registered = [];
|
|
243
|
+
for (const dir of vmDirs) {
|
|
244
|
+
try {
|
|
245
|
+
for (const e of await readdir(dir, { withFileTypes: true })) {
|
|
246
|
+
if (!e.isDirectory())
|
|
247
|
+
continue;
|
|
248
|
+
try {
|
|
249
|
+
const inner = await readdir(join(dir, e.name));
|
|
250
|
+
for (const f of inner)
|
|
251
|
+
if (f.toLowerCase().endsWith('.vmx'))
|
|
252
|
+
registered.push(join(dir, e.name, f));
|
|
253
|
+
}
|
|
254
|
+
catch { /* unreadable */ }
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
catch { /* dir gone */ }
|
|
258
|
+
}
|
|
259
|
+
return { out, running, registered };
|
|
260
|
+
};
|
|
261
|
+
// resolve a VM name -> vmx path from the dirs
|
|
262
|
+
const resolveVmx = async (name) => {
|
|
263
|
+
if (name.toLowerCase().endsWith('.vmx') && existsSync(name))
|
|
264
|
+
return name;
|
|
265
|
+
const { registered } = await listAll();
|
|
266
|
+
const hit = registered.find((p) => p.toLowerCase().includes(name.toLowerCase()));
|
|
267
|
+
if (!hit)
|
|
268
|
+
throw new Error(`no .vmx matching "${name}" under ${vmDirs.join(', ')} - pass the full path`);
|
|
269
|
+
return hit;
|
|
270
|
+
};
|
|
271
|
+
try {
|
|
272
|
+
if (action === 'list') {
|
|
273
|
+
const { out, running, registered } = await listAll();
|
|
274
|
+
const lines = [out, '', 'discovered .vmx files:'];
|
|
275
|
+
for (const p of registered)
|
|
276
|
+
lines.push(` ${running.some((r) => r.toLowerCase() === p.toLowerCase()) ? '[running]' : '[off] '} ${p}`);
|
|
277
|
+
return { output: lines.join('\n') };
|
|
278
|
+
}
|
|
279
|
+
if (action === 'check') {
|
|
280
|
+
// per-OS dev-environment readiness over SSH (BatchMode + maintenance
|
|
281
|
+
// key). Read-only probes; unreachable VMs are reported, not errors.
|
|
282
|
+
const key = String(args?.sshKey ?? join(process.env.USERPROFILE ?? '', '.ssh', 'vm_maintenance_ed25519'));
|
|
283
|
+
const vms = [
|
|
284
|
+
{ name: 'Ubuntu 26.04', host: '192.168.161.128', user: 'hongfu' },
|
|
285
|
+
{ name: 'Kali 2026.2', host: '192.168.161.129', user: 'kali' },
|
|
286
|
+
{ name: 'Win10 Fresh', host: '192.168.161.133', user: 'hongfu2' },
|
|
287
|
+
{ name: 'Win11 Fresh', host: '192.168.161.132', user: 'hongfu1' },
|
|
288
|
+
{ name: 'Omarchy 4.0.4', host: '192.168.161.136', user: 'hongfu' },
|
|
289
|
+
];
|
|
290
|
+
const probe = 'uname -a 2>/dev/null || ver; echo ---; node -v 2>/dev/null || echo no-node; python3 --version 2>/dev/null || echo no-python3; which hdc ohpm hvigorw 2>/dev/null || echo no-hmony-tools';
|
|
291
|
+
const lines = ['VM dev-environment check (SSH BatchMode, key ' + key + '):'];
|
|
292
|
+
for (const vm of vms) {
|
|
293
|
+
let out;
|
|
294
|
+
try {
|
|
295
|
+
const r = await execCb('ssh', [
|
|
296
|
+
'-o', 'BatchMode=yes', '-o', 'ConnectTimeout=8', '-o', 'StrictHostKeyChecking=accept-new',
|
|
297
|
+
'-i', key, vm.user + '@' + vm.host, probe,
|
|
298
|
+
], { timeout: 25000, windowsHide: true, maxBuffer: 1024 * 1024 });
|
|
299
|
+
out = String(r.stdout).trim();
|
|
300
|
+
}
|
|
301
|
+
catch (e) {
|
|
302
|
+
const err = String(e.stdout || e.stderr || e.message || '');
|
|
303
|
+
lines.push(' [' + vm.name + '] ' + vm.user + '@' + vm.host + ' — UNREACHABLE (' + err.split('\n')[0].slice(0, 60) + ')');
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
const os = out.split('---')[0]?.split('\n')[0]?.trim() || '?';
|
|
307
|
+
const parts = out.split('---')[1]?.trim().split('\n').filter(Boolean) ?? [];
|
|
308
|
+
lines.push(' [' + vm.name + '] ' + vm.user + '@' + vm.host + ' — OK');
|
|
309
|
+
lines.push(' os: ' + os.slice(0, 90));
|
|
310
|
+
for (const p of parts)
|
|
311
|
+
lines.push(' ' + p.trim().slice(0, 90));
|
|
312
|
+
}
|
|
313
|
+
return { output: lines.join('\n') };
|
|
314
|
+
}
|
|
315
|
+
if (!args?.vm)
|
|
316
|
+
return { output: 'vm required (name or .vmx path)', isError: true };
|
|
317
|
+
const vmx = await resolveVmx(String(args.vm));
|
|
318
|
+
if (action === 'start') {
|
|
319
|
+
const out = await runVm(['-T', 'ws', 'start', vmx, 'nogui']);
|
|
320
|
+
return { output: `started (headless): ${vmx}\n${out}\nget the IP next: action=ip` };
|
|
321
|
+
}
|
|
322
|
+
if (action === 'stop') {
|
|
323
|
+
const out = await runVm(['-T', 'ws', 'stop', vmx, 'soft']);
|
|
324
|
+
return { output: `stop requested: ${vmx}\n${out}` };
|
|
325
|
+
}
|
|
326
|
+
if (action === 'suspend') {
|
|
327
|
+
const out = await runVm(['-T', 'ws', 'suspend', vmx]);
|
|
328
|
+
return { output: `suspend requested: ${vmx}\n${out}` };
|
|
329
|
+
}
|
|
330
|
+
if (action === 'ip') {
|
|
331
|
+
const out = await runVm(['-T', 'ws', 'getGuestIPAddress', vmx, '-wait']);
|
|
332
|
+
return { output: `guest IP: ${out}` };
|
|
333
|
+
}
|
|
334
|
+
if (action === 'guest-run') {
|
|
335
|
+
if (!args?.guestCmd)
|
|
336
|
+
return { output: 'guestCmd required for guest-run', isError: true };
|
|
337
|
+
const out = await runVm(['-T', 'ws', '-gu', 'ubuntu', '-gp', '123456', 'runProgramInGuest', vmx, String(args.guestCmd)]);
|
|
338
|
+
return { output: out };
|
|
339
|
+
}
|
|
340
|
+
return { output: 'action must be list | start | stop | suspend | ip | guest-run | check', isError: true };
|
|
341
|
+
}
|
|
342
|
+
catch (e) {
|
|
343
|
+
return { output: String(e).slice(0, 300), isError: true };
|
|
344
|
+
}
|
|
345
|
+
},
|
|
346
|
+
};
|
|
347
|
+
export const vmTools = [harmonyVmQemuTool, vmwareVmsTool];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hmharness/domain-harmony",
|
|
3
|
-
"version": "0.13.
|
|
3
|
+
"version": "0.13.6",
|
|
4
4
|
"description": "hmharness HarmonyOS domain core: device, toolchain, build, and project lifecycle capabilities. HarmonyOS is the framework's native domain, not an add-on.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|