func (c *VirConnection) LookupDomainById(id uint32) (VirDomain, error) { ptr := C.virDomainLookupByID(c.ptr, C.int(id)) if ptr == nil { return VirDomain{}, GetLastError() } return VirDomain{ptr: ptr}, nil }
func (h *Hypervisor) LookupDomainById(id int) (*Domain, error) { cdomain := C.virDomainLookupByID(h.cptr, C.int(id)) if cdomain == nil { return nil, GetLastError() } domain := &Domain{cdomain} runtime.SetFinalizer(domain, cleanupDomain) return domain, nil }
// LookupDomainByID tries to find a domain based on the hypervisor ID number. // Note that this won't work for inactive domains which have an ID of -1, in // that case a lookup based on the Name or UUID need to be done instead. func (conn Connection) LookupDomainByID(id uint32) (Domain, error) { conn.log.Printf("looking up domain with ID = %v...\n", id) cDomain := C.virDomainLookupByID(conn.virConnect, C.int(id)) if cDomain == nil { err := LastError() conn.log.Printf("an error occurred: %v\n", err) return Domain{}, err } conn.log.Println("domain found") dom := Domain{ log: conn.log, virDomain: cDomain, } return dom, nil }
func (c *VirConnection) ActiveDomainList() ([]VirDomain, error) { var cDomainsIds [512](C.int) var i int cDomainsPointer := unsafe.Pointer(&cDomainsIds) cNumDomains := C.virConnectListDomains(c.ptr, (*C.int)(cDomainsPointer), 512) var err error if int(cNumDomains) == -1 { return nil, errors.New(GetLastError()) } activeDomainList := make([]VirDomain, int(cNumDomains)) for i = 0; i < int(cNumDomains); i++ { activeDomainList[i].ptr = C.virDomainLookupByID(c.ptr, C.int(cDomainsIds[i])) if activeDomainList[i].ptr == nil { err = errors.New(GetLastError()) break } } return activeDomainList[:i], err }