示例#1
0
func (h *Hypervisor) GetDefinedDomains() ([]string, error) {
	number := C.virConnectNumOfDefinedDomains(h.cptr)
	if number == -1 {
		return nil, GetLastError()
	}

	names := make([]string, number)

	if number == 0 {
		return names, nil
	}

	cnames := make([]*C.char, number)
	result := C.virConnectListDefinedDomains(h.cptr, &cnames[0], number)
	if result == -1 {
		return nil, GetLastError()
	}

	for i, v := range cnames {
		names[i] = C.GoString(v)
		defer C.free(unsafe.Pointer(v))
	}

	return names, nil
}
示例#2
0
func (c *VirConnection) ListDefinedDomains() ([]string, error) {
	var names [1024](*C.char)
	namesPtr := unsafe.Pointer(&names)
	numDomains := C.virConnectListDefinedDomains(
		c.ptr,
		(**C.char)(namesPtr),
		1024)
	if numDomains == -1 {
		return nil, GetLastError()
	}
	goNames := make([]string, numDomains)
	for k := 0; k < int(numDomains); k++ {
		goNames[k] = C.GoString(names[k])
		C.free(unsafe.Pointer(names[k]))
	}
	return goNames, nil
}
示例#3
0
func (c *VirConnection) InActiveDomainList() ([]VirDomain, error) {
	var cDomainsNames [512](*C.char)
	var err error
	var i int
	cDomainsPointer := unsafe.Pointer(&cDomainsNames)
	numDomains := C.virConnectListDefinedDomains(c.ptr, (**C.char)(cDomainsPointer), 512)
	if numDomains == -1 {
		return nil, errors.New(GetLastError())
	}

	inActiveDomainList := make([]VirDomain, numDomains)

	for i = 0; i < int(numDomains); i++ {
		inActiveDomainList[i].ptr = C.virDomainLookupByName(c.ptr, (*C.char)(cDomainsNames[i]))
		C.free(unsafe.Pointer(cDomainsNames[i]))
		if inActiveDomainList[i].ptr == nil {
			err = errors.New(GetLastError())
			break
		}
	}

	return inActiveDomainList[:i], err

}