Merge pull request #19 from digitalocean/capabilities

Adds Capabilities()
This commit is contained in:
Ben LeMasurier 2016-12-01 14:19:01 -07:00 committed by GitHub
commit 953e83ac30
3 changed files with 48 additions and 0 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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))