Merge pull request #19 from digitalocean/capabilities
Adds Capabilities()
This commit is contained in:
commit
953e83ac30
@ -38,6 +38,7 @@ const (
|
||||
const (
|
||||
ProcConnectOpen = 1
|
||||
ProcConnectClose = 2
|
||||
ProcConnectGetCapabilties = 7
|
||||
ProcDomainGetXMLDesc = 14
|
||||
ProcDomainLookupByName = 23
|
||||
ProcAuthList = 66
|
||||
|
18
libvirt.go
18
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 {
|
||||
|
@ -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))
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user