dssnh86244 2019-09-02 09:30 采纳率: 100%
浏览 90
已采纳

Libvirt开始域

When I defining new domain

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

xml looks like:

<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 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

  • 写回答

1条回答 默认 最新

  • doukenqiong0588 2019-09-02 10:47
    关注

    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
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图