Home > Backend Development > Golang > Golang libvirt guest-agent is not available

Golang libvirt guest-agent is not available

WBOY
Release: 2024-02-09 20:48:19
forward
793 people have browsed it

Golang libvirt guest-agent 不可用

php editor Youzi found that recently some users reported that they encountered unavailability problems when using libvirt guest-agent in Golang. libvirt guest-agent is part of the libvirt library and is used to communicate with the guest operating system in a virtual machine. However, some users have experienced connectivity issues or functionality glitches when trying to use it. This is a frustrating issue for developers who rely on libvirt guest-agent for virtual machine management and monitoring. Next, we'll explore possible causes and solutions to help resolve this issue.

Question content

I am trying to communicate with a guest agent on a qemu instance via the libvirt golang api. However, it always refuses my connection to

2022-12-02t00:10:43.799+0100    dpanic  test/main.go:335    failed to connect to guest  {"error": "virerror(code=86, domain=10, message='guest agent is not responding: qemu guest agent is not connected')"}
Copy after login

Even if the qemu instance is fully started and the guest agent is accessible via the command line

sudo virsh qemu-agent-command test-vm '{"execute":"guest-info"}'
Copy after login

Is this a bug in the implementation or do I have to register the proxy somewhere in the go code? I can't find a reference in the documentation.

    <channel type='unix'>
      <source mode='bind' path='/var/lib/libvirt/qemu/channel/target/domain-6-test-vm/org.qemu.guest_agent.0'/>
      <target type='virtio' name='org.qemu.guest_agent.0' state='connected'/>
      <alias name='channel0'/>
      <address type='virtio-serial' controller='0' bus='0' port='1'/>
    </channel>
Copy after login

Thanks!

Solution

I don’t know what the final reason is. I have a loop and am accessing, or more specifically, trying to access a proxy. I changed it to use a timeout of 500ms but it didn't work.

type qemuStatusResponse struct {
    Return struct {
        Exitcode int    `json:"exitcode,omitempty"`
        OutData  string `json:"out-data,omitempty"`
        Exited   bool   `json:"exited,omitempty"`
        ErrData  string `json:"err-data,omitempty"`
    } `json:"return,omitempty"`
}

func (l *LibvirtInstance) waitForCompletion(ctx context.Context, pid int, domain *libvirt.Domain) (response *qemuStatusResponse, err error) {
    response = &qemuStatusResponse{}

    ticker := time.NewTicker(500 * time.Millisecond)
    defer ticker.Stop()
    for {
        select {
        case <-ticker.C:
            result, err := domain.QemuAgentCommand(
                fmt.Sprintf(`
                {
                    "execute": "guest-exec-status",
                    "arguments": {
                        "pid": %d
                    }
                    }`, pid),
                libvirt.DOMAIN_QEMU_AGENT_COMMAND_BLOCK, 0)
            if err != nil {
                return nil, err
            }
            if err := json.Unmarshal([]byte(result), response); err != nil {
                return nil, err
            }
            if response.Return.Exited {
                return response, nil
            }
        case <-ctx.Done():
            return nil, ctx.Err()
        }
    }
}
Copy after login

Additionally, I encountered some stability issues (i.e. when multiple concurrent requests were made to the connection, it would sometimes get corrupted). I found some articles online suggesting adding users to the kvm group. This works for me.

The above is the detailed content of Golang libvirt guest-agent is not available. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template