ruby-libvirt-catphish 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,200 @@
1
+ /*
2
+ * interface.c: virInterface 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_VIRINTERFACEPTR
30
+ static VALUE c_interface;
31
+
32
+ static void interface_free(void *i)
33
+ {
34
+ ruby_libvirt_free_struct(Interface, i);
35
+ }
36
+
37
+ static virInterfacePtr interface_get(VALUE i)
38
+ {
39
+ ruby_libvirt_get_struct(Interface, i);
40
+ }
41
+
42
+ VALUE ruby_libvirt_interface_new(virInterfacePtr i, VALUE conn)
43
+ {
44
+ return ruby_libvirt_new_class(c_interface, i, conn, interface_free);
45
+ }
46
+
47
+ /*
48
+ * call-seq:
49
+ * interface.undefine -> nil
50
+ *
51
+ * Call virInterfaceUndefine[http://www.libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceUndefine]
52
+ * to undefine this interface.
53
+ */
54
+ static VALUE libvirt_interface_undefine(VALUE i)
55
+ {
56
+ ruby_libvirt_generate_call_nil(virInterfaceUndefine,
57
+ ruby_libvirt_connect_get(i),
58
+ interface_get(i));
59
+ }
60
+
61
+ /*
62
+ * call-seq:
63
+ * interface.create(flags=0) -> nil
64
+ *
65
+ * Call virInterfaceCreate[http://www.libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceCreate]
66
+ * to start this interface.
67
+ */
68
+ static VALUE libvirt_interface_create(int argc, VALUE *argv, VALUE i)
69
+ {
70
+ VALUE flags = RUBY_Qnil;
71
+
72
+ rb_scan_args(argc, argv, "01", &flags);
73
+
74
+ ruby_libvirt_generate_call_nil(virInterfaceCreate,
75
+ ruby_libvirt_connect_get(i),
76
+ interface_get(i),
77
+ ruby_libvirt_value_to_uint(flags));
78
+ }
79
+
80
+ /*
81
+ * call-seq:
82
+ * interface.destroy(flags=0) -> nil
83
+ *
84
+ * Call virInterfaceDestroy[http://www.libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceDestroy]
85
+ * to shutdown this interface.
86
+ */
87
+ static VALUE libvirt_interface_destroy(int argc, VALUE *argv, VALUE i)
88
+ {
89
+ VALUE flags = RUBY_Qnil;
90
+
91
+ rb_scan_args(argc, argv, "01", &flags);
92
+
93
+ ruby_libvirt_generate_call_nil(virInterfaceDestroy,
94
+ ruby_libvirt_connect_get(i),
95
+ interface_get(i),
96
+ ruby_libvirt_value_to_uint(flags));
97
+ }
98
+
99
+ #if HAVE_VIRINTERFACEISACTIVE
100
+ /*
101
+ * call-seq:
102
+ * interface.active? -> [true|false]
103
+ *
104
+ * Call virInterfaceIsActive[http://www.libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceIsActive]
105
+ * to determine if this interface is currently active.
106
+ */
107
+ static VALUE libvirt_interface_active_p(VALUE p)
108
+ {
109
+ ruby_libvirt_generate_call_truefalse(virInterfaceIsActive,
110
+ ruby_libvirt_connect_get(p),
111
+ interface_get(p));
112
+ }
113
+ #endif
114
+
115
+ /*
116
+ * call-seq:
117
+ * interface.name -> String
118
+ *
119
+ * Call virInterfaceGetName[http://www.libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetName]
120
+ * to retrieve the name of this interface.
121
+ */
122
+ static VALUE libvirt_interface_name(VALUE i)
123
+ {
124
+ ruby_libvirt_generate_call_string(virInterfaceGetName,
125
+ ruby_libvirt_connect_get(i), 0,
126
+ interface_get(i));
127
+ }
128
+
129
+ /*
130
+ * call-seq:
131
+ * interface.mac -> String
132
+ *
133
+ * Call virInterfaceGetMACString[http://www.libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetMACString]
134
+ * to retrieve the MAC address of this interface.
135
+ */
136
+ static VALUE libvirt_interface_mac(VALUE i)
137
+ {
138
+ ruby_libvirt_generate_call_string(virInterfaceGetMACString,
139
+ ruby_libvirt_connect_get(i),
140
+ 0, interface_get(i));
141
+ }
142
+
143
+ /*
144
+ * call-seq:
145
+ * interface.xml_desc -> String
146
+ *
147
+ * Call virInterfaceGetXMLDesc[http://www.libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceGetXMLDesc]
148
+ * to retrieve the XML of this interface.
149
+ */
150
+ static VALUE libvirt_interface_xml_desc(int argc, VALUE *argv, VALUE i)
151
+ {
152
+ VALUE flags = RUBY_Qnil;
153
+
154
+ rb_scan_args(argc, argv, "01", &flags);
155
+
156
+ ruby_libvirt_generate_call_string(virInterfaceGetXMLDesc,
157
+ ruby_libvirt_connect_get(i),
158
+ 1, interface_get(i),
159
+ ruby_libvirt_value_to_uint(flags));
160
+ }
161
+
162
+ /*
163
+ * call-seq:
164
+ * interface.free -> nil
165
+ *
166
+ * Call virInterfaceFree[http://www.libvirt.org/html/libvirt-libvirt-interface.html#virInterfaceFree]
167
+ * to free this interface. The object will no longer be valid after this call.
168
+ */
169
+ static VALUE libvirt_interface_free(VALUE i)
170
+ {
171
+ ruby_libvirt_generate_call_free(Interface, i);
172
+ }
173
+ #endif
174
+
175
+ /*
176
+ * Class Libvirt::Interface
177
+ */
178
+ void ruby_libvirt_interface_init(void)
179
+ {
180
+ #if HAVE_TYPE_VIRINTERFACEPTR
181
+ c_interface = rb_define_class_under(m_libvirt, "Interface", rb_cObject);
182
+ #if HAVE_CONST_VIR_INTERFACE_XML_INACTIVE
183
+ rb_define_const(c_interface, "XML_INACTIVE",
184
+ INT2NUM(VIR_INTERFACE_XML_INACTIVE));
185
+ #endif
186
+ rb_define_attr(c_interface, "connection", 1, 0);
187
+
188
+ /* Interface object methods */
189
+ rb_define_method(c_interface, "name", libvirt_interface_name, 0);
190
+ rb_define_method(c_interface, "mac", libvirt_interface_mac, 0);
191
+ rb_define_method(c_interface, "xml_desc", libvirt_interface_xml_desc, -1);
192
+ rb_define_method(c_interface, "undefine", libvirt_interface_undefine, 0);
193
+ rb_define_method(c_interface, "create", libvirt_interface_create, -1);
194
+ rb_define_method(c_interface, "destroy", libvirt_interface_destroy, -1);
195
+ rb_define_method(c_interface, "free", libvirt_interface_free, 0);
196
+ #if HAVE_VIRINTERFACEISACTIVE
197
+ rb_define_method(c_interface, "active?", libvirt_interface_active_p, 0);
198
+ #endif
199
+ #endif
200
+ }
@@ -0,0 +1,8 @@
1
+ #ifndef INTERFACE_H
2
+ #define INTERFACE_H
3
+
4
+ void ruby_libvirt_interface_init(void);
5
+
6
+ VALUE ruby_libvirt_interface_new(virInterfacePtr i, VALUE conn);
7
+
8
+ #endif
@@ -0,0 +1,555 @@
1
+ /*
2
+ * network.c: virNetwork methods
3
+ *
4
+ * Copyright (C) 2007,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_VIRNETWORKPTR
30
+ static VALUE c_network;
31
+
32
+ static void network_free(void *d)
33
+ {
34
+ ruby_libvirt_free_struct(Network, d);
35
+ }
36
+
37
+ static virNetworkPtr network_get(VALUE n)
38
+ {
39
+ ruby_libvirt_get_struct(Network, n);
40
+ }
41
+
42
+ VALUE ruby_libvirt_network_new(virNetworkPtr n, VALUE conn)
43
+ {
44
+ return ruby_libvirt_new_class(c_network, n, conn, network_free);
45
+ }
46
+
47
+ /*
48
+ * call-seq:
49
+ * net.undefine -> nil
50
+ *
51
+ * Call virNetworkUndefine[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkUndefine]
52
+ * to undefine this network.
53
+ */
54
+ static VALUE libvirt_network_undefine(VALUE n)
55
+ {
56
+ ruby_libvirt_generate_call_nil(virNetworkUndefine,
57
+ ruby_libvirt_connect_get(n),
58
+ network_get(n));
59
+ }
60
+
61
+ /*
62
+ * call-seq:
63
+ * net.create -> nil
64
+ *
65
+ * Call virNetworkCreate[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkCreate]
66
+ * to start this network.
67
+ */
68
+ static VALUE libvirt_network_create(VALUE n)
69
+ {
70
+ ruby_libvirt_generate_call_nil(virNetworkCreate,
71
+ ruby_libvirt_connect_get(n),
72
+ network_get(n));
73
+ }
74
+
75
+ #if HAVE_VIRNETWORKUPDATE
76
+ /*
77
+ * call-seq:
78
+ * net.update -> nil
79
+ *
80
+ * Call virNetworkUpdate[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkUpdate]
81
+ * to update this network.
82
+ */
83
+ static VALUE libvirt_network_update(VALUE n, VALUE command, VALUE section,
84
+ VALUE index, VALUE xml, VALUE flags)
85
+ {
86
+ ruby_libvirt_generate_call_nil(virNetworkUpdate,
87
+ ruby_libvirt_connect_get(n),
88
+ network_get(n), NUM2UINT(command),
89
+ NUM2UINT(section), NUM2INT(index),
90
+ StringValuePtr(xml), NUM2UINT(flags));
91
+ }
92
+ #endif
93
+
94
+ /*
95
+ * call-seq:
96
+ * net.destroy -> nil
97
+ *
98
+ * Call virNetworkDestroy[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkDestroy]
99
+ * to shutdown this network.
100
+ */
101
+ static VALUE libvirt_network_destroy(VALUE n)
102
+ {
103
+ ruby_libvirt_generate_call_nil(virNetworkDestroy,
104
+ ruby_libvirt_connect_get(n),
105
+ network_get(n));
106
+ }
107
+
108
+ /*
109
+ * call-seq:
110
+ * net.name -> String
111
+ *
112
+ * Call virNetworkGetName[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetName]
113
+ * to retrieve the name of this network.
114
+ */
115
+ static VALUE libvirt_network_name(VALUE n)
116
+ {
117
+ ruby_libvirt_generate_call_string(virNetworkGetName,
118
+ ruby_libvirt_connect_get(n), 0,
119
+ network_get(n));
120
+ }
121
+
122
+ /*
123
+ * call-seq:
124
+ * net.uuid -> String
125
+ *
126
+ * Call virNetworkGetUUIDString[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetUUIDString]
127
+ * to retrieve the UUID of this network.
128
+ */
129
+ static VALUE libvirt_network_uuid(VALUE n)
130
+ {
131
+ ruby_libvirt_generate_uuid(virNetworkGetUUIDString,
132
+ ruby_libvirt_connect_get(n), network_get(n));
133
+ }
134
+
135
+ /*
136
+ * call-seq:
137
+ * net.xml_desc(flags=0) -> String
138
+ *
139
+ * Call virNetworkGetXMLDesc[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetXMLDesc]
140
+ * to retrieve the XML for this network.
141
+ */
142
+ static VALUE libvirt_network_xml_desc(int argc, VALUE *argv, VALUE n)
143
+ {
144
+ VALUE flags = RUBY_Qnil;
145
+
146
+ rb_scan_args(argc, argv, "01", &flags);
147
+
148
+ ruby_libvirt_generate_call_string(virNetworkGetXMLDesc,
149
+ ruby_libvirt_connect_get(n), 1,
150
+ network_get(n),
151
+ ruby_libvirt_value_to_uint(flags));
152
+ }
153
+
154
+ /*
155
+ * call-seq:
156
+ * net.bridge_name -> String
157
+ *
158
+ * Call virNetworkGetBridgeName[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetBridgeName]
159
+ * to retrieve the bridge name for this network.
160
+ */
161
+ static VALUE libvirt_network_bridge_name(VALUE n)
162
+ {
163
+ ruby_libvirt_generate_call_string(virNetworkGetBridgeName,
164
+ ruby_libvirt_connect_get(n),
165
+ 1, network_get(n));
166
+ }
167
+
168
+ /*
169
+ * call-seq:
170
+ * net.autostart? -> [true|false]
171
+ *
172
+ * Call virNetworkGetAutostart[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetAutostart]
173
+ * to determine if this network will be autostarted when libvirtd starts.
174
+ */
175
+ static VALUE libvirt_network_autostart(VALUE n)
176
+ {
177
+ int r, autostart;
178
+
179
+ r = virNetworkGetAutostart(network_get(n), &autostart);
180
+ ruby_libvirt_raise_error_if(r < 0, e_RetrieveError, "virNetworkAutostart",
181
+ ruby_libvirt_connect_get(n));
182
+
183
+ return autostart ? Qtrue : Qfalse;
184
+ }
185
+
186
+ /*
187
+ * call-seq:
188
+ * net.autostart = [true|false]
189
+ *
190
+ * Call virNetworkSetAutostart[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkSetAutostart]
191
+ * to set this network to be autostarted when libvirtd starts.
192
+ */
193
+ static VALUE libvirt_network_autostart_equal(VALUE n, VALUE autostart)
194
+ {
195
+ if (autostart != Qtrue && autostart != Qfalse) {
196
+ rb_raise(rb_eTypeError,
197
+ "wrong argument type (expected TrueClass or FalseClass)");
198
+ }
199
+
200
+ ruby_libvirt_generate_call_nil(virNetworkSetAutostart,
201
+ ruby_libvirt_connect_get(n),
202
+ network_get(n), RTEST(autostart) ? 1 : 0);
203
+ }
204
+
205
+ /*
206
+ * call-seq:
207
+ * net.free -> nil
208
+ *
209
+ * Call virNetworkFree[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkFree]
210
+ * to free this network. The object will no longer be valid after this call.
211
+ */
212
+ static VALUE libvirt_network_free(VALUE n)
213
+ {
214
+ ruby_libvirt_generate_call_free(Network, n);
215
+ }
216
+
217
+ #if HAVE_VIRNETWORKISACTIVE
218
+ /*
219
+ * call-seq:
220
+ * net.active? -> [true|false]
221
+ *
222
+ * Call virNetworkIsActive[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkIsActive]
223
+ * to determine if this network is currently active.
224
+ */
225
+ static VALUE libvirt_network_active_p(VALUE n)
226
+ {
227
+ ruby_libvirt_generate_call_truefalse(virNetworkIsActive,
228
+ ruby_libvirt_connect_get(n),
229
+ network_get(n));
230
+ }
231
+ #endif
232
+
233
+ #if HAVE_VIRNETWORKISPERSISTENT
234
+ /*
235
+ * call-seq:
236
+ * net.persistent? -> [true|false]
237
+ *
238
+ * Call virNetworkIsPersistent[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkIsPersistent]
239
+ * to determine if this network is persistent.
240
+ */
241
+ static VALUE libvirt_network_persistent_p(VALUE n)
242
+ {
243
+ ruby_libvirt_generate_call_truefalse(virNetworkIsPersistent,
244
+ ruby_libvirt_connect_get(n),
245
+ network_get(n));
246
+ }
247
+ #endif
248
+
249
+ #if HAVE_VIRNETWORKGETDHCPLEASES
250
+ struct leases_arg {
251
+ virNetworkDHCPLeasePtr *leases;
252
+ int nleases;
253
+ };
254
+
255
+ static VALUE leases_wrap(VALUE arg)
256
+ {
257
+ struct leases_arg *e = (struct leases_arg *)arg;
258
+ VALUE result, hash;
259
+ virNetworkDHCPLeasePtr lease;
260
+ int i;
261
+
262
+ result = rb_ary_new2(e->nleases);
263
+
264
+ for (i = 0; i < e->nleases; i++) {
265
+ lease = e->leases[i];
266
+
267
+ hash = rb_hash_new();
268
+ rb_hash_aset(hash, rb_str_new2("iface"), rb_str_new2(lease->iface));
269
+ rb_hash_aset(hash, rb_str_new2("expirytime"),
270
+ LL2NUM(lease->expirytime));
271
+ rb_hash_aset(hash, rb_str_new2("type"), INT2NUM(lease->type));
272
+ if (lease->mac) {
273
+ rb_hash_aset(hash, rb_str_new2("mac"), rb_str_new2(lease->mac));
274
+ }
275
+ if (lease->iaid) {
276
+ rb_hash_aset(hash, rb_str_new2("iaid"), rb_str_new2(lease->iaid));
277
+ }
278
+ rb_hash_aset(hash, rb_str_new2("ipaddr"), rb_str_new2(lease->ipaddr));
279
+ rb_hash_aset(hash, rb_str_new2("prefix"), UINT2NUM(lease->prefix));
280
+ if (lease->hostname) {
281
+ rb_hash_aset(hash, rb_str_new2("hostname"),
282
+ rb_str_new2(lease->hostname));
283
+ }
284
+ if (lease->clientid) {
285
+ rb_hash_aset(hash, rb_str_new2("clientid"),
286
+ rb_str_new2(lease->clientid));
287
+ }
288
+
289
+ rb_ary_store(result, i, hash);
290
+ }
291
+
292
+ return result;
293
+ }
294
+
295
+ /*
296
+ * call-seq:
297
+ * net.dhcp_leases(mac=nil, flags=0) -> Hash
298
+ *
299
+ * Call virNetworkGetDHCPLeases[http://www.libvirt.org/html/libvirt-libvirt-network.html#virNetworkGetDHCPLeases]
300
+ * to retrieve the leases for this network.
301
+ */
302
+ static VALUE libvirt_network_get_dhcp_leases(int argc, VALUE *argv, VALUE n)
303
+ {
304
+ VALUE mac = RUBY_Qnil, flags = RUBY_Qnil, result;
305
+ int nleases, i = 0, exception = 0;
306
+ virNetworkDHCPLeasePtr *leases = NULL;
307
+ struct leases_arg args;
308
+
309
+ rb_scan_args(argc, argv, "02", &mac, &flags);
310
+
311
+ nleases = virNetworkGetDHCPLeases(network_get(n),
312
+ ruby_libvirt_get_cstring_or_null(mac),
313
+ &leases,
314
+ ruby_libvirt_value_to_uint(flags));
315
+ ruby_libvirt_raise_error_if(nleases < 0, e_Error, "virNetworkGetDHCPLeases",
316
+ ruby_libvirt_connect_get(n));
317
+
318
+ args.leases = leases;
319
+ args.nleases = nleases;
320
+ result = rb_protect(leases_wrap, (VALUE)&args, &exception);
321
+
322
+ for (i = 0; i < nleases; i++) {
323
+ virNetworkDHCPLeaseFree(leases[i]);
324
+ }
325
+ free(leases);
326
+
327
+ if (exception) {
328
+ rb_jump_tag(exception);
329
+ }
330
+
331
+ return result;
332
+ }
333
+ #endif
334
+
335
+ #endif
336
+
337
+ /*
338
+ * Class Libvirt::Network
339
+ */
340
+ void ruby_libvirt_network_init(void)
341
+ {
342
+ #if HAVE_TYPE_VIRNETWORKPTR
343
+ c_network = rb_define_class_under(m_libvirt, "Network", rb_cObject);
344
+ rb_define_attr(c_network, "connection", 1, 0);
345
+
346
+ rb_define_method(c_network, "undefine", libvirt_network_undefine, 0);
347
+ rb_define_method(c_network, "create", libvirt_network_create, 0);
348
+ #if HAVE_VIRNETWORKUPDATE
349
+ rb_define_method(c_network, "update", libvirt_network_update, 5);
350
+ #endif
351
+ rb_define_method(c_network, "destroy", libvirt_network_destroy, 0);
352
+ rb_define_method(c_network, "name", libvirt_network_name, 0);
353
+ rb_define_method(c_network, "uuid", libvirt_network_uuid, 0);
354
+ rb_define_method(c_network, "xml_desc", libvirt_network_xml_desc, -1);
355
+ rb_define_method(c_network, "bridge_name", libvirt_network_bridge_name, 0);
356
+ rb_define_method(c_network, "autostart", libvirt_network_autostart, 0);
357
+ rb_define_method(c_network, "autostart?", libvirt_network_autostart, 0);
358
+ rb_define_method(c_network, "autostart=", libvirt_network_autostart_equal,
359
+ 1);
360
+ rb_define_method(c_network, "free", libvirt_network_free, 0);
361
+ #if HAVE_VIRNETWORKISACTIVE
362
+ rb_define_method(c_network, "active?", libvirt_network_active_p, 0);
363
+ #endif
364
+ #if HAVE_VIRNETWORKISPERSISTENT
365
+ rb_define_method(c_network, "persistent?", libvirt_network_persistent_p, 0);
366
+ #endif
367
+ #if HAVE_CONST_VIR_NETWORK_UPDATE_COMMAND_NONE
368
+ /* Ideally we would just have the "UPDATE_COMMAND_NONE" constant.
369
+ * Unfortunately we screwed up long ago, and we have to
370
+ * leave "NETWORK_UPDATE_COMMAND_NONE" for backwards compatibility.
371
+ */
372
+ rb_define_const(c_network, "UPDATE_COMMAND_NONE",
373
+ INT2NUM(VIR_NETWORK_UPDATE_COMMAND_NONE));
374
+ rb_define_const(c_network, "NETWORK_UPDATE_COMMAND_NONE",
375
+ INT2NUM(VIR_NETWORK_UPDATE_COMMAND_NONE));
376
+ /* Ideally we would just have the "UPDATE_COMMAND_MODIFY" constant.
377
+ * Unfortunately we screwed up long ago, and we have to
378
+ * leave "NETWORK_UPDATE_COMMAND_MODIFY" for backwards compatibility.
379
+ */
380
+ rb_define_const(c_network, "UPDATE_COMMAND_MODIFY",
381
+ INT2NUM(VIR_NETWORK_UPDATE_COMMAND_MODIFY));
382
+ rb_define_const(c_network, "NETWORK_UPDATE_COMMAND_MODIFY",
383
+ INT2NUM(VIR_NETWORK_UPDATE_COMMAND_MODIFY));
384
+ /* Ideally we would just have the "UPDATE_COMMAND_ADD_LAST" constant.
385
+ * Unfortunately we screwed up long ago, and we have to
386
+ * leave "NETWORK_UPDATE_COMMAND_ADD_LAST" for backwards compatibility.
387
+ */
388
+ rb_define_const(c_network, "UPDATE_COMMAND_ADD_LAST",
389
+ INT2NUM(VIR_NETWORK_UPDATE_COMMAND_ADD_LAST));
390
+ rb_define_const(c_network, "NETWORK_UPDATE_COMMAND_ADD_LAST",
391
+ INT2NUM(VIR_NETWORK_UPDATE_COMMAND_ADD_LAST));
392
+ /* Ideally we would just have the "UPDATE_COMMAND_ADD_FIRST" constant.
393
+ * Unfortunately we screwed up long ago, and we have to
394
+ * leave "NETWORK_UPDATE_COMMAND_ADD_FIRST" for backwards compatibility.
395
+ */
396
+ rb_define_const(c_network, "UPDATE_COMMAND_ADD_FIRST",
397
+ INT2NUM(VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST));
398
+ rb_define_const(c_network, "NETWORK_UPDATE_COMMAND_ADD_FIRST",
399
+ INT2NUM(VIR_NETWORK_UPDATE_COMMAND_ADD_FIRST));
400
+ /* Ideally we would just have the "SECTION_NONE" constant.
401
+ * Unfortunately we screwed up long ago, and we have to
402
+ * leave "NETWORK_SECTION_NONE" for backwards compatibility.
403
+ */
404
+ rb_define_const(c_network, "SECTION_NONE",
405
+ INT2NUM(VIR_NETWORK_SECTION_NONE));
406
+ rb_define_const(c_network, "NETWORK_SECTION_NONE",
407
+ INT2NUM(VIR_NETWORK_SECTION_NONE));
408
+ /* Ideally we would just have the "SECTION_BRIDGE" constant.
409
+ * Unfortunately we screwed up long ago, and we have to
410
+ * leave "NETWORK_SECTION_BRIDGE" for backwards compatibility.
411
+ */
412
+ rb_define_const(c_network, "SECTION_BRIDGE",
413
+ INT2NUM(VIR_NETWORK_SECTION_BRIDGE));
414
+ rb_define_const(c_network, "NETWORK_SECTION_BRIDGE",
415
+ INT2NUM(VIR_NETWORK_SECTION_BRIDGE));
416
+ /* Ideally we would just have the "SECTION_DOMAIN" constant.
417
+ * Unfortunately we screwed up long ago, and we have to
418
+ * leave "NETWORK_SECTION_DOMAIN" for backwards compatibility.
419
+ */
420
+ rb_define_const(c_network, "SECTION_DOMAIN",
421
+ INT2NUM(VIR_NETWORK_SECTION_DOMAIN));
422
+ rb_define_const(c_network, "NETWORK_SECTION_DOMAIN",
423
+ INT2NUM(VIR_NETWORK_SECTION_DOMAIN));
424
+ /* Ideally we would just have the "SECTION_IP" constant.
425
+ * Unfortunately we screwed up long ago, and we have to
426
+ * leave "NETWORK_SECTION_IP" for backwards compatibility.
427
+ */
428
+ rb_define_const(c_network, "SECTION_IP",
429
+ INT2NUM(VIR_NETWORK_SECTION_IP));
430
+ rb_define_const(c_network, "NETWORK_SECTION_IP",
431
+ INT2NUM(VIR_NETWORK_SECTION_IP));
432
+ /* Ideally we would just have the "SECTION_IP_DHCP_HOST" constant.
433
+ * Unfortunately we screwed up long ago, and we have to
434
+ * leave "NETWORK_SECTION_IP_DHCP_HOST" for backwards compatibility.
435
+ */
436
+ rb_define_const(c_network, "SECTION_IP_DHCP_HOST",
437
+ INT2NUM(VIR_NETWORK_SECTION_IP_DHCP_HOST));
438
+ rb_define_const(c_network, "NETWORK_SECTION_IP_DHCP_HOST",
439
+ INT2NUM(VIR_NETWORK_SECTION_IP_DHCP_HOST));
440
+ /* Ideally we would just have the "SECTION_IP_DHCP_RANGE" constant.
441
+ * Unfortunately we screwed up long ago, and we have to
442
+ * leave "NETWORK_SECTION_IP_DHCP_RANGE" for backwards compatibility.
443
+ */
444
+ rb_define_const(c_network, "SECTION_IP_DHCP_RANGE",
445
+ INT2NUM(VIR_NETWORK_SECTION_IP_DHCP_RANGE));
446
+ rb_define_const(c_network, "NETWORK_SECTION_IP_DHCP_RANGE",
447
+ INT2NUM(VIR_NETWORK_SECTION_IP_DHCP_RANGE));
448
+ /* Ideally we would just have the "SECTION_FORWARD" constant.
449
+ * Unfortunately we screwed up long ago, and we have to
450
+ * leave "NETWORK_SECTION_FORWARD" for backwards compatibility.
451
+ */
452
+ rb_define_const(c_network, "SECTION_FORWARD",
453
+ INT2NUM(VIR_NETWORK_SECTION_FORWARD));
454
+ rb_define_const(c_network, "NETWORK_SECTION_FORWARD",
455
+ INT2NUM(VIR_NETWORK_SECTION_FORWARD));
456
+ /* Ideally we would just have the "SECTION_FORWARD_INTERFACE" constant.
457
+ * Unfortunately we screwed up long ago, and we have to
458
+ * leave "NETWORK_SECTION_FORWARD_INTERFACE" for backwards compatibility.
459
+ */
460
+ rb_define_const(c_network, "SECTION_FORWARD_INTERFACE",
461
+ INT2NUM(VIR_NETWORK_SECTION_FORWARD_INTERFACE));
462
+ rb_define_const(c_network, "NETWORK_SECTION_FORWARD_INTERFACE",
463
+ INT2NUM(VIR_NETWORK_SECTION_FORWARD_INTERFACE));
464
+ /* Ideally we would just have the "SECTION_FORWARD_PF" constant.
465
+ * Unfortunately we screwed up long ago, and we have to
466
+ * leave "NETWORK_SECTION_FORWARD_PF" for backwards compatibility.
467
+ */
468
+ rb_define_const(c_network, "SECTION_FORWARD_PF",
469
+ INT2NUM(VIR_NETWORK_SECTION_FORWARD_PF));
470
+ rb_define_const(c_network, "NETWORK_SECTION_FORWARD_PF",
471
+ INT2NUM(VIR_NETWORK_SECTION_FORWARD_PF));
472
+ /* Ideally we would just have the "SECTION_PORTGROUP" constant.
473
+ * Unfortunately we screwed up long ago, and we have to
474
+ * leave "NETWORK_SECTION_PORTGROUP" for backwards compatibility.
475
+ */
476
+ rb_define_const(c_network, "SECTION_PORTGROUP",
477
+ INT2NUM(VIR_NETWORK_SECTION_PORTGROUP));
478
+ rb_define_const(c_network, "NETWORK_SECTION_PORTGROUP",
479
+ INT2NUM(VIR_NETWORK_SECTION_PORTGROUP));
480
+ /* Ideally we would just have the "SECTION_DNS_HOST" constant.
481
+ * Unfortunately we screwed up long ago, and we have to
482
+ * leave "NETWORK_SECTION_DNS_HOST" for backwards compatibility.
483
+ */
484
+ rb_define_const(c_network, "SECTION_DNS_HOST",
485
+ INT2NUM(VIR_NETWORK_SECTION_DNS_HOST));
486
+ rb_define_const(c_network, "NETWORK_SECTION_DNS_HOST",
487
+ INT2NUM(VIR_NETWORK_SECTION_DNS_HOST));
488
+ /* Ideally we would just have the "SECTION_DNS_TXT" constant.
489
+ * Unfortunately we screwed up long ago, and we have to
490
+ * leave "NETWORK_SECTION_DNS_TXT" for backwards compatibility.
491
+ */
492
+ rb_define_const(c_network, "SECTION_DNS_TXT",
493
+ INT2NUM(VIR_NETWORK_SECTION_DNS_TXT));
494
+ rb_define_const(c_network, "NETWORK_SECTION_DNS_TXT",
495
+ INT2NUM(VIR_NETWORK_SECTION_DNS_TXT));
496
+ /* Ideally we would just have the "SECTION_DNS_SRV" constant.
497
+ * Unfortunately we screwed up long ago, and we have to
498
+ * leave "NETWORK_SECTION_DNS_SRV" for backwards compatibility.
499
+ */
500
+ rb_define_const(c_network, "SECTION_DNS_SRV",
501
+ INT2NUM(VIR_NETWORK_SECTION_DNS_SRV));
502
+ rb_define_const(c_network, "NETWORK_SECTION_DNS_SRV",
503
+ INT2NUM(VIR_NETWORK_SECTION_DNS_SRV));
504
+ /* Ideally we would just have the "UPDATE_AFFECT_CURRENT" constant.
505
+ * Unfortunately we screwed up long ago, and we have to
506
+ * leave "NETWORK_UPDATE_AFFECT_CURRENT" for backwards compatibility.
507
+ */
508
+ rb_define_const(c_network, "UPDATE_AFFECT_CURRENT",
509
+ INT2NUM(VIR_NETWORK_UPDATE_AFFECT_CURRENT));
510
+ rb_define_const(c_network, "NETWORK_UPDATE_AFFECT_CURRENT",
511
+ INT2NUM(VIR_NETWORK_UPDATE_AFFECT_CURRENT));
512
+ /* Ideally we would just have the "UPDATE_AFFECT_LIVE" constant.
513
+ * Unfortunately we screwed up long ago, and we have to
514
+ * leave "NETWORK_UPDATE_AFFECT_LIVE" for backwards compatibility.
515
+ */
516
+ rb_define_const(c_network, "UPDATE_AFFECT_LIVE",
517
+ INT2NUM(VIR_NETWORK_UPDATE_AFFECT_LIVE));
518
+ rb_define_const(c_network, "NETWORK_UPDATE_AFFECT_LIVE",
519
+ INT2NUM(VIR_NETWORK_UPDATE_AFFECT_LIVE));
520
+ /* Ideally we would just have the "UPDATE_AFFECT_CONFIG" constant.
521
+ * Unfortunately we screwed up long ago, and we have to
522
+ * leave "NETWORK_UPDATE_AFFECT_CONFIG" for backwards compatibility.
523
+ */
524
+ rb_define_const(c_network, "UPDATE_AFFECT_CONFIG",
525
+ INT2NUM(VIR_NETWORK_UPDATE_AFFECT_CONFIG));
526
+ rb_define_const(c_network, "NETWORK_UPDATE_AFFECT_CONFIG",
527
+ INT2NUM(VIR_NETWORK_UPDATE_AFFECT_CONFIG));
528
+ #endif
529
+
530
+ #if HAVE_CONST_VIR_NETWORK_XML_INACTIVE
531
+ rb_define_const(c_network, "XML_INACTIVE",
532
+ INT2NUM(VIR_NETWORK_XML_INACTIVE));
533
+ #endif
534
+ #if HAVE_CONST_VIR_NETWORK_UPDATE_COMMAND_DELETE
535
+ rb_define_const(c_network, "UPDATE_COMMAND_DELETE",
536
+ INT2NUM(VIR_NETWORK_UPDATE_COMMAND_DELETE));
537
+ #endif
538
+
539
+ #if HAVE_VIRNETWORKGETDHCPLEASES
540
+ rb_define_method(c_network, "dhcp_leases",
541
+ libvirt_network_get_dhcp_leases, -1);
542
+ #endif
543
+
544
+ #if HAVE_CONST_VIR_IP_ADDR_TYPE_IPV4
545
+ rb_define_const(c_network, "IP_ADDR_TYPE_IPV4",
546
+ INT2NUM(VIR_IP_ADDR_TYPE_IPV4));
547
+ #endif
548
+
549
+ #if HAVE_CONST_VIR_IP_ADDR_TYPE_IPV6
550
+ rb_define_const(c_network, "IP_ADDR_TYPE_IPV6",
551
+ INT2NUM(VIR_IP_ADDR_TYPE_IPV6));
552
+ #endif
553
+
554
+ #endif
555
+ }