Storage
Manage storage pools with PoolConf and volumes with VolumeConf instead of hand-written XML. virsh remains the transport; XML parsing and serialization use Bun.XML, so @sysopkit/libvirt only runs on the Bun runtime.
import { buildPool, createVolume, definePool, deleteVolume, destroyPool, getPool, getVolumeInfo, listPools, listVolumes, setPoolAutostart, startPool, undefinePool,} from '@sysopkit/libvirt/storage';IDEMPOTENT
Only dir pools are modeled. Defining compares virsh pool-dumpxml output field-by-field and redefines only on drift; other pool types use the raw XML path (definePool({ name, xml, update })).
await definePool({ pool: { name: 'default', path: '/var/lib/libvirt/images' } });await buildPool({ name: 'default' }); // creates the target dir, no-op when builtawait startPool({ name: 'default' }); // true when it was startedawait setPoolAutostart({ name: 'default', autostart: true });await destroyPool({ name: 'default' }); // no-op when inactiveawait undefinePool({ name: 'default' }); // no-op when not definedconst pools = await listPools();// [{ name: 'default', active: true, autostart: true }, ...]
const conf = await getPool({ name: 'default' }); // normalized PoolConfconst info = await getPoolInfo({ name: 'default' });// { name, active, autostart, persistent }Volumes
Section titled “Volumes”IDEMPOTENT
await createVolume({ pool: 'default', volume: { name: 'guest.qcow2', capacityMiB: 20480 },});
await createVolume({ pool: 'default', volume: { name: 'overlay.qcow2', capacityMiB: 10240, backingPath: '/var/lib/libvirt/images/base.qcow2', },});
await deleteVolume({ pool: 'default', name: 'overlay.qcow2' }); // no-op when absentcreateVolume() is a no-op when a volume with the same name, capacity, and format already exists, and throws when the existing volume differs (volumes cannot be resized in place through this API — delete first).
const volumes = await listVolumes({ pool: 'default' }); // ['guest.qcow2', ...]const vol = await getVolumeInfo({ pool: 'default', name: 'guest.qcow2' });// { name, capacityMiB, format, path }All operations accept an optional connection URI ({ uri: 'qemu:///system' }). When omitted, the virsh default connection is used.
Configuration types
Section titled “Configuration types”import type { PoolConf, PoolInfo, VolumeConf, VolumeInfo } from '@sysopkit/libvirt/storage';import { poolConfigMatches, serializePoolXml, serializeVolumeXml } from '@sysopkit/libvirt/storage';import { parsePoolXml, parseVolumeInfo } from '@sysopkit/libvirt/storage';serializePoolXml(conf)/parsePoolXml(xml)— build and read pool XML.serializeVolumeXml(volume)— build volume XML forvirsh vol-create;parseVolumeInfo(xml)readsvirsh vol-dumpxmloutput.poolConfigMatches(current, desired)— the drift check used bydefinePool().parsePoolList(output)/parsePoolInfo(output)/parseVolumeList(output)— parsevirsh pool-list/pool-info/vol-listoutput.