示例#1
0
func (c *VirConnection) LookupStorageVolByKey(key string) (VirStorageVol, error) {
	cKey := C.CString(key)
	defer C.free(unsafe.Pointer(cKey))
	ptr := C.virStorageVolLookupByKey(c.ptr, cKey)
	if ptr == nil {
		return VirStorageVol{}, GetLastError()
	}
	return VirStorageVol{ptr: ptr}, nil
}
示例#2
0
// LookupStorageVolumeByKey fetches a pointer to a storage volume based on its
// globally unique key.
// "Free" should be used to free the resources after the storage volume object
// is no longer needed.
func (conn Connection) LookupStorageVolumeByKey(key string) (StorageVolume, error) {
	cKey := C.CString(key)
	defer C.free(unsafe.Pointer(cKey))

	conn.log.Printf("looking up storage volume by key = %v...\n", key)
	cVol := C.virStorageVolLookupByKey(conn.virConnect, cKey)

	if cVol == nil {
		err := LastError()
		conn.log.Printf("an error occurred: %v\n", err)
		return StorageVolume{}, err
	}

	conn.log.Println("volume found")

	vol := StorageVolume{
		log:           conn.log,
		virStorageVol: cVol,
	}

	return vol, nil
}