diff --git a/internal/constants/constants.go b/internal/constants/constants.go index 5c9532d..4621ee6 100644 --- a/internal/constants/constants.go +++ b/internal/constants/constants.go @@ -38,6 +38,7 @@ const ( const ( ProcConnectOpen = 1 ProcConnectClose = 2 + ProcConnectGetCapabilties = 7 ProcDomainGetXMLDesc = 14 ProcDomainLookupByName = 23 ProcAuthList = 66 diff --git a/libvirt.go b/libvirt.go index 784c1bc..fb3be48 100644 --- a/libvirt.go +++ b/libvirt.go @@ -170,6 +170,24 @@ const ( DestroyFlagGraceful ) +// Capabilities returns an XML document describing the host's capabilties. +func (l *Libvirt) Capabilities() ([]byte, error) { + resp, err := l.request(constants.ProcConnectGetCapabilties, constants.ProgramRemote, nil) + if err != nil { + return nil, err + } + + r := <-resp + if r.Status != StatusOK { + return nil, decodeError(r.Payload) + } + + dec := xdr.NewDecoder(bytes.NewReader(r.Payload)) + caps, _, err := dec.DecodeString() + + return []byte(caps), err +} + // Connect establishes communication with the libvirt server. // The underlying libvirt socket connection must be previously established. func (l *Libvirt) Connect() error { diff --git a/libvirt_integration_test.go b/libvirt_integration_test.go index c1ce894..8079a69 100644 --- a/libvirt_integration_test.go +++ b/libvirt_integration_test.go @@ -41,6 +41,35 @@ func TestDisconnectIntegration(t *testing.T) { } } +func TestCapabilities(t *testing.T) { + l := New(testConn(t)) + defer l.Disconnect() + + if err := l.Connect(); err != nil { + t.Fatal(err) + } + + resp, err := l.Capabilities() + if err != nil { + t.Fatal(err) + } + + // verify UUID exists within returned XML + var caps struct { + Host struct { + UUID string `xml:"uuid"` + } `xml:"host"` + } + + if err := xml.Unmarshal(resp, &caps); err != nil { + t.Fatal(err) + } + + if caps.Host.UUID == "" { + t.Error("expected capabilities to contain a UUID") + } +} + func TestXMLIntegration(t *testing.T) { l := New(testConn(t))