diff --git a/package.json b/package.json index c2b58f93..940d6254 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,10 @@ { "command": "bootc.image.build", "title": "Build Disk Image" + }, + { + "command": "bootc.vfkit", + "title": "Launch VM" } ] }, @@ -24,6 +28,10 @@ { "command": "bootc.image.build", "title": "Build bootable disk image" + }, + { + "command": "bootc.vfkit", + "title": "Launch VM" } ], "icons": { diff --git a/src/extension.ts b/src/extension.ts index 220dd9fe..3acb0226 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -32,9 +32,18 @@ export async function activate(extensionContext: ExtensionContext): Promise { + launchVfkit('/Users/cdrage/bootc/image/disk.raw'); + }), extensionApi.commands.registerCommand('bootc.image.build', async image => { - const selectedType = await extensionApi.window.showQuickPick(['qcow2', 'ami', 'iso'], { + const selectedType = await extensionApi.window.showQuickPick(['qcow2', 'ami', 'raw', 'iso'], { placeHolder: 'Select image type', }); if (!selectedType) { @@ -51,7 +60,18 @@ export async function activate(extensionContext: ExtensionContext): Promise setTimeout(r, 1000)); } + + successful = true; fs.writeFileSync(logPath, logData, {flag: 'w'}); } catch (error) { @@ -124,14 +150,96 @@ export async function activate(extensionContext: ExtensionContext): Promise { + const command = 'qemu-img'; + const args = ['convert', '-f', 'qcow2', '-O', 'raw', imagePath, imagePathOutput]; + console.log(args); + try { + await extensionApi.process.exec(command, args); + } catch (error) { + console.error(error); + await extensionApi.window.showErrorMessage(`Unable to convert ${imagePath} to raw: ${error}`); + } +} + +/* + +Use this command with process.exec to launch a passed in image path file within vfkit +vfkit --cpus 2 --memory 2048 \ + --bootloader efi,variable-store=./efi-variable-store,create \ + --device virtio-blk,path=bootc.img \ + --device virtio-serial,stdio \ + --device virtio-net,nat,mac=72:20:43:d4:38:62 \ + --device virtio-rng \ + --device virtio-input,keyboard \ + --device virtio-input,pointing \ + --device virtio-gpu,width=1920,height=1080 \ + --gui +*/ +async function launchVfkit(imagePath: string): Promise { + // take image path replace last part (disk.qcow2 / disk.raw) with vfkit-serial.log + // this will be the log file path + const logFilePath = imagePath.replace(/[^/]+$/, '') + 'vfkit-serial.log'; + const command = 'vfkit'; + const args = [ + '--cpus', + '2', + '--memory', + '2048', + '--bootloader', + 'efi,variable-store=./efi-variable-store,create', + '--device', + 'virtio-blk,path=' + imagePath, + '--device', + 'virtio-serial,logFilePath=' + logFilePath, + '--device', + 'virtio-net,nat,mac=72:20:43:d4:38:62', + '--device', + 'virtio-rng', + '--device', + 'virtio-input,keyboard', + '--device', + 'virtio-input,pointing', + '--device', + 'virtio-gpu,width=1920,height=1080', + '--gui', + ]; + console.log(args); + try { + await extensionApi.process.exec(command, args); + } catch (error) { + console.error(error); + await extensionApi.window.showErrorMessage(`Unable to launch ${imagePath} with vfkit: ${error}`); + } +} + async function removePreviousBuildImage(image) { // TODO: Ignore if the container doesn't exist try { @@ -170,6 +278,13 @@ async function pullBootcImageBuilderImage() { } async function createImage(image, type, folder: string) { + + // TEMPORARY UNTIL PR IS MERGED IN BOOTC-IMAGE-BUILDER + // If type is raw, change it to ami + if (type === 'raw') { + type = 'ami'; + } + console.log('Building ' + diskImageBuildingName + ' to ' + type); /*