ruby-libvirt-catphish 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,8 @@
1
+ #ifndef NETWORK_H
2
+ #define NETWORK_H
3
+
4
+ void ruby_libvirt_network_init(void);
5
+
6
+ VALUE ruby_libvirt_network_new(virNetworkPtr n, VALUE conn);
7
+
8
+ #endif
@@ -0,0 +1,299 @@
1
+ /*
2
+ * nodedevice.c: virNodeDevice methods
3
+ *
4
+ * Copyright (C) 2010 Red Hat Inc.
5
+ * Copyright (C) 2013-2016 Chris Lalancette <clalancette@gmail.com>
6
+ *
7
+ * This library is free software; you can redistribute it and/or
8
+ * modify it under the terms of the GNU Lesser General Public
9
+ * License as published by the Free Software Foundation; either
10
+ * version 2.1 of the License, or (at your option) any later version.
11
+ *
12
+ * This library is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ * Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public
18
+ * License along with this library; if not, write to the Free Software
19
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ */
21
+
22
+ #include <ruby.h>
23
+ #include <libvirt/libvirt.h>
24
+ #include <libvirt/virterror.h>
25
+ #include "common.h"
26
+ #include "connect.h"
27
+ #include "extconf.h"
28
+
29
+ #if HAVE_TYPE_VIRNODEDEVICEPTR
30
+ static VALUE c_nodedevice;
31
+
32
+ static void nodedevice_free(void *s)
33
+ {
34
+ ruby_libvirt_free_struct(NodeDevice, s);
35
+ }
36
+
37
+ static virNodeDevicePtr nodedevice_get(VALUE n)
38
+ {
39
+ ruby_libvirt_get_struct(NodeDevice, n);
40
+ }
41
+
42
+ VALUE ruby_libvirt_nodedevice_new(virNodeDevicePtr n, VALUE conn)
43
+ {
44
+ return ruby_libvirt_new_class(c_nodedevice, n, conn, nodedevice_free);
45
+ }
46
+
47
+ /*
48
+ * call-seq:
49
+ * nodedevice.name -> String
50
+ *
51
+ * Call virNodeDeviceGetName[http://www.libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceGetName]
52
+ * to retrieve the name of the node device.
53
+ */
54
+ static VALUE libvirt_nodedevice_name(VALUE c)
55
+ {
56
+ ruby_libvirt_generate_call_string(virNodeDeviceGetName,
57
+ ruby_libvirt_connect_get(c), 0,
58
+ nodedevice_get(c));
59
+ }
60
+
61
+ /*
62
+ * call-seq:
63
+ * nodedevice.parent -> String
64
+ *
65
+ * Call virNodeDeviceGetParent[http://www.libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceGetParent]
66
+ * to retrieve the parent of the node device.
67
+ */
68
+ static VALUE libvirt_nodedevice_parent(VALUE c)
69
+ {
70
+ /* unfortunately we can't use ruby_libvirt_generate_call_string() here
71
+ * because virNodeDeviceGetParent() returns NULL as a valid value (when this
72
+ * device has no parent). Hand-code it instead
73
+ */
74
+
75
+ const char *str;
76
+
77
+ str = virNodeDeviceGetParent(nodedevice_get(c));
78
+ if (str == NULL) {
79
+ return Qnil;
80
+ }
81
+ else {
82
+ return rb_str_new2(str);
83
+ }
84
+ }
85
+
86
+ /*
87
+ * call-seq:
88
+ * nodedevice.num_of_caps -> Fixnum
89
+ *
90
+ * Call virNodeDeviceNumOfCaps[http://www.libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceNumOfCaps]
91
+ * to retrieve the number of capabilities of the node device.
92
+ */
93
+ static VALUE libvirt_nodedevice_num_of_caps(VALUE c)
94
+ {
95
+ ruby_libvirt_generate_call_int(virNodeDeviceNumOfCaps,
96
+ ruby_libvirt_connect_get(c),
97
+ nodedevice_get(c));
98
+ }
99
+
100
+ /*
101
+ * call-seq:
102
+ * nodedevice.list_caps -> list
103
+ *
104
+ * Call virNodeDeviceListCaps[http://www.libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceListCaps]
105
+ * to retrieve a list of capabilities of the node device.
106
+ */
107
+ static VALUE libvirt_nodedevice_list_caps(VALUE c)
108
+ {
109
+ int r, num;
110
+ char **names;
111
+
112
+ num = virNodeDeviceNumOfCaps(nodedevice_get(c));
113
+ ruby_libvirt_raise_error_if(num < 0, e_RetrieveError,
114
+ "virNodeDeviceNumOfCaps",
115
+ ruby_libvirt_connect_get(c));
116
+ if (num == 0) {
117
+ /* if num is 0, don't call virNodeDeviceListCaps function */
118
+ return rb_ary_new2(num);
119
+ }
120
+
121
+ names = alloca(sizeof(char *) * num);
122
+ r = virNodeDeviceListCaps(nodedevice_get(c), names, num);
123
+ ruby_libvirt_raise_error_if(r < 0, e_RetrieveError,
124
+ "virNodeDeviceListCaps",
125
+ ruby_libvirt_connect_get(c));
126
+
127
+ return ruby_libvirt_generate_list(r, names);
128
+ }
129
+
130
+ /*
131
+ * call-seq:
132
+ * nodedevice.xml_desc(flags=0) -> String
133
+ *
134
+ * Call virNodeDeviceGetXMLDesc[http://www.libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceGetXMLDesc]
135
+ * to retrieve the XML for the node device.
136
+ */
137
+ static VALUE libvirt_nodedevice_xml_desc(int argc, VALUE *argv, VALUE n)
138
+ {
139
+ VALUE flags = RUBY_Qnil;
140
+
141
+ rb_scan_args(argc, argv, "01", &flags);
142
+
143
+ ruby_libvirt_generate_call_string(virNodeDeviceGetXMLDesc,
144
+ ruby_libvirt_connect_get(n),
145
+ 1, nodedevice_get(n),
146
+ ruby_libvirt_value_to_uint(flags));
147
+ }
148
+
149
+ /*
150
+ * call-seq:
151
+ * nodedevice.detach(driver=nil, flags=0) -> nil
152
+ *
153
+ * Call virNodeDeviceDettach[http://www.libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceDettach]
154
+ * to detach the node device from the node.
155
+ */
156
+ static VALUE libvirt_nodedevice_detach(int argc, VALUE *argv, VALUE n)
157
+ {
158
+ VALUE driver = RUBY_Qnil, flags = RUBY_Qnil;
159
+
160
+ rb_scan_args(argc, argv, "02", &driver, &flags);
161
+
162
+ #if HAVE_VIRNODEDEVICEDETACHFLAGS
163
+ ruby_libvirt_generate_call_nil(virNodeDeviceDetachFlags,
164
+ ruby_libvirt_connect_get(n),
165
+ nodedevice_get(n),
166
+ ruby_libvirt_get_cstring_or_null(driver),
167
+ ruby_libvirt_value_to_uint(flags));
168
+ #else
169
+ if (ruby_libvirt_value_to_uint(flags) != 0) {
170
+ rb_raise(e_NoSupportError, "Non-zero flags not supported");
171
+ }
172
+
173
+ if (ruby_libvirt_get_cstring_or_null(driver) != NULL) {
174
+ rb_raise(e_NoSupportError, "Non-NULL driver not supported");
175
+ }
176
+
177
+ ruby_libvirt_generate_call_nil(virNodeDeviceDettach,
178
+ ruby_libvirt_connect_get(n),
179
+ nodedevice_get(n));
180
+ #endif
181
+ }
182
+
183
+ /*
184
+ * call-seq:
185
+ * nodedevice.reattach -> nil
186
+ *
187
+ * Call virNodeDeviceReAttach[http://www.libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceReAttach]
188
+ * to reattach the node device to the node.
189
+ */
190
+ static VALUE libvirt_nodedevice_reattach(VALUE n)
191
+ {
192
+ ruby_libvirt_generate_call_nil(virNodeDeviceReAttach,
193
+ ruby_libvirt_connect_get(n),
194
+ nodedevice_get(n));
195
+ }
196
+
197
+ /*
198
+ * call-seq:
199
+ * nodedevice.reset -> nil
200
+ *
201
+ * Call virNodeDeviceReset[http://www.libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceReset]
202
+ * to reset the node device.
203
+ */
204
+ static VALUE libvirt_nodedevice_reset(VALUE n)
205
+ {
206
+ ruby_libvirt_generate_call_nil(virNodeDeviceReset,
207
+ ruby_libvirt_connect_get(n),
208
+ nodedevice_get(n));
209
+ }
210
+
211
+ #if HAVE_VIRNODEDEVICEDESTROY
212
+ /*
213
+ * call-seq:
214
+ * nodedevice.destroy -> nil
215
+ *
216
+ * Call virNodeDeviceDestroy[http://www.libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceDestroy]
217
+ * to shutdown the node device.
218
+ */
219
+ static VALUE libvirt_nodedevice_destroy(VALUE n)
220
+ {
221
+ ruby_libvirt_generate_call_nil(virNodeDeviceDestroy,
222
+ ruby_libvirt_connect_get(n),
223
+ nodedevice_get(n));
224
+ }
225
+ #endif
226
+
227
+ /*
228
+ * call-seq:
229
+ * nodedevice.free -> nil
230
+ *
231
+ * Call virNodeDeviceFree[http://www.libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceFree]
232
+ * to free the node device object. After this call the node device object is
233
+ * no longer valid.
234
+ */
235
+ static VALUE libvirt_nodedevice_free(VALUE n)
236
+ {
237
+ ruby_libvirt_generate_call_free(NodeDevice, n);
238
+ }
239
+
240
+ #if HAVE_VIRNODEDEVICELOOKUPSCSIHOSTBYWWN
241
+ /*
242
+ * call-seq:
243
+ * nodedevice.lookup_scsi_host_by_wwn(wwnn, wwpn, flags=0) -> Libvirt::NodeDevice
244
+ *
245
+ * Call virNodeDeviceLookupSCSIHostByWWN[http://www.libvirt.org/html/libvirt-libvirt-nodedev.html#virNodeDeviceLookupSCSIHostByWWN]
246
+ * to look up a SCSI host by its WWNN and WWPN.
247
+ */
248
+ static VALUE libvirt_nodedevice_lookup_scsi_host_by_wwn(int argc, VALUE *argv,
249
+ VALUE n)
250
+ {
251
+ VALUE wwnn, wwpn, flags = RUBY_Qnil;
252
+ virNodeDevicePtr nd;
253
+
254
+ rb_scan_args(argc, argv, "21", &wwnn, &wwpn, &flags);
255
+
256
+ nd = virNodeDeviceLookupSCSIHostByWWN(ruby_libvirt_connect_get(n),
257
+ StringValueCStr(wwnn),
258
+ StringValueCStr(wwpn),
259
+ ruby_libvirt_value_to_uint(flags));
260
+ if (nd == NULL) {
261
+ return Qnil;
262
+ }
263
+
264
+ return ruby_libvirt_nodedevice_new(nd, ruby_libvirt_conn_attr(n));
265
+ }
266
+ #endif
267
+
268
+ #endif
269
+
270
+ /*
271
+ * Class Libvirt::NodeDevice
272
+ */
273
+ void ruby_libvirt_nodedevice_init(void)
274
+ {
275
+ #if HAVE_TYPE_VIRNODEDEVICEPTR
276
+ c_nodedevice = rb_define_class_under(m_libvirt, "NodeDevice", rb_cObject);
277
+
278
+ rb_define_attr(c_nodedevice, "connection", 1, 0);
279
+
280
+ rb_define_method(c_nodedevice, "name", libvirt_nodedevice_name, 0);
281
+ rb_define_method(c_nodedevice, "parent", libvirt_nodedevice_parent, 0);
282
+ rb_define_method(c_nodedevice, "num_of_caps",
283
+ libvirt_nodedevice_num_of_caps, 0);
284
+ rb_define_method(c_nodedevice, "list_caps",
285
+ libvirt_nodedevice_list_caps, 0);
286
+ rb_define_method(c_nodedevice, "xml_desc", libvirt_nodedevice_xml_desc, -1);
287
+ rb_define_method(c_nodedevice, "detach", libvirt_nodedevice_detach, -1);
288
+ rb_define_method(c_nodedevice, "reattach", libvirt_nodedevice_reattach, 0);
289
+ rb_define_method(c_nodedevice, "reset", libvirt_nodedevice_reset, 0);
290
+ #if HAVE_VIRNODEDEVICEDESTROY
291
+ rb_define_method(c_nodedevice, "destroy", libvirt_nodedevice_destroy, 0);
292
+ #endif
293
+ rb_define_method(c_nodedevice, "free", libvirt_nodedevice_free, 0);
294
+ #if HAVE_VIRNODEDEVICELOOKUPSCSIHOSTBYWWN
295
+ rb_define_method(c_nodedevice, "lookup_scsi_host_by_wwn",
296
+ libvirt_nodedevice_lookup_scsi_host_by_wwn, -1);
297
+ #endif
298
+ #endif
299
+ }
@@ -0,0 +1,8 @@
1
+ #ifndef NODEDEVICE_H
2
+ #define NODEDEVICE_H
3
+
4
+ void ruby_libvirt_nodedevice_init(void);
5
+
6
+ VALUE ruby_libvirt_nodedevice_new(virNodeDevicePtr n, VALUE conn);
7
+
8
+ #endif
@@ -0,0 +1,138 @@
1
+ /*
2
+ * nwfilter.c: virNWFilter methods
3
+ *
4
+ * Copyright (C) 2010 Red Hat Inc.
5
+ * Copyright (C) 2013-2016 Chris Lalancette <clalancette@gmail.com>
6
+ *
7
+ * This library is free software; you can redistribute it and/or
8
+ * modify it under the terms of the GNU Lesser General Public
9
+ * License as published by the Free Software Foundation; either
10
+ * version 2.1 of the License, or (at your option) any later version.
11
+ *
12
+ * This library is distributed in the hope that it will be useful,
13
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ * Lesser General Public License for more details.
16
+ *
17
+ * You should have received a copy of the GNU Lesser General Public
18
+ * License along with this library; if not, write to the Free Software
19
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+ */
21
+
22
+ #include <ruby.h>
23
+ #include <libvirt/libvirt.h>
24
+ #include <libvirt/virterror.h>
25
+ #include "common.h"
26
+ #include "connect.h"
27
+ #include "extconf.h"
28
+
29
+ #if HAVE_TYPE_VIRNWFILTERPTR
30
+ static VALUE c_nwfilter;
31
+
32
+ static void nwfilter_free(void *n)
33
+ {
34
+ ruby_libvirt_free_struct(NWFilter, n);
35
+ }
36
+
37
+ static virNWFilterPtr nwfilter_get(VALUE n)
38
+ {
39
+ ruby_libvirt_get_struct(NWFilter, n);
40
+ }
41
+
42
+ VALUE ruby_libvirt_nwfilter_new(virNWFilterPtr n, VALUE conn)
43
+ {
44
+ return ruby_libvirt_new_class(c_nwfilter, n, conn, nwfilter_free);
45
+ }
46
+
47
+ /*
48
+ * call-seq:
49
+ * nwfilter.undefine -> nil
50
+ *
51
+ * Call virNWFilterUndefine[http://www.libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterUndefine]
52
+ * to undefine the network filter.
53
+ */
54
+ static VALUE libvirt_nwfilter_undefine(VALUE n)
55
+ {
56
+ ruby_libvirt_generate_call_nil(virNWFilterUndefine,
57
+ ruby_libvirt_connect_get(n),
58
+ nwfilter_get(n));
59
+ }
60
+
61
+ /*
62
+ * call-seq:
63
+ * nwfilter.name -> String
64
+ *
65
+ * Call virNWFilterGetName[http://www.libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterGetName]
66
+ * to retrieve the network filter name.
67
+ */
68
+ static VALUE libvirt_nwfilter_name(VALUE n)
69
+ {
70
+ ruby_libvirt_generate_call_string(virNWFilterGetName,
71
+ ruby_libvirt_connect_get(n), 0,
72
+ nwfilter_get(n));
73
+ }
74
+
75
+ /*
76
+ * call-seq:
77
+ * nwfilter.uuid -> String
78
+ *
79
+ * Call virNWFilterGetUUIDString[http://www.libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterGetUUIDString]
80
+ * to retrieve the network filter UUID.
81
+ */
82
+ static VALUE libvirt_nwfilter_uuid(VALUE n)
83
+ {
84
+ ruby_libvirt_generate_uuid(virNWFilterGetUUIDString,
85
+ ruby_libvirt_connect_get(n), nwfilter_get(n));
86
+ }
87
+
88
+ /*
89
+ * call-seq:
90
+ * nwfilter.xml_desc(flags=0) -> String
91
+ *
92
+ * Call virNWFilterGetXMLDesc[http://www.libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterGetXMLDesc]
93
+ * to retrieve the XML for this network filter.
94
+ */
95
+ static VALUE libvirt_nwfilter_xml_desc(int argc, VALUE *argv, VALUE n)
96
+ {
97
+ VALUE flags = RUBY_Qnil;
98
+
99
+ rb_scan_args(argc, argv, "01", &flags);
100
+
101
+ ruby_libvirt_generate_call_string(virNWFilterGetXMLDesc,
102
+ ruby_libvirt_connect_get(n), 1,
103
+ nwfilter_get(n),
104
+ ruby_libvirt_value_to_uint(flags));
105
+ }
106
+
107
+ /*
108
+ * call-seq:
109
+ * nwfilter.free -> nil
110
+ *
111
+ * Call virNWFilterFree[http://www.libvirt.org/html/libvirt-libvirt-nwfilter.html#virNWFilterFree]
112
+ * to free this network filter. After this call the network filter object is
113
+ * no longer valid.
114
+ */
115
+ static VALUE libvirt_nwfilter_free(VALUE n)
116
+ {
117
+ ruby_libvirt_generate_call_free(NWFilter, n);
118
+ }
119
+
120
+ #endif
121
+
122
+ /*
123
+ * Class Libvirt::NWFilter
124
+ */
125
+ void ruby_libvirt_nwfilter_init(void)
126
+ {
127
+ #if HAVE_TYPE_VIRNWFILTERPTR
128
+ c_nwfilter = rb_define_class_under(m_libvirt, "NWFilter", rb_cObject);
129
+ rb_define_attr(c_nwfilter, "connection", 1, 0);
130
+
131
+ /* NWFilter object methods */
132
+ rb_define_method(c_nwfilter, "undefine", libvirt_nwfilter_undefine, 0);
133
+ rb_define_method(c_nwfilter, "name", libvirt_nwfilter_name, 0);
134
+ rb_define_method(c_nwfilter, "uuid", libvirt_nwfilter_uuid, 0);
135
+ rb_define_method(c_nwfilter, "xml_desc", libvirt_nwfilter_xml_desc, -1);
136
+ rb_define_method(c_nwfilter, "free", libvirt_nwfilter_free, 0);
137
+ #endif
138
+ }