Commit 3370d16097afd0e5b751b886a013a6af6ba4825e

  • avatar
  • Bryan Kearney <bkearney @red…at.com>
  • Wed May 19 18:41:12 CEST 2010
Added the remainder of the 0.8.0 API
  
77import org.libvirt.jna.DomainPointer;
88import org.libvirt.jna.InterfacePointer;
99import org.libvirt.jna.Libvirt;
10import org.libvirt.jna.NetworkFilterPointer;
1011import org.libvirt.jna.NetworkPointer;
1112import org.libvirt.jna.SecretPointer;
1213import org.libvirt.jna.StoragePoolPointer;
376376 }
377377
378378 /**
379 * Removes an event callback.
380 *
381 * @see <a
382 * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventDeregisterAny">Libvirt
383 * Documentation</a>
384 * @param callbackID
385 * the callback to deregister
386 * @return
387 * @throws LibvirtException
388 */
389 public int domainEventDeregisterAny(int callbackID) throws LibvirtException {
390 int returnValue = libvirt.virConnectDomainEventDeregisterAny(VCP, callbackID);
391 processError();
392 return returnValue;
393 }
394
395 /**
396 * Adds a callback to receive notifications of arbitrary domain events
397 * occurring on a domain.
398 *
399 * @see <a
400 * href="http://www.libvirt.org/html/libvirt-libvirt.html#virConnectDomainEventRegisterAny">Libvirt
401 * Documentation</a>
402 * @param domain
403 * option domain to limit the events monitored
404 * @param eventId
405 * the events to monitor
406 * @param cb
407 * the callback function to use.
408 * @return . The return value from this method is a positive integer
409 * identifier for the callback. -1 if an error
410 * @throws LibvirtException
411 */
412 public int domainEventRegisterAny(Domain domain, int eventId, Libvirt.VirConnectDomainEventGenericCallback cb)
413 throws LibvirtException {
414 DomainPointer ptr = domain == null ? null : domain.VDP;
415 int returnValue = libvirt.virConnectDomainEventRegisterAny(VCP, ptr, eventId, cb, null, null);
416 processError();
417 return returnValue;
418 }
419
420 /**
379421 * Finds a domain based on the hypervisor ID number.
380422 *
381423 * @param id
899899 }
900900
901901 /**
902 * Lists the names of the network filters
903 *
904 * @return an Array of Strings that contains the names network filters
905 * @throws LibvirtException
906 */
907 public String[] listNetworkFilters() throws LibvirtException {
908 int maxnames = numOfNetworkFilters();
909 String[] names = new String[maxnames];
910 if (maxnames > 0) {
911 libvirt.virConnectListNWFilters(VCP, names, maxnames);
912 processError();
913 }
914 return names;
915 }
916
917 /**
902918 * Lists the active networks.
903919 *
904920 * @return an Array of Strings that contains the names of the active
10051005 }
10061006
10071007 /**
1008 * Defines a networkFilter
1009 *
1010 * @param xmlDesc
1011 * the descirption of the filter
1012 * @return the new filer
1013 * @throws LibvirtException
1014 * @see <a
1015 * href="http://www.libvirt.org/html/libvirt-libvirt.html#virNWFilterDefineXML"
1016 * > Libvirt Documentation </a>
1017 */
1018 public NetworkFilter networkFilterDefineXML(String xmlDesc) throws LibvirtException {
1019 NetworkFilter returnValue = null;
1020 NetworkFilterPointer ptr = libvirt.virNWFilterDefineXML(VCP, xmlDesc);
1021 processError();
1022 if (ptr != null) {
1023 returnValue = new NetworkFilter(this, ptr);
1024 }
1025 return returnValue;
1026 }
1027
1028 /**
1029 * Fetch a network filter based on its unique name
1030 *
1031 * @param name
1032 * name of network filter to fetch
1033 * @return network filter object
1034 * @throws LibvirtException
1035 * @see <a
1036 * href="http://www.libvirt.org/html/libvirt-libvirt.html#virNWFilterLookupByName"
1037 * > Libvirt Documentation </a>
1038 */
1039 public NetworkFilter networkFilterLookupByName(String name) throws LibvirtException {
1040 NetworkFilter returnValue = null;
1041 NetworkFilterPointer ptr = libvirt.virNWFilterLookupByName(VCP, name);
1042 processError();
1043 if (ptr != null) {
1044 returnValue = new NetworkFilter(this, ptr);
1045 }
1046 return returnValue;
1047 }
1048
1049 /**
1050 * Looks up a network filter based on its UUID in array form. The UUID Array
1051 * contains an unpacked representation of the UUID, each int contains only
1052 * one byte.
1053 *
1054 * @param UUID
1055 * the UUID as an unpacked int array
1056 * @return the network filter object
1057 * @throws LibvirtException
1058 */
1059 public NetworkFilter networkFilterLookupByUUID(int[] UUID) throws LibvirtException {
1060 byte[] uuidBytes = Connect.createUUIDBytes(UUID);
1061 NetworkFilter returnValue = null;
1062 NetworkFilterPointer ptr = libvirt.virNWFilterLookupByUUID(VCP, uuidBytes);
1063 processError();
1064 if (ptr != null) {
1065 returnValue = new NetworkFilter(this, ptr);
1066 }
1067 return returnValue;
1068 }
1069
1070 /**
1071 * Fetch a network filter based on its globally unique id
1072 *
1073 * @param UUID
1074 * a java UUID
1075 * @return a new network filter object
1076 * @throws LibvirtException
1077 */
1078 public NetworkFilter networkFilterLookupByUUID(UUID uuid) throws LibvirtException {
1079 return networkFilterLookupByUUIDString(uuid.toString());
1080 }
1081
1082 /**
1083 * Looks up a network filter based on its UUID in String form.
1084 *
1085 * @param UUID
1086 * the UUID in canonical String representation
1087 * @return the Network Filter object
1088 * @throws LibvirtException
1089 */
1090 public NetworkFilter networkFilterLookupByUUIDString(String UUID) throws LibvirtException {
1091 NetworkFilter returnValue = null;
1092 NetworkFilterPointer ptr = libvirt.virNWFilterLookupByUUIDString(VCP, UUID);
1093 processError();
1094 if (ptr != null) {
1095 returnValue = new NetworkFilter(this, ptr);
1096 }
1097 return returnValue;
1098 }
1099
1100 /**
10081101 * Looks up a network on the based on its name.
10091102 *
10101103 * @param name
12671267 }
12681268
12691269 /**
1270 * Provides the number of network filters
1271 *
1272 * @return the number of network filters
1273 * @throws LibvirtException
1274 */
1275 public int numOfNetworkFilters() throws LibvirtException {
1276 int returnValue = libvirt.virConnectNumOfNWFilters(VCP);
1277 processError();
1278 return returnValue;
1279 }
1280
1281 /**
12701282 * Provides the number of active networks.
12711283 *
12721284 * @return the number of active networks
15601560 * use Stream.VIR_STREAM_NONBLOCK if non-blocking is required
15611561 * @return the new object
15621562 */
1563 public Stream virStreamNew(int flags) throws LibvirtException {
1563 public Stream streamNew(int flags) throws LibvirtException {
15641564 StreamPointer sPtr = libvirt.virStreamNew(VCP, flags);
15651565 processError();
15661566 return new Stream(this, sPtr);
  
516516 /**
517517 * Determine if the domain has a snapshot
518518 *
519 * @see <a href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainHasCurrentSnapshot>Libvirt
520 * Documentation</a>
519 * @see <a href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainHasCurrentSnapshot>Libvir
520 * t Documentation</a>
521521 * @return 1 if running, 0 if inactive, -1 on error
522522 * @throws LibvirtException
523523 */
528528 }
529529
530530 /**
531 * Determine if the domain has a managed save image
532 *
533 * @see <a href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainHasManagedSaveImage>Libvir
534 * t Documentation</a>
535 * @return 0 if no image is present, 1 if an image is present, and -1 in
536 * case of error
537 * @throws LibvirtException
538 */
539 public int hasManagedSaveImage() throws LibvirtException {
540 int returnValue = libvirt.virDomainHasManagedSaveImage(VDP, 0);
541 processError();
542 return returnValue;
543 }
544
545 /**
531546 * Returns network interface stats for interfaces attached to this domain.
532547 * The path parameter is the name of the network interface. Domains may have
533548 * more than network interface. To get stats for each you should make
594594 }
595595
596596 /**
597 * suspend a domain and save its memory contents to a file on disk.
598 *
599 * @see <a
600 * href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainManagedSave">Libvirt
601 * Documentation</a>
602 * @return 0 in case of success or -1 in case of failure
603 * @throws LibvirtException
604 */
605 public int managedSave() throws LibvirtException {
606 int returnValue = libvirt.virDomainManagedSave(VDP, 0);
607 processError();
608 return returnValue;
609 }
610
611 /**
612 * Remove any managed save images from the domain
613 *
614 * @see <a
615 * href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainManagedSaveRemove">Libvirt
616 * Documentation</a>
617 * @return
618 * @throws LibvirtException
619 */
620 public int managedSaveRemote() throws LibvirtException {
621 int returnValue = libvirt.virDomainManagedSaveRemove(VDP, 0);
622 processError();
623 return returnValue;
624 }
625
626 /**
597627 * This function provides memory statistics for the domain.
598628 *
599629 * @param number
696696 }
697697
698698 /**
699 * Sets maximum tolerable time for which the domain is allowed to be paused
700 * at the end of live migration.
701 *
702 * @see <a
703 * href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainMigrateSetMaxDowntime">LIbvirt
704 * Documentation</a>
705 * @param downtime
706 * the time to be down
707 * @return 0 in case of success, -1 otherwise.
708 * @throws LibvirtException
709 */
710 public int migrateSetMaxDowntime(long downtime) throws LibvirtException {
711 int returnValue = libvirt.virDomainMigrateSetMaxDowntime(VDP, downtime, 0);
712 processError();
713 return returnValue;
714 }
715
716 /**
699717 * Migrate the domain object from its current host to the destination host
700718 * given by duri.
701719 *
10281028 public void undefine() throws LibvirtException {
10291029 libvirt.virDomainUndefine(VDP);
10301030 processError();
1031 }
1032
1033 /**
1034 * Change a virtual device on a domain
1035 *
1036 * @see <a
1037 * href="http://www.libvirt.org/html/libvirt-libvirt.html#virDomainUpdateDeviceFlags">Libvirt
1038 * Documentation</a>
1039 * @param xml
1040 * the xml to update with
1041 * @param flags
1042 * controls the update
1043 * @return 0 in case of success, -1 in case of failure.
1044 * @throws LibvirtException
1045 */
1046 public int updateDeviceFlags(String xml, int flags) throws LibvirtException {
1047 int returnValue = libvirt.virDomainUpdateDeviceFlags(VDP, xml, flags);
1048 processError();
1049 return returnValue;
10311050 }
10321051
10331052}
  
