ruby-libvirt 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +16 -2
- data/Rakefile +8 -6
- data/ext/libvirt/_libvirt.c +85 -1872
- data/ext/libvirt/common.c +75 -0
- data/ext/libvirt/common.h +155 -0
- data/ext/libvirt/connect.c +392 -0
- data/ext/libvirt/connect.h +12 -0
- data/ext/libvirt/domain.c +1606 -0
- data/ext/libvirt/domain.h +8 -0
- data/ext/libvirt/extconf.rb +30 -1
- data/ext/libvirt/interface.c +259 -0
- data/ext/libvirt/interface.h +6 -0
- data/ext/libvirt/network.c +338 -0
- data/ext/libvirt/network.h +6 -0
- data/ext/libvirt/nodedevice.c +333 -0
- data/ext/libvirt/nodedevice.h +6 -0
- data/ext/libvirt/nwfilter.c +206 -0
- data/ext/libvirt/nwfilter.h +6 -0
- data/ext/libvirt/secret.c +288 -0
- data/ext/libvirt/secret.h +6 -0
- data/ext/libvirt/storage.c +825 -0
- data/ext/libvirt/storage.h +6 -0
- data/tests/tc_connect.rb +1 -1
- data/tests/test_conn.rb +53 -0
- data/tests/test_domain.rb +165 -0
- data/tests/test_interface.rb +35 -0
- data/tests/test_network.rb +40 -0
- data/tests/test_nodedevice.rb +23 -0
- data/tests/test_nwfilter.rb +28 -0
- data/tests/test_open.rb +23 -0
- data/tests/test_secret.rb +33 -0
- data/tests/test_storage.rb +49 -0
- metadata +58 -14
- data/ext/libvirt/extconf.h +0 -6
@@ -0,0 +1,333 @@
|
|
1
|
+
/*
|
2
|
+
* nodedevice.c: virNodeDevice methods
|
3
|
+
*
|
4
|
+
* Copyright (C) 2010 Red Hat Inc.
|
5
|
+
*
|
6
|
+
* This library is free software; you can redistribute it and/or
|
7
|
+
* modify it under the terms of the GNU Lesser General Public
|
8
|
+
* License as published by the Free Software Foundation; either
|
9
|
+
* version 2.1 of the License, or (at your option) any later version.
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Lesser General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
*/
|
20
|
+
|
21
|
+
#include <ruby.h>
|
22
|
+
#include <libvirt/libvirt.h>
|
23
|
+
#include <libvirt/virterror.h>
|
24
|
+
#include "common.h"
|
25
|
+
#include "connect.h"
|
26
|
+
#include "extconf.h"
|
27
|
+
|
28
|
+
static VALUE c_nodedevice;
|
29
|
+
|
30
|
+
static void nodedevice_free(void *s) {
|
31
|
+
generic_free(NodeDevice, s);
|
32
|
+
}
|
33
|
+
|
34
|
+
static virNodeDevicePtr nodedevice_get(VALUE s) {
|
35
|
+
generic_get(NodeDevice, s);
|
36
|
+
}
|
37
|
+
|
38
|
+
static VALUE nodedevice_new(virNodeDevicePtr s, VALUE conn) {
|
39
|
+
return generic_new(c_nodedevice, s, conn, nodedevice_free);
|
40
|
+
}
|
41
|
+
|
42
|
+
/*
|
43
|
+
* call-seq:
|
44
|
+
* conn.num_of_nodedevices -> fixnum
|
45
|
+
*
|
46
|
+
* Call +virNodeNumOfDevices+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeNumOfDevices]
|
47
|
+
*/
|
48
|
+
static VALUE libvirt_conn_num_of_nodedevices(int argc, VALUE *argv, VALUE c) {
|
49
|
+
int result;
|
50
|
+
virConnectPtr conn = connect_get(c);
|
51
|
+
VALUE cap, flags;
|
52
|
+
|
53
|
+
rb_scan_args(argc, argv, "02", &cap, &flags);
|
54
|
+
|
55
|
+
if (NIL_P(flags))
|
56
|
+
flags = INT2FIX(0);
|
57
|
+
|
58
|
+
result = virNodeNumOfDevices(conn, get_string_or_nil(cap), NUM2UINT(flags));
|
59
|
+
_E(result < 0, create_error(e_RetrieveError, "virNodeNumOfDevices", "",
|
60
|
+
conn));
|
61
|
+
|
62
|
+
return INT2NUM(result);
|
63
|
+
}
|
64
|
+
|
65
|
+
/*
|
66
|
+
* call-seq:
|
67
|
+
* conn.list_nodedevices -> list
|
68
|
+
*
|
69
|
+
* Call +virNodeListDevices+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeListDevices]
|
70
|
+
*/
|
71
|
+
static VALUE libvirt_conn_list_nodedevices(int argc, VALUE *argv, VALUE c) {
|
72
|
+
int i, r, num;
|
73
|
+
virConnectPtr conn = connect_get(c);
|
74
|
+
VALUE cap, flags;
|
75
|
+
char *capstr;
|
76
|
+
VALUE result;
|
77
|
+
char **names;
|
78
|
+
|
79
|
+
rb_scan_args(argc, argv, "02", &cap, &flags);
|
80
|
+
|
81
|
+
if (NIL_P(flags))
|
82
|
+
flags = INT2FIX(0);
|
83
|
+
|
84
|
+
capstr = get_string_or_nil(cap);
|
85
|
+
|
86
|
+
num = virNodeNumOfDevices(conn, capstr, 0);
|
87
|
+
_E(num < 0, create_error(e_RetrieveError, "virNodeNumOfDevices", "", conn));
|
88
|
+
if (num == 0) {
|
89
|
+
/* if num is 0, don't call virNodeListDevices function */
|
90
|
+
result = rb_ary_new2(num);
|
91
|
+
return result;
|
92
|
+
}
|
93
|
+
names = ALLOC_N(char *, num);
|
94
|
+
r = virNodeListDevices(conn, capstr, names, num, NUM2UINT(flags));
|
95
|
+
if (r < 0) {
|
96
|
+
free(names);
|
97
|
+
_E(r < 0, create_error(e_RetrieveError, "virNodeListDevices", "", conn));
|
98
|
+
}
|
99
|
+
|
100
|
+
result = rb_ary_new2(num);
|
101
|
+
for (i=0; i<num; i++) {
|
102
|
+
rb_ary_push(result, rb_str_new2(names[i]));
|
103
|
+
free(names[i]);
|
104
|
+
}
|
105
|
+
free(names);
|
106
|
+
return result;
|
107
|
+
}
|
108
|
+
|
109
|
+
/*
|
110
|
+
* call-seq:
|
111
|
+
* conn.lookup_nodedevice_by_name -> Libvirt::NodeDevice
|
112
|
+
*
|
113
|
+
* Call +virNodeDeviceLookupByName+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceLookupByName]
|
114
|
+
*/
|
115
|
+
static VALUE libvirt_conn_lookup_nodedevice_by_name(VALUE c, VALUE name) {
|
116
|
+
virNodeDevicePtr nodedev;
|
117
|
+
virConnectPtr conn = connect_get(c);
|
118
|
+
|
119
|
+
nodedev = virNodeDeviceLookupByName(conn, StringValueCStr(name));
|
120
|
+
_E(nodedev == NULL, create_error(e_RetrieveError, "virNodeDeviceLookupByName", "", conn));
|
121
|
+
|
122
|
+
return nodedevice_new(nodedev, c);
|
123
|
+
|
124
|
+
}
|
125
|
+
|
126
|
+
#if HAVE_VIRNODEDEVICECREATEXML
|
127
|
+
/*
|
128
|
+
* call-seq:
|
129
|
+
* conn.create_nodedevice_xml -> Libvirt::NodeDevice
|
130
|
+
*
|
131
|
+
* Call +virNodeDeviceCreateXML+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceCreateXML]
|
132
|
+
*/
|
133
|
+
static VALUE libvirt_conn_create_nodedevice_xml(int argc, VALUE *argv, VALUE c) {
|
134
|
+
virNodeDevicePtr nodedev;
|
135
|
+
virConnectPtr conn = connect_get(c);
|
136
|
+
VALUE xml, flags;
|
137
|
+
|
138
|
+
rb_scan_args(argc, argv, "11", &xml, &flags);
|
139
|
+
|
140
|
+
if (NIL_P(flags))
|
141
|
+
flags = INT2FIX(0);
|
142
|
+
|
143
|
+
nodedev = virNodeDeviceCreateXML(conn, StringValueCStr(xml), NUM2UINT(flags));
|
144
|
+
_E(nodedev == NULL, create_error(e_Error, "virNodeDeviceCreateXML", "", conn));
|
145
|
+
|
146
|
+
return nodedevice_new(nodedev, c);
|
147
|
+
}
|
148
|
+
#endif
|
149
|
+
|
150
|
+
/*
|
151
|
+
* call-seq:
|
152
|
+
* nodedevice.name -> string
|
153
|
+
*
|
154
|
+
* Call +virNodeDeviceGetName+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceGetName]
|
155
|
+
*/
|
156
|
+
static VALUE libvirt_nodedevice_name(VALUE c) {
|
157
|
+
gen_call_string(virNodeDeviceGetName, conn(c), 0, nodedevice_get(c));
|
158
|
+
}
|
159
|
+
|
160
|
+
/*
|
161
|
+
* call-seq:
|
162
|
+
* nodedevice.parent -> string
|
163
|
+
*
|
164
|
+
* Call +virNodeDeviceGetParent+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceGetParent]
|
165
|
+
*/
|
166
|
+
static VALUE libvirt_nodedevice_parent(VALUE c) {
|
167
|
+
/* unfortunately we can't use gen_call_string() here because
|
168
|
+
* virNodeDeviceGetParent() returns NULL as a valid value (when this
|
169
|
+
* device has no parent. Hand-code it instead
|
170
|
+
*/
|
171
|
+
|
172
|
+
const char *str;
|
173
|
+
|
174
|
+
str = virNodeDeviceGetParent(nodedevice_get(c));
|
175
|
+
if (str == NULL)
|
176
|
+
return Qnil;
|
177
|
+
else
|
178
|
+
return rb_str_new2(str);
|
179
|
+
}
|
180
|
+
|
181
|
+
/*
|
182
|
+
* call-seq:
|
183
|
+
* nodedevice.num_of_caps -> fixnum
|
184
|
+
*
|
185
|
+
* Call +virNodeDeviceNumOfCaps+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceNumOfCaps]
|
186
|
+
*/
|
187
|
+
static VALUE libvirt_nodedevice_num_of_caps(VALUE c) {
|
188
|
+
int result;
|
189
|
+
|
190
|
+
result = virNodeDeviceNumOfCaps(nodedevice_get(c));
|
191
|
+
_E(result < 0, create_error(e_RetrieveError, "virNodeNumOfDevices", "", connect_get(c)));
|
192
|
+
|
193
|
+
return INT2NUM(result);
|
194
|
+
}
|
195
|
+
|
196
|
+
/*
|
197
|
+
* call-seq:
|
198
|
+
* nodedevice.list_caps -> list
|
199
|
+
*
|
200
|
+
* Call +virNodeDeviceListCaps+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceListCaps]
|
201
|
+
*/
|
202
|
+
static VALUE libvirt_nodedevice_list_caps(VALUE c) {
|
203
|
+
int i, r, num;
|
204
|
+
virConnectPtr conn = connect_get(c);
|
205
|
+
virNodeDevicePtr nodedev = nodedevice_get(c);
|
206
|
+
VALUE result;
|
207
|
+
char **names;
|
208
|
+
|
209
|
+
num = virNodeDeviceNumOfCaps(nodedev);
|
210
|
+
_E(num < 0, create_error(e_RetrieveError, "virNodeDeviceNumOfCaps", "", conn));
|
211
|
+
if (num == 0) {
|
212
|
+
/* if num is 0, don't call virNodeDeviceListCaps function */
|
213
|
+
result = rb_ary_new2(num);
|
214
|
+
return result;
|
215
|
+
}
|
216
|
+
names = ALLOC_N(char *, num);
|
217
|
+
r = virNodeDeviceListCaps(nodedev, names, num);
|
218
|
+
if (r < 0) {
|
219
|
+
free(names);
|
220
|
+
_E(r < 0, create_error(e_RetrieveError, "virNodeDeviceListCaps", "", conn));
|
221
|
+
}
|
222
|
+
|
223
|
+
result = rb_ary_new2(num);
|
224
|
+
for (i=0; i<num; i++) {
|
225
|
+
rb_ary_push(result, rb_str_new2(names[i]));
|
226
|
+
free(names[i]);
|
227
|
+
}
|
228
|
+
free(names);
|
229
|
+
return result;
|
230
|
+
}
|
231
|
+
|
232
|
+
/*
|
233
|
+
* call-seq:
|
234
|
+
* nodedevice.xml_desc -> string
|
235
|
+
*
|
236
|
+
* Call +virNodeDeviceGetXMLDesc+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceGetXMLDesc]
|
237
|
+
*/
|
238
|
+
static VALUE libvirt_nodedevice_xml_desc(int argc, VALUE *argv, VALUE s) {
|
239
|
+
VALUE flags;
|
240
|
+
|
241
|
+
rb_scan_args(argc, argv, "01", &flags);
|
242
|
+
|
243
|
+
if (NIL_P(flags))
|
244
|
+
flags = INT2FIX(0);
|
245
|
+
|
246
|
+
gen_call_string(virNodeDeviceGetXMLDesc, conn(s), 1,
|
247
|
+
nodedevice_get(s), NUM2UINT(flags));
|
248
|
+
}
|
249
|
+
|
250
|
+
/*
|
251
|
+
* call-seq:
|
252
|
+
* nodedevice.detach -> nil
|
253
|
+
*
|
254
|
+
* Call +virNodeDeviceDettach+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceDettach]
|
255
|
+
*/
|
256
|
+
static VALUE libvirt_nodedevice_detach(VALUE s) {
|
257
|
+
gen_call_void(virNodeDeviceDettach, conn(s), nodedevice_get(s));
|
258
|
+
}
|
259
|
+
|
260
|
+
/*
|
261
|
+
* call-seq:
|
262
|
+
* nodedevice.reattach -> nil
|
263
|
+
*
|
264
|
+
* Call +virNodeDeviceReAttach+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceReAttach]
|
265
|
+
*/
|
266
|
+
static VALUE libvirt_nodedevice_reattach(VALUE s) {
|
267
|
+
gen_call_void(virNodeDeviceReAttach, conn(s), nodedevice_get(s));
|
268
|
+
}
|
269
|
+
|
270
|
+
/*
|
271
|
+
* call-seq:
|
272
|
+
* nodedevice.reset -> nil
|
273
|
+
*
|
274
|
+
* Call +virNodeDeviceReset+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceReset]
|
275
|
+
*/
|
276
|
+
static VALUE libvirt_nodedevice_reset(VALUE s) {
|
277
|
+
gen_call_void(virNodeDeviceReset, conn(s), nodedevice_get(s));
|
278
|
+
}
|
279
|
+
|
280
|
+
#if HAVE_VIRNODEDEVICEDESTROY
|
281
|
+
/*
|
282
|
+
* call-seq:
|
283
|
+
* nodedevice.destroy -> nil
|
284
|
+
*
|
285
|
+
* Call +virNodeDeviceDestroy+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceDestroy]
|
286
|
+
*/
|
287
|
+
static VALUE libvirt_nodedevice_destroy(VALUE s) {
|
288
|
+
gen_call_void(virNodeDeviceDestroy, conn(s), nodedevice_get(s));
|
289
|
+
}
|
290
|
+
#endif
|
291
|
+
|
292
|
+
/*
|
293
|
+
* call-seq:
|
294
|
+
* nodedevice.free -> nil
|
295
|
+
*
|
296
|
+
* Call +virNodeDeviceFree+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceFree]
|
297
|
+
*/
|
298
|
+
static VALUE libvirt_nodedevice_free(VALUE s) {
|
299
|
+
gen_call_free(NodeDevice, s);
|
300
|
+
}
|
301
|
+
|
302
|
+
/*
|
303
|
+
* Class Libvirt::NodeDevice
|
304
|
+
*/
|
305
|
+
void init_nodedevice()
|
306
|
+
{
|
307
|
+
c_nodedevice = rb_define_class_under(m_libvirt, "NodeDevice", rb_cObject);
|
308
|
+
rb_define_method(c_connect, "num_of_nodedevices",
|
309
|
+
libvirt_conn_num_of_nodedevices, -1);
|
310
|
+
rb_define_method(c_connect, "list_nodedevices",
|
311
|
+
libvirt_conn_list_nodedevices, -1);
|
312
|
+
rb_define_method(c_connect, "lookup_nodedevice_by_name",
|
313
|
+
libvirt_conn_lookup_nodedevice_by_name, 1);
|
314
|
+
#if HAVE_VIRNODEDEVICECREATEXML
|
315
|
+
rb_define_method(c_connect, "create_nodedevice_xml",
|
316
|
+
libvirt_conn_create_nodedevice_xml, -1);
|
317
|
+
#endif
|
318
|
+
|
319
|
+
rb_define_method(c_nodedevice, "name", libvirt_nodedevice_name, 0);
|
320
|
+
rb_define_method(c_nodedevice, "parent", libvirt_nodedevice_parent, 0);
|
321
|
+
rb_define_method(c_nodedevice, "num_of_caps",
|
322
|
+
libvirt_nodedevice_num_of_caps, 0);
|
323
|
+
rb_define_method(c_nodedevice, "list_caps",
|
324
|
+
libvirt_nodedevice_list_caps, 0);
|
325
|
+
rb_define_method(c_nodedevice, "xml_desc", libvirt_nodedevice_xml_desc, -1);
|
326
|
+
rb_define_method(c_nodedevice, "detach", libvirt_nodedevice_detach, 0);
|
327
|
+
rb_define_method(c_nodedevice, "reattach", libvirt_nodedevice_reattach, 0);
|
328
|
+
rb_define_method(c_nodedevice, "reset", libvirt_nodedevice_reset, 0);
|
329
|
+
#if HAVE_VIRNODEDEVICEDESTROY
|
330
|
+
rb_define_method(c_nodedevice, "destroy", libvirt_nodedevice_destroy, 0);
|
331
|
+
#endif
|
332
|
+
rb_define_method(c_nodedevice, "free", libvirt_nodedevice_free, 0);
|
333
|
+
}
|
@@ -0,0 +1,206 @@
|
|
1
|
+
/*
|
2
|
+
* nwfilter.c: virNWFilter methods
|
3
|
+
*
|
4
|
+
* Copyright (C) 2010 Red Hat Inc.
|
5
|
+
*
|
6
|
+
* This library is free software; you can redistribute it and/or
|
7
|
+
* modify it under the terms of the GNU Lesser General Public
|
8
|
+
* License as published by the Free Software Foundation; either
|
9
|
+
* version 2.1 of the License, or (at your option) any later version.
|
10
|
+
*
|
11
|
+
* This library is distributed in the hope that it will be useful,
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
14
|
+
* Lesser General Public License for more details.
|
15
|
+
*
|
16
|
+
* You should have received a copy of the GNU Lesser General Public
|
17
|
+
* License along with this library; if not, write to the Free Software
|
18
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
19
|
+
*/
|
20
|
+
|
21
|
+
#include <ruby.h>
|
22
|
+
#include <libvirt/libvirt.h>
|
23
|
+
#include <libvirt/virterror.h>
|
24
|
+
#include "common.h"
|
25
|
+
#include "connect.h"
|
26
|
+
#include "extconf.h"
|
27
|
+
|
28
|
+
#if HAVE_TYPE_VIRNWFILTERPTR
|
29
|
+
static VALUE c_nwfilter;
|
30
|
+
|
31
|
+
static void nwfilter_free(void *nw) {
|
32
|
+
generic_free(NWFilter, nw);
|
33
|
+
}
|
34
|
+
|
35
|
+
static virNWFilterPtr nwfilter_get(VALUE nw) {
|
36
|
+
generic_get(NWFilter, nw);
|
37
|
+
}
|
38
|
+
|
39
|
+
static VALUE nwfilter_new(virNWFilterPtr nw, VALUE conn) {
|
40
|
+
return generic_new(c_nwfilter, nw, conn, nwfilter_free);
|
41
|
+
}
|
42
|
+
|
43
|
+
/*
|
44
|
+
* call-seq:
|
45
|
+
* conn.num_of_nwfilters -> fixnum
|
46
|
+
*
|
47
|
+
* Call +virConnectNumOfNWFilters+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectNumOfNWFilters]
|
48
|
+
*/
|
49
|
+
static VALUE libvirt_conn_num_of_nwfilters(VALUE s) {
|
50
|
+
gen_conn_num_of(s, NWFilters);
|
51
|
+
}
|
52
|
+
|
53
|
+
/*
|
54
|
+
* call-seq:
|
55
|
+
* conn.list_nwfilters -> list
|
56
|
+
*
|
57
|
+
* Call +virConnectListNWFilters+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectListNWFilters]
|
58
|
+
*/
|
59
|
+
static VALUE libvirt_conn_list_nwfilters(VALUE s) {
|
60
|
+
gen_conn_list_names(s, NWFilters);
|
61
|
+
}
|
62
|
+
|
63
|
+
/*
|
64
|
+
* call-seq:
|
65
|
+
* conn.lookup_nwfilter_by_name -> Libvirt::NWFilter
|
66
|
+
*
|
67
|
+
* Call +virNWFilterLookupByName+[http://www.libvirt.org/html/libvirt-libvirt.html#virNWFilterLookupByName]
|
68
|
+
*/
|
69
|
+
static VALUE libvirt_conn_lookup_nwfilter_by_name(VALUE c, VALUE name) {
|
70
|
+
virNWFilterPtr nwfilter;
|
71
|
+
virConnectPtr conn = connect_get(c);
|
72
|
+
|
73
|
+
nwfilter = virNWFilterLookupByName(conn, StringValueCStr(name));
|
74
|
+
_E(nwfilter == NULL, create_error(e_RetrieveError, "virNWFilterLookupByName", "", conn));
|
75
|
+
|
76
|
+
return nwfilter_new(nwfilter, c);
|
77
|
+
}
|
78
|
+
|
79
|
+
/*
|
80
|
+
* call-seq:
|
81
|
+
* conn.lookup_nwfilter_by_uuid -> Libvirt::NWFilter
|
82
|
+
*
|
83
|
+
* Call +virNWFilterLookupByUUIDString+[http://www.libvirt.org/html/libvirt-libvirt.html#virNWFilterLookupByUUIDString]
|
84
|
+
*/
|
85
|
+
static VALUE libvirt_conn_lookup_nwfilter_by_uuid(VALUE c, VALUE uuid) {
|
86
|
+
virNWFilterPtr nwfilter;
|
87
|
+
virConnectPtr conn = connect_get(c);
|
88
|
+
|
89
|
+
nwfilter = virNWFilterLookupByUUIDString(conn, StringValueCStr(uuid));
|
90
|
+
_E(nwfilter == NULL, create_error(e_RetrieveError, "virNWFilterLookupByUUIDString", "", conn));
|
91
|
+
|
92
|
+
return nwfilter_new(nwfilter, c);
|
93
|
+
}
|
94
|
+
|
95
|
+
/*
|
96
|
+
* call-seq:
|
97
|
+
* conn.define_nwfilter_xml -> Libvirt::NWFilter
|
98
|
+
*
|
99
|
+
* Call +virNWFilterDefineXML+[http://www.libvirt.org/html/libvirt-libvirt.html#virNWFilterDefineXML]
|
100
|
+
*/
|
101
|
+
static VALUE libvirt_conn_define_nwfilter_xml(VALUE c, VALUE xml) {
|
102
|
+
virNWFilterPtr nwfilter;
|
103
|
+
virConnectPtr conn = connect_get(c);
|
104
|
+
|
105
|
+
nwfilter = virNWFilterDefineXML(conn, StringValueCStr(xml));
|
106
|
+
_E(nwfilter == NULL, create_error(e_DefinitionError, "virNWFilterDefineXML", "", conn));
|
107
|
+
|
108
|
+
return nwfilter_new(nwfilter, c);
|
109
|
+
}
|
110
|
+
|
111
|
+
/*
|
112
|
+
* call-seq:
|
113
|
+
* nwfilter.undefine -> nil
|
114
|
+
*
|
115
|
+
* Call +virNWFilterUndefine+[http://www.libvirt.org/html/libvirt-libvirt.html#virNWFilterUndefine]
|
116
|
+
*/
|
117
|
+
static VALUE libvirt_nwfilter_undefine(VALUE s) {
|
118
|
+
gen_call_void(virNWFilterUndefine, conn(s), nwfilter_get(s));
|
119
|
+
}
|
120
|
+
|
121
|
+
/*
|
122
|
+
* call-seq:
|
123
|
+
* nwfilter.name -> string
|
124
|
+
*
|
125
|
+
* Call +virNWFilterGetName+[http://www.libvirt.org/html/libvirt-libvirt.html#virNWFilterGetName]
|
126
|
+
*/
|
127
|
+
static VALUE libvirt_nwfilter_name(VALUE s) {
|
128
|
+
gen_call_string(virNWFilterGetName, conn(s), 0, nwfilter_get(s));
|
129
|
+
}
|
130
|
+
|
131
|
+
/*
|
132
|
+
* call-seq:
|
133
|
+
* nwfilter.uuid -> string
|
134
|
+
*
|
135
|
+
* Call +virNWFilterGetUUIDString+[http://www.libvirt.org/html/libvirt-libvirt.html#virNWFilterGetUUIDString]
|
136
|
+
*/
|
137
|
+
static VALUE libvirt_nwfilter_uuid(VALUE s) {
|
138
|
+
virNWFilterPtr nwfilter = nwfilter_get(s);
|
139
|
+
int r;
|
140
|
+
char uuid[VIR_UUID_STRING_BUFLEN];
|
141
|
+
|
142
|
+
r = virNWFilterGetUUIDString(nwfilter, uuid);
|
143
|
+
_E(r < 0, create_error(e_RetrieveError, "virNWFilterGetUUIDString", "", conn(s)));
|
144
|
+
|
145
|
+
return rb_str_new2((char *)uuid);
|
146
|
+
}
|
147
|
+
|
148
|
+
/*
|
149
|
+
* call-seq:
|
150
|
+
* nwfilter.xml_desc -> string
|
151
|
+
*
|
152
|
+
* Call +virNWFilterGetXMLDesc+[http://www.libvirt.org/html/libvirt-libvirt.html#virNWFilterGetXMLDesc]
|
153
|
+
*/
|
154
|
+
static VALUE libvirt_nwfilter_xml_desc(int argc, VALUE *argv, VALUE s) {
|
155
|
+
VALUE flags;
|
156
|
+
|
157
|
+
rb_scan_args(argc, argv, "01", &flags);
|
158
|
+
|
159
|
+
if (NIL_P(flags))
|
160
|
+
flags = INT2FIX(0);
|
161
|
+
|
162
|
+
gen_call_string(virNWFilterGetXMLDesc, conn(s), 1, nwfilter_get(s),
|
163
|
+
NUM2UINT(flags));
|
164
|
+
}
|
165
|
+
|
166
|
+
/*
|
167
|
+
* call-seq:
|
168
|
+
* nwfilter.free -> nil
|
169
|
+
*
|
170
|
+
* Call +virNWFilterFree+[http://www.libvirt.org/html/libvirt-libvirt.html#virNWFilterFree]
|
171
|
+
*/
|
172
|
+
static VALUE libvirt_nwfilter_free(VALUE s) {
|
173
|
+
gen_call_free(NWFilter, s);
|
174
|
+
}
|
175
|
+
|
176
|
+
#endif
|
177
|
+
|
178
|
+
/*
|
179
|
+
* Class Libvirt::NWFilter
|
180
|
+
*/
|
181
|
+
void init_nwfilter()
|
182
|
+
{
|
183
|
+
#if HAVE_TYPE_VIRNWFILTERPTR
|
184
|
+
c_nwfilter = rb_define_class_under(m_libvirt, "NWFilter", rb_cObject);
|
185
|
+
rb_define_attr(c_nwfilter, "connection", 1, 0);
|
186
|
+
|
187
|
+
/* NWFilter lookup/creation methods */
|
188
|
+
rb_define_method(c_connect, "num_of_nwfilters",
|
189
|
+
libvirt_conn_num_of_nwfilters, 0);
|
190
|
+
rb_define_method(c_connect, "list_nwfilters",
|
191
|
+
libvirt_conn_list_nwfilters, 0);
|
192
|
+
rb_define_method(c_connect, "lookup_nwfilter_by_name",
|
193
|
+
libvirt_conn_lookup_nwfilter_by_name, 1);
|
194
|
+
rb_define_method(c_connect, "lookup_nwfilter_by_uuid",
|
195
|
+
libvirt_conn_lookup_nwfilter_by_uuid, 1);
|
196
|
+
rb_define_method(c_connect, "define_nwfilter_xml",
|
197
|
+
libvirt_conn_define_nwfilter_xml, 1);
|
198
|
+
|
199
|
+
/* NWFilter object methods */
|
200
|
+
rb_define_method(c_nwfilter, "undefine", libvirt_nwfilter_undefine, 0);
|
201
|
+
rb_define_method(c_nwfilter, "name", libvirt_nwfilter_name, 0);
|
202
|
+
rb_define_method(c_nwfilter, "uuid", libvirt_nwfilter_uuid, 0);
|
203
|
+
rb_define_method(c_nwfilter, "xml_desc", libvirt_nwfilter_xml_desc, -1);
|
204
|
+
rb_define_method(c_nwfilter, "free", libvirt_nwfilter_free, 0);
|
205
|
+
#endif
|
206
|
+
}
|