Example #1
0
func (d *Domain) GetUUID() (string, error) {
	uuid := make([]C.char, VIR_UUID_STRING_BUFLEN)
	result := C.virDomainGetUUIDString(d.cptr, &uuid[0])
	if result == -1 {
		return "", GetLastError()
	}

	return C.GoString(&uuid[0]), nil
}
Example #2
0
func (d *VirDomain) GetUUIDString() (string, error) {
	var cUuid [C.VIR_UUID_STRING_BUFLEN](C.char)
	cuidPtr := unsafe.Pointer(&cUuid)
	result := C.virDomainGetUUIDString(d.ptr, (*C.char)(cuidPtr))
	if result != 0 {
		return "", errors.New(GetLastError())
	}
	return C.GoString((*C.char)(cuidPtr)), nil
}
Example #3
0
// UUID gets the UUID for a domain as string. For more information about UUID
// see RFC4122.
func (dom Domain) UUID() (string, error) {
	cUUID := (*C.char)(C.malloc(C.size_t(C.VIR_UUID_STRING_BUFLEN)))
	defer C.free(unsafe.Pointer(cUUID))

	dom.log.Println("reading domain UUID...")
	cRet := C.virDomainGetUUIDString(dom.virDomain, cUUID)
	ret := int32(cRet)

	if ret == -1 {
		err := LastError()
		dom.log.Printf("an error occurred: %v\n", err)
		return "", err
	}

	uuid := C.GoString(cUUID)
	dom.log.Printf("UUID: %v\n", uuid)

	return uuid, nil
}