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.
@@ -0,0 +1,8 @@
1
+ #ifndef DOMAIN_H
2
+ #define DOMAIN_H
3
+
4
+ extern VALUE c_domain;
5
+
6
+ void init_domain();
7
+
8
+ #endif
@@ -18,9 +18,38 @@ end
18
18
 
19
19
  libvirt_types = [ 'virNetworkPtr',
20
20
  'virStoragePoolPtr',
21
- 'virStorageVolPtr' ]
21
+ 'virStorageVolPtr',
22
+ 'virSecretPtr',
23
+ 'virNWFilterPtr',
24
+ 'virInterfacePtr',
25
+ 'virDomainBlockInfoPtr',
26
+ 'virDomainMemoryStatPtr',
27
+ 'virDomainSnapshotPtr',
28
+ 'virDomainJobInfoPtr',
29
+ ]
30
+
31
+ libvirt_funcs = [ 'virStorageVolWipe',
32
+ 'virStoragePoolIsActive',
33
+ 'virStoragePoolIsPersistent',
34
+ 'virConnectGetLibVersion',
35
+ 'virConnectIsEncrypted',
36
+ 'virConnectIsSecure',
37
+ 'virNetworkIsActive',
38
+ 'virNetworkIsPersistent',
39
+ 'virNodeDeviceCreateXML',
40
+ 'virNodeDeviceDestroy',
41
+ 'virInterfaceIsActive',
42
+ 'virDomainMigrateToURI',
43
+ 'virDomainMigrateSetMaxDowntime',
44
+ 'virDomainManagedSave',
45
+ 'virDomainIsActive',
46
+ 'virDomainIsPersistent',
47
+ 'virConnectDomainXMLFromNative',
48
+ 'virConnectDomainXMLToNative',
49
+ ]
22
50
 
23
51
  have_libvirt_types(libvirt_types)
52
+ have_libvirt_funcs(libvirt_funcs)
24
53
 
25
54
  create_header
26
55
  create_makefile(extension_name)
