forked from lstoll/libvirt-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkFilter.java
More file actions
124 lines (110 loc) · 3.46 KB
/
Copy pathNetworkFilter.java
File metadata and controls
124 lines (110 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package org.libvirt;
import org.libvirt.jna.Libvirt;
import org.libvirt.jna.NetworkFilterPointer;
import com.sun.jna.Native;
public class NetworkFilter {
/**
* the native virNWFilterPtr.
*/
NetworkFilterPointer NFP;
/**
* The Connect Object that represents the Hypervisor of this Filter
*/
private Connect virConnect;
/**
* The libvirt connection from the hypervisor
*/
protected Libvirt libvirt;
public NetworkFilter(Connect virConnect, NetworkFilterPointer NFP) {
this.NFP = NFP;
this.virConnect = virConnect;
libvirt = virConnect.libvirt;
}
@Override
public void finalize() throws LibvirtException {
free();
}
/**
* Release the network filter handle. The underlying snapshot continues to
* exist.
*
* @throws LibvirtException
* @return 0 on success, or -1 on error.
*/
public int free() throws LibvirtException {
int success = 0;
if (NFP != null) {
success = libvirt.virNWFilterFree(NFP);
ErrorHandler.processError(libvirt, success);
NFP = null;
}
return success;
}
/**
* Gets the public name for this network filter
*
* @return the name
* @throws LibvirtException
*/
public String getName() throws LibvirtException {
String returnValue = libvirt.virNWFilterGetName(NFP);
ErrorHandler.processError(libvirt, returnValue);
return returnValue;
}
/**
* Get the UUID for this network filter.
*
* @return the UUID as an unpacked int array
* @throws LibvirtException
* @see <a href="http://www.ietf.org/rfc/rfc4122.txt">rfc4122</a>
*/
public int[] getUUID() throws LibvirtException {
byte[] bytes = new byte[Libvirt.VIR_UUID_BUFLEN];
int success = libvirt.virNWFilterGetUUID(NFP, bytes);
ErrorHandler.processError(libvirt, success);
int[] returnValue = new int[0];
if (success == 0) {
returnValue = Connect.convertUUIDBytes(bytes);
}
return returnValue;
}
/**
* Gets the UUID for this network filter as string.
*
* @return the UUID in canonical String format
* @throws LibvirtException
* @see <a href="http://www.ietf.org/rfc/rfc4122.txt">rfc4122</a>
*/
public String getUUIDString() throws LibvirtException {
byte[] bytes = new byte[Libvirt.VIR_UUID_STRING_BUFLEN];
int success = libvirt.virNWFilterGetUUIDString(NFP, bytes);
ErrorHandler.processError(libvirt, success);
String returnValue = null;
if (success == 0) {
returnValue = Native.toString(bytes);
}
return returnValue;
}
/**
* Fetches an XML document describing attributes of the network filter.
*
* @see <a
* href="http://www.libvirt.org/html/libvirt-libvirt.html#virNWFilterGetXMLDesc">Libvirt
* Documentation</a>
* @return the XML document
*/
public String getXMLDesc() throws LibvirtException {
String returnValue = libvirt.virNWFilterGetXMLDesc(NFP, 0);
ErrorHandler.processError(libvirt, returnValue);
return returnValue;
}
/**
* undefine the network filter
*
* @throws LibvirtException
*/
public void undefine() throws LibvirtException {
int result = libvirt.virNWFilterUndefine(NFP);
ErrorHandler.processError(libvirt, result);
}
}