【问题标题】:Libvirt-go start domainlibvirt-go 启动域
【发布时间】:2019-09-02 09:30:02
【问题描述】:

当我定义新域时

_, 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 创建一个新的persistent domain。但是这个域被关闭了。

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

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

谢谢

【问题讨论】:

    标签: go libvirt


    【解决方案1】:

    您需要对从DomainDefineXMLFlags 返回的Domain 对象使用Create 方法。例如

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-10-15
      • 1970-01-01
      • 2018-01-08
      • 2021-02-22
      • 2013-07-13
      • 2021-09-18
      • 1970-01-01
      相关资源
      最近更新 更多