A simple, powerful CLI tool to spin up OpenIndiana virtual machines with QEMU
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add support for creating VM disk images with size option

+45
+45
main.ts
··· 12 12 memory: string; 13 13 drive?: string; 14 14 diskFormat: string; 15 + size?: string; 15 16 } 16 17 17 18 async function downloadIso(url: string, outputPath?: string): Promise<string> { ··· 112 113 return input; 113 114 } 114 115 116 + async function createDriveImageIfNeeded( 117 + { 118 + drive: path, 119 + diskFormat: format, 120 + size, 121 + }: Options, 122 + ): Promise<void> { 123 + if (await Deno.stat(path!).catch(() => false)) { 124 + console.log( 125 + chalk.yellowBright( 126 + `Drive image ${path} already exists, skipping creation.`, 127 + ), 128 + ); 129 + return; 130 + } 131 + 132 + const cmd = new Deno.Command("qemu-img", { 133 + args: ["create", "-f", format, path!, size!], 134 + stdin: "inherit", 135 + stdout: "inherit", 136 + stderr: "inherit", 137 + }); 138 + 139 + const status = await cmd.spawn().status; 140 + if (!status.success) { 141 + console.error(chalk.redBright("Failed to create drive image.")); 142 + Deno.exit(status.code); 143 + } 144 + 145 + console.log(chalk.greenBright(`Created drive image at ${path}`)); 146 + } 147 + 115 148 if (import.meta.main) { 116 149 await new Command() 117 150 .name("openindiana-up") ··· 138 171 default: "raw", 139 172 }, 140 173 ) 174 + .option( 175 + "--size <size:string>", 176 + "Size of the VM disk image (e.g., 20G)", 177 + { 178 + default: "20G", 179 + }, 180 + ) 141 181 .example( 142 182 "Default usage", 143 183 "openindiana-up", ··· 165 205 isoPath = await downloadIso(resolvedInput, options.output); 166 206 } 167 207 208 + if (options.drive) { 209 + await createDriveImageIfNeeded(options); 210 + } 211 + 168 212 await runQemu(isoPath, { 169 213 cpu: options.cpu, 170 214 memory: options.memory, 171 215 cpus: options.cpus, 172 216 drive: options.drive, 173 217 diskFormat: options.diskFormat, 218 + size: options.size, 174 219 }); 175 220 }) 176 221 .parse(Deno.args);