Skip to content

Commit

Permalink
Merge pull request #61 from dmacvicar/dmacvicar-domain-LookupByUUIDSt…
Browse files Browse the repository at this point in the history
…ring

Add virDomainLookupByUUIDString (already available in 1.2.2)
  • Loading branch information
rgbkrk committed Apr 6, 2016
2 parents 3578936 + 8eb0337 commit ff60ea0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
10 changes: 10 additions & 0 deletions libvirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,16 @@ func (c *VirConnection) LookupDomainByName(id string) (VirDomain, error) {
return VirDomain{ptr: ptr}, nil
}

func (c *VirConnection) LookupByUUIDString(uuid string) (VirDomain, error) {
cUuid := C.CString(uuid)
defer C.free(unsafe.Pointer(cUuid))
ptr := C.virDomainLookupByUUIDString(c.ptr, cUuid)
if ptr == nil {
return VirDomain{}, GetLastError()
}
return VirDomain{ptr: ptr}, nil
}

func (c *VirConnection) DomainCreateXMLFromFile(xmlFile string, flags uint32) (VirDomain, error) {
xmlConfig, err := ioutil.ReadFile(xmlFile)
if err != nil {
Expand Down
26 changes: 26 additions & 0 deletions libvirt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,32 @@ func TestLookupDomainById(t *testing.T) {
defer dom.Free()
}

func TestLookupDomainByUUIDString(t *testing.T) {
conn := buildTestConnection()
defer conn.CloseConnection()
doms, err := conn.ListAllDomains(0)
if err != nil {
t.Error(err)
return
}
t.Log(doms)
if len(doms) == 0 {
t.Fatal("Length of ListAllDomains shouldn't be empty")
return
}
uuid, err := doms[0].GetUUIDString()
if err != nil {
t.Error(err)
return
}
dom, err := conn.LookupByUUIDString(uuid)
if err != nil {
t.Error(err)
return
}
defer dom.Free()
}

func TestLookupInvalidDomainById(t *testing.T) {
conn := buildTestConnection()
defer conn.CloseConnection()
Expand Down

0 comments on commit ff60ea0

Please sign in to comment.