Adds Capabilities()
This adds a new method, Capabilities(), which returns an XML definition of the hypervisor's system capabilities, much like `virsh capabilities`. I've only included integration tests for these two methods due to the large amount of data returned by the capabilities call.
This commit is contained in:
parent
311150f931
commit
5a1fe4c14a
@ -38,6 +38,7 @@ const (
|
|||||||
const (
|
const (
|
||||||
ProcConnectOpen = 1
|
ProcConnectOpen = 1
|
||||||
ProcConnectClose = 2
|
ProcConnectClose = 2
|
||||||
|
ProcConnectGetCapabilties = 7
|
||||||
ProcDomainGetXMLDesc = 14
|
ProcDomainGetXMLDesc = 14
|
||||||
ProcDomainLookupByName = 23
|
ProcDomainLookupByName = 23
|
||||||
ProcAuthList = 66
|
ProcAuthList = 66
|
||||||
|
18
libvirt.go
18
libvirt.go
@ -170,6 +170,24 @@ const (
|
|||||||
DestroyFlagGraceful
|
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.
|
// Connect establishes communication with the libvirt server.
|
||||||
// The underlying libvirt socket connection must be previously established.
|
// The underlying libvirt socket connection must be previously established.
|
||||||
func (l *Libvirt) Connect() error {
|
func (l *Libvirt) Connect() error {
|
||||||
|
@ -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) {
|
func TestXMLIntegration(t *testing.T) {
|
||||||
l := New(testConn(t))
|
l := New(testConn(t))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user