summaryrefslogtreecommitdiff
path: root/libvirt/qemu_agent.go
diff options
context:
space:
mode:
Diffstat (limited to 'libvirt/qemu_agent.go')
-rw-r--r--libvirt/qemu_agent.go25
1 files changed, 14 insertions, 11 deletions
diff --git a/libvirt/qemu_agent.go b/libvirt/qemu_agent.go
index fd7cef39..7f3ca7a4 100644
--- a/libvirt/qemu_agent.go
+++ b/libvirt/qemu_agent.go
@@ -10,6 +10,9 @@ import (
libvirt "github.com/libvirt/libvirt-go"
)
+const qemuGetIfaceWait = "qemu-agent-wait"
+const qemuGetIfaceDone = "qemu-agent-done"
+
// QemuAgentInterfacesResponse type
type QemuAgentInterfacesResponse struct {
Interfaces []QemuAgentInterface `json:"return"`
@@ -29,19 +32,19 @@ type QemuAgentInterfaceIPAddress struct {
Prefix uint `json:"prefix"`
}
-func qemuAgentInterfacesRefreshFunc(domain LibVirtDomain, wait4ipv4 bool) resource.StateRefreshFunc {
+func qemuAgentInterfacesRefreshFunc(domain Domain, wait4ipv4 bool) resource.StateRefreshFunc {
return func() (interface{}, string, error) {
var interfaces []libvirt.DomainInterface
- log.Printf("[DEBUG] sending command to qemu-agent in %s", domain)
+ log.Printf("[DEBUG] sending command to qemu-agent")
result, err := domain.QemuAgentCommand(
"{\"execute\":\"guest-network-get-interfaces\"}",
libvirt.DOMAIN_QEMU_AGENT_COMMAND_DEFAULT,
0)
if err != nil {
log.Printf("[DEBUG] command error: %s", err)
- return interfaces, "failed", nil
+ return interfaces, qemuGetIfaceWait, nil
}
log.Printf("[DEBUG] qemu-agent response: %s", result)
@@ -49,9 +52,9 @@ func qemuAgentInterfacesRefreshFunc(domain LibVirtDomain, wait4ipv4 bool) resour
response := QemuAgentInterfacesResponse{}
if err := json.Unmarshal([]byte(result), &response); err != nil {
log.Printf("[DEBUG] Error converting qemu-agent response about domain interfaces: %s", err)
- log.Printf("[DEBUG] Original message: %s", response)
+ log.Printf("[DEBUG] Original message: %+v", response)
log.Print("[DEBUG] Returning an empty list of interfaces")
- return interfaces, "fatal", nil
+ return interfaces, "", nil
}
log.Printf("[DEBUG] Parsed response %+v", response)
@@ -66,7 +69,7 @@ func qemuAgentInterfacesRefreshFunc(domain LibVirtDomain, wait4ipv4 bool) resour
Hwaddr: iface.Hwaddr}
ipv4Assigned := false
- for _, addr := range iface.IpAddresses {
+ for _, addr := range iface.IPAddresses {
if addr.Address == "" {
// ignore interfaces without an address (eg. waiting for dhcp lease)
continue
@@ -95,7 +98,7 @@ func qemuAgentInterfacesRefreshFunc(domain LibVirtDomain, wait4ipv4 bool) resour
}
log.Printf("[DEBUG] Interfaces obtained via qemu-agent: %+v", interfaces)
- return interfaces, "success", nil
+ return interfaces, qemuGetIfaceDone, nil
}
}
@@ -104,15 +107,15 @@ func qemuAgentInterfacesRefreshFunc(domain LibVirtDomain, wait4ipv4 bool) resour
// When wait4ipv4 is turned on the code will not report interfaces that don't
// have a ipv4 address set. This is useful when a domain gets the ipv6 address
// before the ipv4 one.
-func getDomainInterfacesViaQemuAgent(domain LibVirtDomain, wait4ipv4 bool) []libvirt.DomainInterface {
+func qemuAgentGetInterfacesInfo(domain Domain, wait4ipv4 bool) []libvirt.DomainInterface {
qemuAgentQuery := &resource.StateChangeConf{
- Pending: []string{"failed"},
- Target: []string{"success"},
+ Pending: []string{qemuGetIfaceWait},
+ Target: []string{qemuGetIfaceDone},
Refresh: qemuAgentInterfacesRefreshFunc(domain, wait4ipv4),
MinTimeout: 4 * time.Second,
Delay: 4 * time.Second, // Wait this time before starting checks
- Timeout: 16 * time.Second,
+ Timeout: 30 * time.Second,
}
interfaces, err := qemuAgentQuery.WaitForState()