gpt4 book ai didi

go - libvirt-go 启动域

转载 作者:数据小太阳 更新时间:2023-10-29 03:08:04 27 4
gpt4 key购买 nike

当我定义新域时

_, err = v.conn.DomainDefineXMLFlags(domainXml, libvirt.DOMAIN_DEFINE_VALIDATE)

xml 看起来像:

<domain type='kvm'>
<name>{{.name}}</name>
<memory unit='KiB'>{{.memory}}</memory>
<currentMemory unit='KiB'>{{.current_memory}}</currentMemory>
<vcpu>{{.count_cpu}}</vcpu>
<os>
<type arch='x86_64' machine='pc-i440fx-disco'>hvm</type>
<boot dev='hd'/>
</os>
<clock offset='utc'/>
<on_poweroff>destroy</on_poweroff>
<on_reboot>restart</on_reboot>
<on_crash>destroy</on_crash>
<devices>
<emulator>/usr/bin/kvm-spice</emulator>
<disk type='block' device='disk'>
<driver name='qemu' type='raw' cache='none'/>
<source dev='{{.lvm_path}}'/>
<target dev='vda' bus='virtio'/>
</disk>
<disk type='file' device='cdrom'>
<driver name='qemu' type='raw'/>
<source file='{{.config_file}}'/>
<target dev='sda' bus='sata'/>
<readonly/>
<address type='drive' controller='0' bus='0' target='0' unit='0'/>
</disk>
<interface type='bridge'>
<source bridge='virbr0'/>
<model type='virtio'/>
<mac address='{{.mac_address}}'/>
</interface>
<serial type='pty'>
<target port='0'/>
</serial>
<console type='pty'>
<target type='serial' port='0'/>
</console>
</devices>
</domain>

go-libvirt 创建了一个新的持久域。但是这个域已关闭。

$ virsh list --all
Id Name State
---------------------------
- new_domain shut off

在源代码中https://github.com/libvirt/libvirt-go/blob/master/domain.go我没有找到解决方案,如何使用 golang 运行这个域?

谢谢

最佳答案

您需要使用 CreateDomainDefineXMLFlags 返回的 Domain 对象上的方法。例如

dom, err := v.conn.DomainDefineXMLFlags(domainXml, libvirt.DOMAIN_DEFINE_VALIDATE)
if err != nil {
return err
}
err = dom.Create()
if err != nil {
return err
}

关于go - libvirt-go 启动域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57754525/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com