@@ -0,0 +1,259 @@
1
+ /*
2
+ * interface.c: virInterface 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_VIRINTERFACEPTR
29
+ static VALUE c_interface;
30
+
31
+ static void interface_free(void *i) {
32
+ generic_free(Interface, i);
33
+ }
34
+
35
+ static virInterfacePtr interface_get(VALUE s) {
36
+ generic_get(Interface, s);
37
+ }
38
+
39
+ static VALUE interface_new(virInterfacePtr i, VALUE conn) {
40
+ return generic_new(c_interface, i, conn, interface_free);
41
+ }
42
+
43
+ /*
44
+ * call-seq:
45
+ * conn.num_of_interfaces -> fixnum
46
+ *
47
+ * Call +virConnectNumOfInterfaces+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectNumOfInterfaces]
48
+ */
49
+ static VALUE libvirt_conn_num_of_interfaces(VALUE s) {
50
+ gen_conn_num_of(s, Interfaces);
51
+ }
52
+
53
+ /*
54
+ * call-seq:
55
+ * conn.list_interfaces -> list
56
+ *
57
+ * Call +virConnectListInterfaces+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectListInterfaces]
58
+ */
59
+ static VALUE libvirt_conn_list_interfaces(VALUE s) {
60
+ gen_conn_list_names(s, Interfaces);
61
+ }
62
+
63
+ /*
64
+ * call-seq:
65
+ * conn.num_of_defined_interfaces -> fixnum
66
+ *
67
+ * Call +virConnectNumOfDefinedInterfaces+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectNumOfDefinedInterfaces]
68
+ */
69
+ static VALUE libvirt_conn_num_of_defined_interfaces(VALUE s) {
70
+ gen_conn_num_of(s, DefinedInterfaces);
71
+ }
72
+
73
+ /*
74
+ * call-seq:
75
+ * conn.list_defined_interfaces -> list
76
+ *
77
+ * Call +virConnectListDefinedInterfaces+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectListDefinedInterfaces]
78
+ */
79
+ static VALUE libvirt_conn_list_defined_interfaces(VALUE s) {
80
+ gen_conn_list_names(s, DefinedInterfaces);
81
+ }
82
+
83
+ /*
84
+ * call-seq:
85
+ * conn.lookup_interface_by_name -> Libvirt::Interface
86
+ *
87
+ * Call +virInterfaceLookupByName+[http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceLookupByName]
88
+ */
89
+ static VALUE libvirt_conn_lookup_interface_by_name(VALUE c, VALUE name) {
90
+ virInterfacePtr iface;
91
+ virConnectPtr conn = connect_get(c);
92
+
93
+ iface = virInterfaceLookupByName(conn, StringValueCStr(name));
94
+ _E(iface == NULL, create_error(e_RetrieveError, "virInterfaceLookupByName", "", conn));
95
+
96
+ return interface_new(iface, c);
97
+ }
98
+
99
+ /*
100
+ * call-seq:
101
+ * conn.lookup_interface_by_mac -> Libvirt::Interface
102
+ *
103
+ * Call +virInterfaceLookupByMACString+[http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceLookupByMACString]
104
+ */
105
+ static VALUE libvirt_conn_lookup_interface_by_mac(VALUE c, VALUE mac) {
106
+ virInterfacePtr iface;
107
+ virConnectPtr conn = connect_get(c);
108
+
109
+ iface = virInterfaceLookupByMACString(conn, StringValueCStr(mac));
110
+ _E(iface == NULL, create_error(e_RetrieveError, "virInterfaceLookupByMACString", "", conn));
111
+
112
+ return interface_new(iface, c);
113
+ }
114
+
115
+ /*
116
+ * call-seq:
117
+ * conn.define_interface_xml -> Libvirt::Interface
118
+ *
119
+ * Call +virInterfaceDefineXML+[http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceDefineXML]
120
+ */
121
+ static VALUE libvirt_conn_define_interface_xml(int argc, VALUE *argv, VALUE c) {
122
+ virInterfacePtr iface;
123
+ virConnectPtr conn = connect_get(c);
124
+ VALUE xml, flags;
125
+
126
+ rb_scan_args(argc, argv, "11", &xml, &flags);
127
+
128
+ if (NIL_P(flags))
129
+ flags = INT2FIX(0);
130
+
131
+ iface = virInterfaceDefineXML(conn, StringValueCStr(xml), NUM2UINT(flags));
132
+ _E(iface == NULL, create_error(e_DefinitionError, "virInterfaceDefineXML", "", conn));
133
+
134
+ return interface_new(iface, c);
135
+ }
136
+
137
+ /*
138
+ * call-seq:
139
+ * interface.undefine -> nil
140
+ *
141
+ * Call +virInterfaceUndefine+[http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceUndefine]
142
+ */
143
+ static VALUE libvirt_interface_undefine(VALUE s) {
144
+ gen_call_void(virInterfaceUndefine, conn(s), interface_get(s));
145
+ }
146
+
147
+ /*
148
+ * call-seq:
149
+ * interface.create -> nil
150
+ *
151
+ * Call +virInterfaceCreate+[http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceCreate]
152
+ */
153
+ static VALUE libvirt_interface_create(VALUE s) {
154
+ gen_call_void(virInterfaceCreate, conn(s), interface_get(s), 0);
155
+ }
156
+
157
+ /*
158
+ * call-seq:
159
+ * interface.destroy -> nil
160
+ *
161
+ * Call +virInterfaceDestroy+[http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceDestroy]
162
+ */
163
+ static VALUE libvirt_interface_destroy(VALUE s) {
164
+ gen_call_void(virInterfaceDestroy, conn(s), interface_get(s), 0);
165
+ }
166
+
167
+ #if HAVE_VIRINTERFACEISACTIVE
168
+ /*
169
+ * call-seq:
170
+ * interface.active? -> [true|false]
171
+ *
172
+ * Call +virInterfaceIsActive+[http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceIsActive]
173
+ */
174
+ static VALUE libvirt_interface_active_p(VALUE p) {
175
+ gen_call_truefalse(virInterfaceIsActive, conn(p), interface_get(p));
176
+ }
177
+ #endif
178
+
179
+ /*
180
+ * call-seq:
181
+ * interface.name -> string
182
+ *
183
+ * Call +virInterfaceGetName+[http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceGetName]
184
+ */
185
+ static VALUE libvirt_interface_name(VALUE s) {
186
+ gen_call_string(virInterfaceGetName, conn(s), 0, interface_get(s));
187
+ }
188
+
189
+ /*
190
+ * call-seq:
191
+ * interface.mac -> string
192
+ *
193
+ * Call +virInterfaceGetMACString+[http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceGetMACString]
194
+ */
195
+ static VALUE libvirt_interface_mac(VALUE s) {
196
+ gen_call_string(virInterfaceGetMACString, conn(s), 0, interface_get(s));
197
+ }
198
+
199
+ /*
200
+ * call-seq:
201
+ * interface.xml_desc -> string
202
+ *
203
+ * Call +virInterfaceGetXMLDesc+[http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceGetXMLDesc]
204
+ */
205
+ static VALUE libvirt_interface_xml_desc(int argc, VALUE *argv, VALUE s) {
206
+ VALUE flags;
207
+
208
+ rb_scan_args(argc, argv, "01", &flags);
209
+
210
+ if (NIL_P(flags))
211
+ flags = INT2FIX(0);
212
+
213
+ gen_call_string(virInterfaceGetXMLDesc, conn(s), 1, interface_get(s),
214
+ NUM2UINT(flags));
215
+ }
216
+
217
+ #endif
218
+
219
+ /*
220
+ * Class Libvirt::Interface
221
+ */
222
+ void init_interface()
223
+ {
224
+ #if HAVE_TYPE_VIRINTERFACEPTR
225
+ c_interface = rb_define_class_under(m_libvirt, "Interface", rb_cObject);
226
+ #ifdef VIR_INTERFACE_XML_INACTIVE
227
+ rb_define_const(c_interface, "XML_INACTIVE",
228
+ INT2NUM(VIR_INTERFACE_XML_INACTIVE));
229
+ #endif
230
+ rb_define_attr(c_interface, "connection", 1, 0);
231
+
232
+ /* Interface lookup/creation methods */
233
+ rb_define_method(c_connect, "num_of_interfaces",
234
+ libvirt_conn_num_of_interfaces, 0);
235
+ rb_define_method(c_connect, "list_interfaces",
236
+ libvirt_conn_list_interfaces, 0);
237
+ rb_define_method(c_connect, "num_of_defined_interfaces",
238
+ libvirt_conn_num_of_defined_interfaces, 0);
239
+ rb_define_method(c_connect, "list_defined_interfaces",
240
+ libvirt_conn_list_defined_interfaces, 0);
241
+ rb_define_method(c_connect, "lookup_interface_by_name",
242
+ libvirt_conn_lookup_interface_by_name, 1);
243
+ rb_define_method(c_connect, "lookup_interface_by_mac",
244
+ libvirt_conn_lookup_interface_by_mac, 1);
245
+ rb_define_method(c_connect, "define_interface_xml",
246
+ libvirt_conn_define_interface_xml, -1);
247
+
248
+ /* Interface object methods */
249
+ rb_define_method(c_interface, "name", libvirt_interface_name, 0);
250
+ rb_define_method(c_interface, "mac", libvirt_interface_mac, 0);
251
+ rb_define_method(c_interface, "xml_desc", libvirt_interface_xml_desc, -1);
252
+ rb_define_method(c_interface, "undefine", libvirt_interface_undefine, 0);
253
+ rb_define_method(c_interface, "create", libvirt_interface_create, -1);
254
+ rb_define_method(c_interface, "destroy", libvirt_interface_destroy, -1);
255
+ #if HAVE_VIRINTERFACEISACTIVE
256
+ rb_define_method(c_interface, "active?", libvirt_interface_active_p, 0);
257
+ #endif
258
+ #endif
259
+ }
@@ -0,0 +1,6 @@
1
+ #ifndef INTERFACE_H
2
+ #define INTERFACE_H
3
+
4
+ void init_interface();
5
+
6
+ #endif
@@ -0,0 +1,338 @@
1
+ /*
2
+ * network.c: virNetwork methods
3
+ *
4
+ * Copyright (C) 2007,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_VIRNETWORKPTR
29
+ static VALUE c_network;
30
+
31
+ static void network_free(void *d) {
32
+ generic_free(Network, d);
33
+ }
34
+
35
+ static virNetworkPtr network_get(VALUE s) {
36
+ generic_get(Network, s);
37
+ }
38
+
39
+ static VALUE network_new(virNetworkPtr n, VALUE conn) {
40
+ return generic_new(c_network, n, conn, network_free);
41
+ }
42
+
43
+ /*
44
+ * call-seq:
45
+ * conn.num_of_networks -> fixnum
46
+ *
47
+ * Call +virConnectNumOfNetworks+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectNumOfNetworks]
48
+ */
49
+ static VALUE libvirt_conn_num_of_networks(VALUE s) {
50
+ gen_conn_num_of(s, Networks);
51
+ }
52
+
53
+ /*
54
+ * call-seq:
55
+ * conn.list_networks -> list
56
+ *
57
+ * Call +virConnectListNetworks+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectListNetworks]
58
+ */
59
+ static VALUE libvirt_conn_list_networks(VALUE s) {
60
+ gen_conn_list_names(s, Networks);
61
+ }
62
+
63
+ /*
64
+ * call-seq:
65
+ * conn.num_of_defined_networks -> fixnum
66
+ *
67
+ * Call +virConnectNumOfDefinedNetworks+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectNumOfDefinedNetworks]
68
+ */
69
+ static VALUE libvirt_conn_num_of_defined_networks(VALUE s) {
70
+ gen_conn_num_of(s, DefinedNetworks);
71
+ }
72
+
73
+ /*
74
+ * call-seq:
75
+ * conn.list_of_defined_networks -> list
76
+ *
77
+ * Call +virConnectListDefinedNetworks+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectListDefinedNetworks]
78
+ */
79
+ static VALUE libvirt_conn_list_defined_networks(VALUE s) {
80
+ gen_conn_list_names(s, DefinedNetworks);
81
+ }
82
+
83
+ /*
84
+ * call-seq:
85
+ * conn.lookup_network_by_name -> Libvirt::Network
86
+ *
87
+ * Call +virNetworkLookupByName+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkLookupByName]
88
+ */
89
+ static VALUE libvirt_conn_lookup_network_by_name(VALUE c, VALUE name) {
90
+ virNetworkPtr netw;
91
+ virConnectPtr conn = connect_get(c);
92
+
93
+ netw = virNetworkLookupByName(conn, StringValueCStr(name));
94
+ _E(netw == NULL, create_error(e_RetrieveError, "virNetworkLookupByName", "", conn));
95
+
96
+ return network_new(netw, c);
97
+ }
98
+
99
+ /*
100
+ * call-seq:
101
+ * conn.lookup_network_by_uuid -> Libvirt::Network
102
+ *
103
+ * Call +virNetworkLookupByUUIDString+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkLookupByUUIDString]
104
+ */
105
+ static VALUE libvirt_conn_lookup_network_by_uuid(VALUE c, VALUE uuid) {
106
+ virNetworkPtr netw;
107
+ virConnectPtr conn = connect_get(c);
108
+
109
+ netw = virNetworkLookupByUUIDString(conn, StringValueCStr(uuid));
110
+ _E(netw == NULL, create_error(e_RetrieveError, "virNetworkLookupByUUID", "", conn));
111
+
112
+ return network_new(netw, c);
113
+ }
114
+
115
+ /*
116
+ * call-seq:
117
+ * conn.create_network_xml -> Libvirt::Network
118
+ *
119
+ * Call +virNetworkCreateXML+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkCreateXML]
120
+ */
121
+ static VALUE libvirt_conn_create_network_xml(VALUE c, VALUE xml) {
122
+ virNetworkPtr netw;
123
+ virConnectPtr conn = connect_get(c);
124
+
125
+ netw = virNetworkCreateXML(conn, StringValueCStr(xml));
126
+ _E(netw == NULL, create_error(e_Error, "virNetworkCreateXML", "", conn));
127
+
128
+ return network_new(netw, c);
129
+ }
130
+
131
+ /*
132
+ * call-seq:
133
+ * conn.define_network_xml -> Libvirt::Network
134
+ *
135
+ * Call +virNetworkDefineXML+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkDefineXML]
136
+ */
137
+ static VALUE libvirt_conn_define_network_xml(VALUE c, VALUE xml) {
138
+ virNetworkPtr netw;
139
+ virConnectPtr conn = connect_get(c);
140
+
141
+ netw = virNetworkDefineXML(conn, StringValueCStr(xml));
142
+ _E(netw == NULL, create_error(e_DefinitionError, "virNetworkDefineXML", "", conn));
143
+
144
+ return network_new(netw, c);
145
+ }
146
+
147
+ /*
148
+ * call-seq:
149
+ * net.undefine -> nil
150
+ *
151
+ * Call +virNetworkUndefine+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkUndefine]
152
+ */
153
+ static VALUE libvirt_netw_undefine(VALUE s) {
154
+ gen_call_void(virNetworkUndefine, conn(s), network_get(s));
155
+ }
156
+
157
+ /*
158
+ * call-seq:
159
+ * net.create -> nil
160
+ *
161
+ * Call +virNetworkCreate+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkCreate]
162
+ */
163
+ static VALUE libvirt_netw_create(VALUE s) {
164
+ gen_call_void(virNetworkCreate, conn(s), network_get(s));
165
+ }
166
+
167
+ /*
168
+ * call-seq:
169
+ * net.destroy -> nil
170
+ *
171
+ * Call +virNetworkDestroy+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkDestroy]
172
+ */
173
+ static VALUE libvirt_netw_destroy(VALUE s) {
174
+ gen_call_void(virNetworkDestroy, conn(s), network_get(s));
175
+ }
176
+
177
+ /*
178
+ * call-seq:
179
+ * net.name -> string
180
+ *
181
+ * Call +virNetworkGetName+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkGetName]
182
+ */
183
+ static VALUE libvirt_netw_name(VALUE s) {
184
+ gen_call_string(virNetworkGetName, conn(s), 0, network_get(s));
185
+ }
186
+
187
+ /*
188
+ * call-seq:
189
+ * net.uuid -> string
190
+ *
191
+ * Call +virNetworkGetUUIDString+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkGetUUIDString]
192
+ */
193
+ static VALUE libvirt_netw_uuid(VALUE s) {
194
+ virNetworkPtr netw = network_get(s);
195
+ char uuid[VIR_UUID_STRING_BUFLEN];
196
+ int r;
197
+
198
+ r = virNetworkGetUUIDString(netw, uuid);
199
+ _E(r < 0, create_error(e_RetrieveError, "virNetworkGetUUIDString", "", conn(s)));
200
+
201
+ return rb_str_new2((char *) uuid);
202
+ }
203
+
204
+ /*
205
+ * call-seq:
206
+ * net.xml_desc -> string
207
+ *
208
+ * Call +virNetworkGetXMLDesc+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkGetXMLDesc]
209
+ */
210
+ static VALUE libvirt_netw_xml_desc(int argc, VALUE *argv, VALUE s) {
211
+ VALUE flags;
212
+
213
+ rb_scan_args(argc, argv, "01", &flags);
214
+
215
+ if (NIL_P(flags))
216
+ flags = INT2FIX(0);
217
+
218
+ gen_call_string(virNetworkGetXMLDesc, conn(s), 1, network_get(s),
219
+ NUM2UINT(flags));
220
+ }
221
+
222
+ /*
223
+ * call-seq:
224
+ * net.bridge_name -> string
225
+ *
226
+ * Call +virNetworkGetBridgeName+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkGetBridgeName]
227
+ */
228
+ static VALUE libvirt_netw_bridge_name(VALUE s) {
229
+ gen_call_string(virNetworkGetBridgeName, conn(s), 1, network_get(s));
230
+ }
231
+
232
+ /*
233
+ * call-seq:
234
+ * net.autostart? -> [true|false]
235
+ *
236
+ * Call +virNetworkGetAutostart+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkGetAutostart]
237
+ */
238
+ static VALUE libvirt_netw_autostart(VALUE s){
239
+ virNetworkPtr netw = network_get(s);
240
+ int r, autostart;
241
+
242
+ r = virNetworkGetAutostart(netw, &autostart);
243
+ _E(r < 0, create_error(e_RetrieveError, "virNetworkAutostart", "", conn(s)));
244
+
245
+ return autostart ? Qtrue : Qfalse;
246
+ }
247
+
248
+ /*
249
+ * call-seq:
250
+ * net.autostart_set -> nil
251
+ *
252
+ * Call +virNetworkSetAutostart+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkSetAutostart]
253
+ */
254
+ static VALUE libvirt_netw_autostart_set(VALUE s, VALUE autostart) {
255
+ gen_call_void(virNetworkSetAutostart, conn(s), network_get(s),
256
+ RTEST(autostart) ? 1 : 0);
257
+ }
258
+
259
+ /*
260
+ * call-seq:
261
+ * net.free -> nil
262
+ *
263
+ * Call +virNetworkFree+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkFree]
264
+ */
265
+ static VALUE libvirt_netw_free(VALUE s) {
266
+ gen_call_free(Network, s);
267
+ }
268
+
269
+ #if HAVE_VIRNETWORKISACTIVE
270
+ /*
271
+ * call-seq:
272
+ * net.active? -> [true|false]
273
+ *
274
+ * Call +virNetworkIsActive+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkIsActive]
275
+ */
276
+ static VALUE libvirt_netw_active_p(VALUE s) {
277
+ gen_call_truefalse(virNetworkIsActive, conn(s), network_get(s));
278
+ }
279
+ #endif
280
+
281
+ #if HAVE_VIRNETWORKISPERSISTENT
282
+ /*
283
+ * call-seq:
284
+ * net.persistent? -> [true|false]
285
+ *
286
+ * Call +virNetworkIsPersistent+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkIsPersistent]
287
+ */
288
+ static VALUE libvirt_netw_persistent_p(VALUE s) {
289
+ gen_call_truefalse(virNetworkIsPersistent, conn(s), network_get(s));
290
+ }
291
+ #endif
292
+
293
+ #endif
294
+
295
+ /*
296
+ * Class Libvirt::Network
297
+ */
298
+ void init_network()
299
+ {
300
+ #if HAVE_TYPE_VIRNETWORKPTR
301
+ c_network = rb_define_class_under(m_libvirt, "Network", rb_cObject);
302
+ rb_define_attr(c_network, "connection", 1, 0);
303
+
304
+ rb_define_method(c_connect, "num_of_networks",
305
+ libvirt_conn_num_of_networks, 0);
306
+ rb_define_method(c_connect, "list_networks", libvirt_conn_list_networks, 0);
307
+ rb_define_method(c_connect, "num_of_defined_networks",
308
+ libvirt_conn_num_of_defined_networks, 0);
309
+ rb_define_method(c_connect, "list_defined_networks",
310
+ libvirt_conn_list_defined_networks, 0);
311
+ rb_define_method(c_connect, "lookup_network_by_name",
312
+ libvirt_conn_lookup_network_by_name, 1);
313
+ rb_define_method(c_connect, "lookup_network_by_uuid",
314
+ libvirt_conn_lookup_network_by_uuid, 1);
315
+ rb_define_method(c_connect, "create_network_xml",
316
+ libvirt_conn_create_network_xml, 1);
317
+ rb_define_method(c_connect, "define_network_xml",
318
+ libvirt_conn_define_network_xml, 1);
319
+
320
+ rb_define_method(c_network, "undefine", libvirt_netw_undefine, 0);
321
+ rb_define_method(c_network, "create", libvirt_netw_create, 0);
322
+ rb_define_method(c_network, "destroy", libvirt_netw_destroy, 0);
323
+ rb_define_method(c_network, "name", libvirt_netw_name, 0);
324
+ rb_define_method(c_network, "uuid", libvirt_netw_uuid, 0);
325
+ rb_define_method(c_network, "xml_desc", libvirt_netw_xml_desc, -1);
326
+ rb_define_method(c_network, "bridge_name", libvirt_netw_bridge_name, 0);
327
+ rb_define_method(c_network, "autostart", libvirt_netw_autostart, 0);
328
+ rb_define_method(c_network, "autostart?", libvirt_netw_autostart, 0);
329
+ rb_define_method(c_network, "autostart=", libvirt_netw_autostart_set, 1);
330
+ rb_define_method(c_network, "free", libvirt_netw_free, 0);
331
+ #if HAVE_VIRNETWORKISACTIVE
332
+ rb_define_method(c_network, "active?", libvirt_netw_active_p, 0);
333
+ #endif
334
+ #if HAVE_VIRNETWORKISPERSISTENT
335
+ rb_define_method(c_network, "persistent?", libvirt_netw_persistent_p, 0);
336
+ #endif
337
+ #endif
338
+ }