定制 coquibot/coqui-toolkit-libvirt 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

coquibot/coqui-toolkit-libvirt

Composer 安装命令:

composer require coquibot/coqui-toolkit-libvirt

包简介

Libvirt virtualization toolkit for Coqui — manage VMs, networks, snapshots, and GPU passthrough via virsh/virt-install

README 文档

README

Libvirt/KVM virtualization toolkit for Coqui. Wraps virsh, virt-install, and qemu-img to give agents full VM management capabilities including lifecycle control, disk management, virtual networking, GPU passthrough, shared folders, snapshots, and browser-based console access via noVNC.

Requirements

  • PHP 8.4+
  • libvirt (virsh, virt-install, virt-xml-validate)
  • QEMU/KVM (qemu-system-x86_64, qemu-img)
  • KVM kernel modules loaded (/dev/kvm accessible)
  • websockify (optional — for web console)
  • noVNC (optional — for browser-based console UI)

Installing Dependencies (Debian/Ubuntu)

# Core
sudo apt install libvirt-daemon-system qemu-kvm virtinst qemu-utils

# Web console (optional)
pip3 install websockify
sudo apt install novnc

Installation

composer require coquibot/coqui-toolkit-libvirt

When installed alongside Coqui, the toolkit is auto-discovered via Composer's extra.php-agents.toolkits — no manual registration needed.

Credentials

