2024-08-23 07:01:21 -04:00
|
|
|
// A simple/contrived? example of how to use superqemu.
|
|
|
|
//
|
2024-07-16 07:59:02 -04:00
|
|
|
// Note that this example requires a valid desktop environment to function
|
|
|
|
// due to `-display gtk`, but you can remove it and run it headless.
|
2024-08-23 07:01:21 -04:00
|
|
|
//
|
|
|
|
// Also note that while superqemu automatically sets up QEMU to use VNC,
|
|
|
|
// it does not provide its own VNC client implementation.
|
2024-07-16 07:59:02 -04:00
|
|
|
|
2024-08-23 07:01:21 -04:00
|
|
|
import { QemuVM, VMState } from "../dist/index.js";
|
2024-07-16 07:59:02 -04:00
|
|
|
|
|
|
|
import pino from 'pino';
|
|
|
|
|
|
|
|
let logger = pino();
|
|
|
|
|
|
|
|
let vm = new QemuVM(
|
|
|
|
{
|
|
|
|
id: "testvm",
|
|
|
|
command: "qemu-system-x86_64 -M pc,hpet=off,accel=kvm -cpu host -m 512 -display gtk",
|
|
|
|
snapshot: true
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
|
|
|
vm.on('statechange', (newState) => {
|
|
|
|
logger.info(`state changed to ${newState}`);
|
2024-08-23 07:01:21 -04:00
|
|
|
if(newState == VMState.Started) {
|
|
|
|
logger.info(vm.GetDisplayInfo(), `VM started: display info prepends this message`);
|
|
|
|
}
|
2024-07-16 07:59:02 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
await vm.Start();
|
|
|
|
})();
|