forked from lstoll/libvirt-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInterface.java
More file actions
150 lines (133 loc) · 4.07 KB
/
Copy pathInterface.java
File metadata and controls
150 lines (133 loc) · 4.07 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package org.libvirt;
import org.libvirt.jna.InterfacePointer;
import org.libvirt.jna.Libvirt;
/**
* A device which is attached to a node
*/
public class Interface {
/**
* Get XML Flag: dump inactive interface information
*/
public static int VIR_INTERFACE_XML_INACTIVE = 1;
/**
* the native virInterfacePtr.
*/
InterfacePointer VIP;
/**
* The Connect Object that represents the Hypervisor of this Interface
*/
private Connect virConnect;
/**
* The libvirt connection from the hypervisor
*/
protected Libvirt libvirt;
/**
* Constructs an Interface object from an InterfacePointer, and a Connect
* object.
*
* @param virConnect
* the Interfaces hypervisor
* @param VIP
* the native virInterfacePtr
*/
Interface(Connect virConnect, InterfacePointer VIP) {
this.virConnect = virConnect;
this.VIP = VIP;
libvirt = virConnect.libvirt;
}
/**
* Create and start a defined network. If the call succeed the network moves
* from the defined to the running networks pools.
*
* @throws LibvirtException
*/
public int create() throws LibvirtException {
int returnValue = libvirt.virInterfaceCreate(VIP);
ErrorHandler.processError(libvirt, returnValue);
return returnValue;
}
/**
* Destroy the network object. The running instance is shutdown if not down
* already and all resources used by it are given back to the hypervisor.
*
* @throws LibvirtException
*/
public int destroy() throws LibvirtException {
int returnValue = libvirt.virInterfaceDestroy(VIP);
ErrorHandler.processError(libvirt, returnValue);
return returnValue;
}
@Override
public void finalize() throws LibvirtException {
free();
}
/**
* Frees this interface object. The running instance is kept alive. The data
* structure is freed and should not be used thereafter.
*
* @throws LibvirtException
* @return number of references left (>= 0) for success, -1 for failure.
*/
public int free() throws LibvirtException {
int success = 0;
if (VIP != null) {
success = libvirt.virInterfaceFree(VIP);
ErrorHandler.processError(libvirt, success);
VIP = null;
}
return success;
}
/**
* Returns the mac string of the interface
*
* @throws LibvirtException
*/
public String getMACString() throws LibvirtException {
String name = libvirt.virInterfaceGetMACString(VIP);
return name;
}
/**
* Returns the name of the interface
*
* @throws LibvirtException
*/
public String getName() throws LibvirtException {
String name = libvirt.virInterfaceGetName(VIP);
return name;
}
/**
* Returns the XML description for theinterface
*
* @throws LibvirtException
*/
public String getXMLDescription(int flags) throws LibvirtException {
String xml = libvirt.virInterfaceGetXMLDesc(VIP, flags);
ErrorHandler.processError(libvirt, xml);
return xml;
}
/**
* Determine if the interface is currently running
*
* @see <a
* href="http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceIsActive">Libvirt
* Documentation</a>
* @return 1 if running, 0 if inactive, -1 on error
* @throws LibvirtException
*/
public int isActive() throws LibvirtException {
int returnValue = libvirt.virInterfaceIsActive(VIP);
ErrorHandler.processError(libvirt, returnValue);
return returnValue;
}
/**
* Undefine an interface, ie remove it from the config. This does not free
* the associated virInterfacePtr object.
*
* @throws LibvirtException
*/
public int undefine() throws LibvirtException {
int returnValue = libvirt.virInterfaceUndefine(VIP);
ErrorHandler.processError(libvirt, returnValue);
return returnValue;
}
}