1111 DomainSnapshotPointer VDSP;
1212
1313 /**
14 * The Connect Object that represents the Hypervisor of this Domain
14 * The Connect Object that represents the Hypervisor of this Domain Snapshot
1515 */
1616 private Connect virConnect;
1717
  
1package org.libvirt;
2
3import org.libvirt.jna.Libvirt;
4import org.libvirt.jna.NetworkFilterPointer;
5
6import com.sun.jna.Native;
7
8public class NetworkFilter {
9 /**
10 * the native virNWFilterPtr.
11 */
12 NetworkFilterPointer NFP;
13
14 /**
15 * The Connect Object that represents the Hypervisor of this Filter
16 */
17 private Connect virConnect;
18
19 /**
20 * The libvirt connection from the hypervisor
21 */
22 protected Libvirt libvirt;
23
24 public NetworkFilter(Connect virConnect, NetworkFilterPointer NFP) {
25 this.NFP = NFP;
26 this.virConnect = virConnect;
27 libvirt = virConnect.libvirt;
28 }
29
30 @Override
31 public void finalize() throws LibvirtException {
32 free();
33 }
34
35 /**
36 * Release the network filter handle. The underlying snapshot continues to
37 * exist.
38 *
39 * @throws LibvirtException
40 * @return 0 on success, or -1 on error.
41 */
42 public int free() throws LibvirtException {
43 int success = 0;
44 if (NFP != null) {
45 success = libvirt.virNWFilterFree(NFP);
46 processError();
47 NFP = null;
48 }
49
50 return success;
51 }
52
53 /**
54 * Gets the public name for this network filter
55 *
56 * @return the name
57 * @throws LibvirtException
58 */
59 public String getName() throws LibvirtException {
60 String returnValue = libvirt.virNWFilterGetName(NFP);
61 processError();
62 return returnValue;
63 }
64
65 /**
66 * Get the UUID for this network filter.
67 *
68 * @return the UUID as an unpacked int array
69 * @throws LibvirtException
70 * @see <a href="http://www.ietf.org/rfc/rfc4122.txt">rfc4122</a>
71 */
72 public int[] getUUID() throws LibvirtException {
73 byte[] bytes = new byte[Libvirt.VIR_UUID_BUFLEN];
74 int success = libvirt.virNWFilterGetUUID(NFP, bytes);
75 processError();
76 int[] returnValue = new int[0];
77 if (success == 0) {
78 returnValue = Connect.convertUUIDBytes(bytes);
79 }
80 return returnValue;
81 }
82
83 /**
84 * Gets the UUID for this network filter as string.
85 *
86 * @return the UUID in canonical String format
87 * @throws LibvirtException
88 * @see <a href="http://www.ietf.org/rfc/rfc4122.txt">rfc4122</a>
89 */
90 public String getUUIDString() throws LibvirtException {
91 byte[] bytes = new byte[Libvirt.VIR_UUID_STRING_BUFLEN];
92 int success = libvirt.virNWFilterGetUUIDString(NFP, bytes);
93 processError();
94 String returnValue = null;
95 if (success == 0) {
96 returnValue = Native.toString(bytes);
97 }
98 return returnValue;
99 }
100
101 /**
102 * Fetches an XML document describing attributes of the network filter.
103 *
104 * @see <a
105 * href="http://www.libvirt.org/html/libvirt-libvirt.html#virNWFilterGetXMLDesc">Libvirt
106 * Documentation</a>
107 * @return the XML document
108 */
109 public String getXMLDesc() throws LibvirtException {
110 String returnValue = libvirt.virNWFilterGetXMLDesc(NFP, 0);
111 processError();
112 return returnValue;
113 }
114
115 /**
116 * Error handling logic to throw errors. Must be called after every libvirt
117 * call.
118 */
119 protected void processError() throws LibvirtException {
120 virConnect.processError();
121 }
122
123 /**
124 * undefine the network filter
125 *
126 * @throws LibvirtException
127 */
128 public void undefine() throws LibvirtException {
129 libvirt.virNWFilterUndefine(NFP);
130 processError();
131 }
132}
  
