2019-09-02 09:30



When I defining new domain

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

xml looks like:

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

go-libvirt makes a new persistent domain. But this domain is shutted down.

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

In source code https://github.com/libvirt/libvirt-go/blob/master/domain.go I didn't find solutions how can I run this domain with golang ?

Thank you

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答


  • doukenqiong0588 doukenqiong0588 2年前

    You need to use the Create method on the Domain object that is returned from DomainDefineXMLFlags. For example

    dom, err := v.conn.DomainDefineXMLFlags(domainXml, libvirt.DOMAIN_DEFINE_VALIDATE)
    if err != nil {
        return err
    err = dom.Create()
    if err != nil {
        return err
    点赞 评论 复制链接分享