Skip to content

Commit

Permalink
Added the 0.8.1 API
Browse files Browse the repository at this point in the history
  • Loading branch information
bkearney committed May 19, 2010
1 parent 3370d16 commit 58f4f05
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version=0.4.3
release=1
libvirt.required=0.8.0
libvirt.required=0.8.1
java.required=1:1.5.0
rpm.topdir=/home/bkearney/rpmbuild
jar.dir=/usr/share/java
29 changes: 23 additions & 6 deletions src/main/java/org/libvirt/Domain.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.libvirt.jna.DomainPointer;
import org.libvirt.jna.DomainSnapshotPointer;
import org.libvirt.jna.Libvirt;
import org.libvirt.jna.virDomainBlockInfo;
import org.libvirt.jna.virDomainBlockStats;
import org.libvirt.jna.virDomainInfo;
import org.libvirt.jna.virDomainInterfaceStats;
Expand Down Expand Up @@ -121,6 +122,22 @@ public void attachDeviceFlags(String xmlDesc, int flags) throws LibvirtException
processError();
}

/**
* This function returns block device (disk) stats for block devices
* attached to the domain.
*
* @param path
* the path to the block device
* @return the info, or null if an error
* @throws LibvirtException
*/
public DomainBlockInfo blockInfo(String path) throws LibvirtException {
virDomainBlockInfo info = new virDomainBlockInfo();
int success = libvirt.virDomainGetBlockInfo(VDP, path, info, 0);
processError();
return success == 0 ? new DomainBlockInfo(info) : null;
}

/**
* Returns block device (disk) stats for block devices attached to this
* domain. The path parameter is the name of the block device. Get this by
Expand All @@ -138,9 +155,9 @@ public void attachDeviceFlags(String xmlDesc, int flags) throws LibvirtException
*/
public DomainBlockStats blockStats(String path) throws LibvirtException {
virDomainBlockStats stats = new virDomainBlockStats();
libvirt.virDomainBlockStats(VDP, path, stats, stats.size());
int success = libvirt.virDomainBlockStats(VDP, path, stats, stats.size());
processError();
return new DomainBlockStats(stats);
return success == 0 ? new DomainBlockStats(stats) : null;
}

/**
Expand Down Expand Up @@ -516,8 +533,8 @@ public String getXMLDesc(int flags) throws LibvirtException {
/**
* Determine if the domain has a snapshot
*
* @see <a href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainHasCurrentSnapshot>Libvir
* t Documentation</a>
* @see <a href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainHasCurrentSnapshot>Libvi
* r t Documentation</a>
* @return 1 if running, 0 if inactive, -1 on error
* @throws LibvirtException
*/
Expand All @@ -530,8 +547,8 @@ public int hasCurrentSnapshot() throws LibvirtException {
/**
* Determine if the domain has a managed save image
*
* @see <a href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainHasManagedSaveImage>Libvir
* t Documentation</a>
* @see <a href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainHasManagedSaveImage>Libvi
* r t Documentation</a>
* @return 0 if no image is present, 1 if an image is present, and -1 in
* case of error
* @throws LibvirtException
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/org/libvirt/DomainBlockInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.libvirt;

import org.libvirt.jna.virDomainBlockInfo;

public class DomainBlockInfo {
protected long capacity;
protected long allocation;
protected long physical;

public DomainBlockInfo(virDomainBlockInfo info) {
capacity = info.capacity;
allocation = info.allocation;
physical = info.physical;
}

public long getAllocation() {
return allocation;
}

public long getCapacity() {
return capacity;
}

public long getPhysical() {
return physical;
}

public void setAllocation(long allocation) {
this.allocation = allocation;
}

public void setCapacity(long capacity) {
this.capacity = capacity;
}

public void setPhysical(long physical) {
this.physical = physical;
}
}
3 changes: 2 additions & 1 deletion src/main/java/org/libvirt/jna/Libvirt.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ public String virConnectDomainXMLToNative(ConnectionPointer virConnectPtr, Strin
public int virDomainDetachDeviceFlags(DomainPointer virDomainPtr, String deviceXML, int flags);
public int virDomainFree(DomainPointer virDomainPtr);
public int virDomainGetAutostart(DomainPointer virDomainPtr, IntByReference value);
public ConnectionPointer virDomainGetConnect(DomainPointer virDomainPtr);
public ConnectionPointer virDomainGetConnect(DomainPointer virDomainPtr);
public int virDomainGetBlockInfo(DomainPointer virDomainPtr, String path, virDomainBlockInfo info, int flags);
public int virDomainGetID(DomainPointer virDomainPtr);
public int virDomainGetInfo(DomainPointer virDomainPtr, virDomainInfo vInfo);
public int virDomainGetJobInfo(DomainPointer virDomainPtr, virDomainJobInfo vInfo);
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/org/libvirt/jna/virDomainBlockInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.libvirt.jna;

import com.sun.jna.Structure;

public class virDomainBlockInfo extends Structure {
public long capacity;
public long allocation;
public long physical;

}

0 comments on commit 58f4f05

Please sign in to comment.