func (c *VirConnection) ListDomains() ([]uint32, error) { var cDomainsIds [512](uint32) cDomainsPointer := unsafe.Pointer(&cDomainsIds) numDomains := C.virConnectListDomains(c.ptr, (*C.int)(cDomainsPointer), 512) if numDomains == -1 { return nil, GetLastError() } return cDomainsIds[:numDomains], nil }
func (c *VirConnection) ListDomains() ([]uint32, error) { domainIds := make([]int, 1024) domainIdsPtr := unsafe.Pointer(&domainIds) numDomains := C.virConnectListDomains(c.ptr, (*C.int)(domainIdsPtr), 1024) if numDomains == -1 { return nil, errors.New(GetLastError()) } domains := make([]uint32, numDomains) gBytes := C.GoBytes(domainIdsPtr, C.int(numDomains*32)) buf := bytes.NewBuffer(gBytes) for k := 0; k < int(numDomains); k++ { binary.Read(buf, binary.LittleEndian, &domains[k]) } return domains, 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 }
func (h *Hypervisor) GetActiveDomains() ([]int, error) { number := C.virConnectNumOfDomains(h.cptr) if number == -1 { return nil, GetLastError() } ids := make([]int, number) if number == 0 { return ids, nil } cids := make([]C.int, number) result := C.virConnectListDomains(h.cptr, &cids[0], number) if result == -1 { return nil, GetLastError() } for i, v := range cids { ids[i] = int(v) } return ids, nil }