195195 processError();
196196 return new StoragePool(virConnect, ptr);
197197 }
198
199 /**
200 * Ensure data previously on a volume is not accessible to future reads
201 *
202 * @see <a
203 * href="http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolWipe">Libvirt
204 * Documentation</a>
205 * @return 0 on success, or -1 on error
206 * @throws LibvirtException
207 */
208 public int wipe() throws LibvirtException {
209 int returnValue = libvirt.virStorageVolWipe(VSVP, 0);
210 processError();
211 return returnValue;
212 }
198213}
  
4848 * virSecretRef
4949 *
5050 * LIBVIRT_0.7.2
51 * virStreamRef
51 * virStreamRef
52 *
53 * LIBVIRT_0.8.0
54 * virNWFilterRef
55 *
5256 */
5357public interface Libvirt extends Library {
5458 // Callbacks
8585 public void eventCallback(StreamPointer virStreamPointer, int events, Pointer opaque) ;
8686 }
8787
88 /**
89 * Generic Callbacks
90 */
8891 interface VirFreeCallback extends Callback {
8992 public void freeCallback(Pointer opaque) ;
9093 }
9194
95 interface VirConnectDomainEventGenericCallback extends Callback {
96 public void eventCallback(ConnectionPointer virConnectPtr, DomainPointer virDomainPointer, Pointer opaque) ;
97 }
98
9299 Libvirt INSTANCE = (Libvirt) Native.loadLibrary("virt", Libvirt.class);
93100
94101 // Constants we need
108108 public int virConnCopyLastError(ConnectionPointer virConnectPtr, virError to);
109109 public int virConnectClose(ConnectionPointer virConnectPtr);
110110 public int virConnectCompareCPU(ConnectionPointer virConnectPtr, String xmlDesc, int flags);
111 public int virConnectDomainEventRegisterAny(ConnectionPointer virConnectPtr, DomainPointer virDomainPtr, int eventID, Libvirt.VirConnectDomainEventGenericCallback cb, Pointer opaque, Libvirt.VirFreeCallback freecb);
112 public int virConnectDomainEventDeregisterAny(ConnectionPointer virConnectPtr, int callbackID) ;
111113 public void virConnSetErrorFunc(ConnectionPointer virConnectPtr, Pointer userData, VirErrorCallback callback);
112114 public int virConnectIsEncrypted(ConnectionPointer virConnectPtr) ;
113115 public int virConnectIsSecure(ConnectionPointer virConnectPtr) ;
128128 public int virConnectListDomains(ConnectionPointer virConnectPtr, int[] ids, int maxnames);
129129 public int virConnectListInterfaces(ConnectionPointer virConnectPtr, String[] name, int maxNames);
130130 public int virConnectListNetworks(ConnectionPointer virConnectPtr, String[] name, int maxnames);
131 public int virConnectListNWFilters(ConnectionPointer virConnectPtr, String[] name, int maxnames);
131132 public int virConnectListSecrets(ConnectionPointer virConnectPtr, String[] uids, int maxUids);
132133 public int virConnectListStoragePools(ConnectionPointer virConnectPtr, String[] names, int maxnames);
133134 public int virConnectNumOfDefinedDomains(ConnectionPointer virConnectPtr);
138138 public int virConnectNumOfDomains(ConnectionPointer virConnectPtr);
139139 public int virConnectNumOfInterfaces(ConnectionPointer virConnectPtr);
140140 public int virConnectNumOfNetworks(ConnectionPointer virConnectPtr);
141 public int virConnectNumOfNWFilters(ConnectionPointer virConnectPtr);
141142 public int virConnectNumOfSecrets(ConnectionPointer virConnectPtr);
142143 public int virConnectNumOfStoragePools(ConnectionPointer virConnectPtr);
143144 public ConnectionPointer virConnectOpen(String name);
190190 public int virDomainGetVcpus(DomainPointer virDomainPtr, virVcpuInfo[] info, int maxInfo, byte[] cpumaps, int maplen);
191191 public String virDomainGetXMLDesc(DomainPointer virDomainPtr, int flags);
192192 public int virDomainHasCurrentSnapshot(DomainPointer virDomainPtr, int flags);
193 public int virDomainHasManagedSaveImage(DomainPointer virDomainPtr, int flags);
193194 public int virDomainInterfaceStats(DomainPointer virDomainPtr, String path, virDomainInterfaceStats stats, int size);
194195 public int virDomainIsActive(DomainPointer virDomainPtr);
195196 public int virDomainIsPersistent(DomainPointer virDomainPtr);
198198 public DomainPointer virDomainLookupByName(ConnectionPointer virConnectPtr, String name);
199199 public DomainPointer virDomainLookupByUUID(ConnectionPointer virConnectPtr, byte[] uuidBytes);
200200 public DomainPointer virDomainLookupByUUIDString(ConnectionPointer virConnectPtr, String uuidstr);
201 public int virDomainManagedSave(DomainPointer virDomainPtr, int flags);
202 public int virDomainManagedSaveRemove(DomainPointer virDomainPtr, int flags);
201203 public DomainPointer virDomainMigrate(DomainPointer virDomainPtr, ConnectionPointer virConnectPtr,
202204 NativeLong flags, String dname, String uri, NativeLong bandwidth);
205 public int virDomainMigrateSetMaxDowntime(DomainPointer virDomainPtr, long downtime, int flags);
203206 public int virDomainMigrateToURI(DomainPointer virDomainPtr, String duri,
204207 NativeLong flags, String dname, NativeLong bandwidth);
205208 public int virDomainMemoryStats(DomainPointer virDomainPtr, virDomainMemoryStats[] stats, int nr_stats, int flags);
219219 public int virDomainSetVcpus(DomainPointer virDomainPtr, int nvcpus);
220220 public int virDomainShutdown(DomainPointer virDomainPtr);
221221 public int virDomainSuspend(DomainPointer virDomainPtr);
222 public int virDomainUpdateDeviceFlags(DomainPointer virDomainPtr, String xml, int flags);
222223 public int virDomainUndefine(DomainPointer virDomainPtr);
223224
224225 // Network functions
306306 public StorageVolPointer virStorageVolLookupByKey(ConnectionPointer virConnectPtr, String name);
307307 public StorageVolPointer virStorageVolLookupByName(StoragePoolPointer storagePoolPtr, String name);
308308 public StorageVolPointer virStorageVolLookupByPath(ConnectionPointer virConnectPtr, String path);
309 public int virStorageVolWipe(StorageVolPointer storageVolPtr, int flags);
309310
310311 // Interface Methods
311312 public int virInterfaceCreate(InterfacePointer virDevicePointer);
359359 public int virDomainSnapshotListNames(DomainPointer virDomainPtr, String[] names, int nameslen, int flags);
360360 public DomainSnapshotPointer virDomainSnapshotLookupByName(DomainPointer virDomainPtr, String name, int flags);
361361 public int virDomainSnapshotNum(DomainPointer virDomainPtr, int flags);
362
363 // Network Filter Methods
364 public String virNWFilterGetXMLDesc(NetworkFilterPointer virNWFilterPtr, int flags);
365 public NetworkFilterPointer virNWFilterDefineXML(ConnectionPointer virConnectPtr, String xml);
366 public int virNWFilterFree(NetworkFilterPointer virNWFilterPtr);
367 public NetworkFilterPointer virNWFilterLookupByName(ConnectionPointer virConnectPtr, String name);
368 public NetworkFilterPointer virNWFilterLookupByUUID(ConnectionPointer virConnectPtr, byte[] uuidBytes);
369 public NetworkFilterPointer virNWFilterLookupByUUIDString(ConnectionPointer virConnectPtr, String uuidstr);
370 public String virNWFilterGetName(NetworkFilterPointer virNWFilterPtr);
371 public int virNWFilterGetUUID(NetworkFilterPointer virNWFilterPtr, byte[] uuidString);
372 public int virNWFilterGetUUIDString(NetworkFilterPointer virNWFilterPtr, byte[] uuidString);
373 public int virNWFilterUndefine(NetworkFilterPointer virNWFilterPtr);
362374}
  
1package org.libvirt.jna;
2
3import com.sun.jna.PointerType;
4
5public class NetworkFilterPointer extends PointerType {
6}