Key Description
LIBVIRT_URI Libvirt connection URI (default: qemu:///system). Set to qemu:///session for unprivileged access or qemu+ssh://user@host/system for remote hosts.

Set via the Coqui credentials tool or in your workspace .env:

LIBVIRT_URI=qemu:///system

Tools Provided

vm_lifecycle

Manage VM lifecycle — create, start, stop, reboot, destroy, delete, snapshot, restore.

Parameter Type Required Description
action enum Yes create, start, stop, force_stop, destroy, reboot, delete, suspend, resume, snapshot, restore, delete_snapshot, check_deps
name string * VM name. Required for all actions except check_deps.
memory integer No RAM in MiB (default: 2048). Used with create.
vcpus integer No Virtual CPUs (default: 2). Used with create.
disk_path string No Path to existing disk image. Used with create.
disk_size string No Disk size (e.g. 20G). Used with create when disk_path is not given.
iso string No Path to ISO for CD-ROM. Used with create for OS installation.
network string No Network name (default: default). Used with create.
os_variant string No OS variant hint (e.g. ubuntu22.04, win11). Used with create.
pci_devices array No PCI addresses for GPU passthrough (e.g. ["0000:06:00.0"]). Used with create.
shared_folders array No Shared folders: [{"host_path": "...", "mount_tag": "...", "driver": "9p"}]. Used with create.
boot_dev enum No Boot device: hd (default) or cdrom. Used with create.
snapshot_name string No Snapshot name. Used with snapshot, restore, delete_snapshot.
snapshot_description string No Snapshot description. Used with snapshot.
remove_storage boolean No Remove disk images when deleting. Used with delete.

vm_info

Query VM and host information.

Parameter Type Required Description
action enum Yes info, list, domxml, hardware, snapshots
name string * VM name. Required for info, domxml, snapshots.
all boolean No Include all VM states. Default: true. Used with list.

vm_console

Manage web console access to VMs via noVNC + websockify.

Parameter Type Required Description
action enum Yes open, close, status
name string Yes VM name.
ws_port integer No WebSocket port (auto-detected from 6080 if omitted). Used with open.

vm_network

Manage libvirt virtual networks.

Parameter Type Required Description
action enum Yes create, start, stop, destroy, list, info
name string * Network name. Required for all actions except list.
type enum No nat (default), isolated, bridged. Used with create.
subnet string No CIDR subnet (e.g. 192.168.100.0/24). Used with create.
bridge string No Bridge interface name. Required when type is bridged.
dhcp boolean No Enable DHCP. Default: true. Used with create.
autostart boolean No Auto-start on host boot. Default: true. Used with create.

vm_storage

Manage disk images, shared folders, and GPU passthrough.

Parameter Type Required Description
action enum Yes create_disk, disk_info, resize_disk, attach_disk, shared_folder, gpu_passthrough
path string No Disk image path. Used with create_disk, disk_info, resize_disk, attach_disk.
size string No Disk size (e.g. 20G, +10G). Used with create_disk, resize_disk.
format enum No qcow2 (default), raw, vmdk, vdi. Used with create_disk.
name string No VM name. Used with attach_disk, shared_folder.
target string No Target device (e.g. vdb). Used with attach_disk.
host_path string No Host directory to share. Used with shared_folder.
mount_tag string No Mount tag for shared filesystem. Used with shared_folder.
driver enum No 9p (default, wider compat) or virtiofs (faster). Used with shared_folder.
sub_action enum No list_gpus, check_iommu, iommu_group. Used with gpu_passthrough.
pci_address string No PCI address (e.g. 0000:06:00.0). Used with iommu_group sub-action.

Agent Workflow

Creating a VM

1. vm_lifecycle  action: check_deps          → verify system requirements
2. vm_storage    action: create_disk          → create a qcow2 disk image
3. vm_network    action: create               → create a virtual network (or use "default")
4. vm_lifecycle  action: create               → define the VM with CPU, RAM, disk, network, ISO
5. vm_lifecycle  action: start                → boot the VM
6. vm_console    action: open                 → get a noVNC URL for browser-based console

Shared Folders (9p)

Mount a host directory inside the guest:

vm_storage  action: shared_folder  name: my-vm  host_path: /data/shared  mount_tag: hostshare

Inside the guest:

mount -t 9p -o trans=virtio hostshare /mnt/shared

GPU Passthrough

1. vm_storage  action: gpu_passthrough  sub_action: check_iommu    → verify IOMMU/VFIO
2. vm_storage  action: gpu_passthrough  sub_action: list_gpus      → find GPU PCI addresses
3. vm_storage  action: gpu_passthrough  sub_action: iommu_group    → check IOMMU group isolation
4. vm_lifecycle action: create ... pci_devices: ["0000:06:00.0"]   → create VM with GPU attached

Prerequisites: IOMMU enabled in BIOS + kernel (intel_iommu=on or amd_iommu=on), GPU bound to vfio-pci driver.

Snapshots

vm_lifecycle  action: snapshot         name: my-vm  snapshot_name: before-update
vm_lifecycle  action: restore          name: my-vm  snapshot_name: before-update
vm_lifecycle  action: delete_snapshot  name: my-vm  snapshot_name: before-update
vm_info       action: snapshots        name: my-vm

Standalone Usage

<?php

declare(strict_types=1);

use CoquiBot\Toolkits\Libvirt\LibvirtToolkit;

require __DIR__ . '/vendor/autoload.php';

$toolkit = LibvirtToolkit::fromEnv();

foreach ($toolkit->tools() as $tool) {
    echo $tool->name() . ': ' . $tool->description() . PHP_EOL;
}

// Check system dependencies
$lifecycle = $toolkit->tools()[0];
$result = $lifecycle->execute(['action' => 'check_deps']);
echo $result->content;

Architecture

The toolkit wraps CLI tools rather than using PHP libvirt bindings (which are abandoned/minimal):

Class Purpose
VirshRunner Core CLI wrapper — virsh, virt-install, qemu-img via proc_open()
HardwareDiscovery Host hardware detection — GPUs, IOMMU, CPU, RAM via sysfs/procfs
ConsoleProxyRunner noVNC + websockify background process manager
DependencyChecker System dependency verification
DomainXmlBuilder Fluent immutable builder for libvirt domain XML
NetworkXmlBuilder Fluent builder for libvirt network XML
VmStateStore SQLite-backed metadata persistence

Development

git clone https://github.com/AgentCoqui/coqui-toolkit-libvirt.git
cd coqui-toolkit-libvirt
composer install

Run tests

./vendor/bin/pest

Static analysis

./vendor/bin/phpstan analyse

License

MIT

coquibot/coqui-toolkit-libvirt 适用场景与选型建议

coquibot/coqui-toolkit-libvirt 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「toolkit」 「Virtualization」 「KVM」 「libvirt」 「qemu」 「php-agents」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 coquibot/coqui-toolkit-libvirt 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 coquibot/coqui-toolkit-libvirt 我们能提供哪些服务?
定制开发 / 二次开发

基于 coquibot/coqui-toolkit-libvirt 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 39
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-08