Example #1
0
func (c *VirConnection) LookupDomainByName(id string) (VirDomain, error) {
	cName := C.CString(id)
	defer C.free(unsafe.Pointer(cName))
	ptr := C.virDomainLookupByName(c.ptr, cName)
	if ptr == nil {
		return VirDomain{}, GetLastError()
	}
	return VirDomain{ptr: ptr}, nil
}
Example #2
0
func (h *Hypervisor) LookupDomainByName(name string) (*Domain, error) {
	cname := C.CString(name)
	defer C.free(unsafe.Pointer(cname))

	cdomain := C.virDomainLookupByName(h.cptr, cname)
	if cdomain == nil {
		return nil, GetLastError()
	}

	domain := &Domain{cdomain}
	runtime.SetFinalizer(domain, cleanupDomain)

	return domain, nil
}
Example #3
0
// LookupDomainByName tries to lookup a domain on the given hypervisor based on
// its name.
func (conn Connection) LookupDomainByName(name string) (Domain, error) {
	cName := C.CString(name)
	defer C.free(unsafe.Pointer(cName))

	conn.log.Printf("looking up domain with name = %v...\n", name)
	cDomain := C.virDomainLookupByName(conn.virConnect, cName)
	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
}
Example #4
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

}