ruby-libvirt 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,10 @@
3
3
 
4
4
  extern VALUE c_domain;
5
5
 
6
+ void domain_free(void *d);
7
+ VALUE domain_new(virDomainPtr d, VALUE conn);
8
+ virDomainPtr domain_get(VALUE s);
9
+
6
10
  void init_domain();
7
11
 
8
12
  #endif
@@ -1,5 +1,7 @@
1
1
  require 'mkmf'
2
2
 
3
+ RbConfig::MAKEFILE_CONFIG['CC'] = ENV['CC'] if ENV['CC']
4
+
3
5
  def have_libvirt_funcs(funcs)
4
6
  funcs.each { |f| have_func(f, "libvirt/libvirt.h") }
5
7
  end
@@ -8,6 +10,41 @@ def have_libvirt_types(types)
8
10
  types.each { |t| have_type(t, "libvirt/libvirt.h") }
9
11
  end
10
12
 
13
+ def libvirt_checking_message(target, place = nil, opt = nil)
14
+ [["in", place], ["with", opt]].inject("#{target}") do |msg, (pre, noun)|
15
+ if noun
16
+ [[:to_str], [:join, ","], [:to_s]].each do |meth, *args|
17
+ if noun.respond_to?(meth)
18
+ break noun = noun.send(meth, *args)
19
+ end
20
+ end
21
+ msg << " #{pre} #{noun}" unless noun.empty?
22
+ end
23
+ msg
24
+ end
25
+ end
26
+
27
+ def have_const(const, headers = nil, opt = "", &b)
28
+ checking_for libvirt_checking_message(const, headers, opt) do
29
+ headers = cpp_include(headers)
30
+ if try_compile(<<"SRC", opt, &b)
31
+ #{COMMON_HEADERS}
32
+ #{headers}
33
+ /*top*/
34
+ static int t = #{const};
35
+ SRC
36
+ $defs.push(format("-DHAVE_CONST_%s", const.strip.upcase.tr_s("^A-Z0-9_", "_")))
37
+ true
38
+ else
39
+ false
40
+ end
41
+ end
42
+ end
43
+
44
+ def have_libvirt_consts(consts)
45
+ consts.each { |c| have_const(c, "libvirt/libvirt.h") }
46
+ end
47
+
11
48
  extension_name = '_libvirt'
12
49
 
13
50
  dir_config(extension_name)
@@ -26,11 +63,13 @@ libvirt_types = [ 'virNetworkPtr',
26
63
  'virDomainMemoryStatPtr',
27
64
  'virDomainSnapshotPtr',
28
65
  'virDomainJobInfoPtr',
66
+ 'virNodeDevicePtr',
29
67
  ]
30
68
 
31
69
  libvirt_funcs = [ 'virStorageVolWipe',
32
70
  'virStoragePoolIsActive',
33
71
  'virStoragePoolIsPersistent',
72
+ 'virStorageVolCreateXMLFrom',
34
73
  'virConnectGetLibVersion',
35
74
  'virConnectIsEncrypted',
36
75
  'virConnectIsSecure',
@@ -46,10 +85,61 @@ libvirt_funcs = [ 'virStorageVolWipe',
46
85
  'virDomainIsPersistent',
47
86
  'virConnectDomainXMLFromNative',
48
87
  'virConnectDomainXMLToNative',
88
+ 'virDomainCreateWithFlags',
89
+ 'virDomainAttachDeviceFlags',
90
+ 'virDomainDetachDeviceFlags',
91
+ 'virDomainUpdateDeviceFlags',
92
+ 'virNodeGetSecurityModel',
93
+ 'virDomainCreateXML',
94
+ 'virDomainGetSecurityLabel',
95
+ 'virConnectCompareCPU',
96
+ 'virConnectBaselineCPU',
97
+ 'virDomainSetVcpusFlags',
98
+ 'virDomainGetVcpusFlags',
99
+ 'virConnectDomainEventRegisterAny',
100
+ 'virConnectDomainEventRegister',
101
+ 'virDomainBlockPeek',
102
+ 'virDomainMemoryPeek',
103
+ 'virConnectOpenAuth',
104
+ 'virEventRegisterImpl',
49
105
  ]
50
106
 
107
+ libvirt_consts = [ 'VIR_MIGRATE_LIVE',
108
+ 'VIR_MIGRATE_PEER2PEER',
109
+ 'VIR_MIGRATE_TUNNELLED',
110
+ 'VIR_MIGRATE_PERSIST_DEST',
111
+ 'VIR_MIGRATE_UNDEFINE_SOURCE',
112
+ 'VIR_MIGRATE_PAUSED',
113
+ 'VIR_MIGRATE_NON_SHARED_DISK',
114
+ 'VIR_MIGRATE_NON_SHARED_INC',
115
+ 'VIR_DOMAIN_XML_UPDATE_CPU',
116
+ 'VIR_MEMORY_PHYSICAL',
117
+ 'VIR_DOMAIN_START_PAUSED',
118
+ 'VIR_DUMP_CRASH',
119
+ 'VIR_DUMP_LIVE',
120
+ 'VIR_DOMAIN_DEVICE_MODIFY_CURRENT',
121
+ 'VIR_DOMAIN_DEVICE_MODIFY_CONFIG',
122
+ 'VIR_DOMAIN_DEVICE_MODIFY_FORCE',
123
+ 'VIR_INTERFACE_XML_INACTIVE',
124
+ 'VIR_STORAGE_POOL_INACCESSIBLE',
125
+ 'VIR_DOMAIN_EVENT_DEFINED',
126
+ 'VIR_DOMAIN_EVENT_STARTED',
127
+ 'VIR_DOMAIN_EVENT_SUSPENDED_IOERROR',
128
+ 'VIR_DOMAIN_EVENT_ID_WATCHDOG',
129
+ 'VIR_DOMAIN_EVENT_ID_IO_ERROR',
130
+ 'VIR_DOMAIN_EVENT_ID_GRAPHICS',
131
+ 'VIR_DOMAIN_EVENT_ID_REBOOT',
132
+ 'VIR_DOMAIN_EVENT_ID_RTC_CHANGE',
133
+ 'VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON',
134
+ ]
135
+
51
136
  have_libvirt_types(libvirt_types)
52
137
  have_libvirt_funcs(libvirt_funcs)
138
+ if find_header("libvirt/libvirt-qemu.h")
139
+ have_func("virDomainQemuMonitorCommand", "libvirt/libvirt-qemu.h")
140
+ end
141
+
142
+ have_libvirt_consts(libvirt_consts)
53
143
 
54
144
  create_header
55
145
  create_makefile(extension_name)
@@ -36,109 +36,16 @@ static virInterfacePtr interface_get(VALUE s) {
36
36
  generic_get(Interface, s);
37
37
  }
38
38
 
39
- static VALUE interface_new(virInterfacePtr i, VALUE conn) {
39
+ VALUE interface_new(virInterfacePtr i, VALUE conn) {
40
40
  return generic_new(c_interface, i, conn, interface_free);
41
41
  }
42
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
43
  /*
138
44
  * call-seq:
139
45
  * interface.undefine -> nil
140
46
  *
141
47
  * Call +virInterfaceUndefine+[http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceUndefine]
48
+ * to undefine this interface.
142
49
  */
143
50
  static VALUE libvirt_interface_undefine(VALUE s) {
144
51
  gen_call_void(virInterfaceUndefine, conn(s), interface_get(s));
@@ -146,22 +53,38 @@ static VALUE libvirt_interface_undefine(VALUE s) {
146
53
 
147
54
  /*
148
55
  * call-seq:
149
- * interface.create -> nil
56
+ * interface.create(flags=0) -> nil
150
57
  *
151
58
  * Call +virInterfaceCreate+[http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceCreate]
59
+ * to start this interface.
152
60
  */
153
- static VALUE libvirt_interface_create(VALUE s) {
154
- gen_call_void(virInterfaceCreate, conn(s), interface_get(s), 0);
61
+ static VALUE libvirt_interface_create(int argc, VALUE *argv, VALUE s) {
62
+ VALUE flags;
63
+
64
+ rb_scan_args(argc, argv, "01", &flags);
65
+ if (NIL_P(flags))
66
+ flags = INT2FIX(0);
67
+
68
+ gen_call_void(virInterfaceCreate, conn(s), interface_get(s),
69
+ NUM2UINT(flags));
155
70
  }
156
71
 
157
72
  /*
158
73
  * call-seq:
159
- * interface.destroy -> nil
74
+ * interface.destroy(flags=0) -> nil
160
75
  *
161
76
  * Call +virInterfaceDestroy+[http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceDestroy]
77
+ * to shutdown this interface.
162
78
  */
163
- static VALUE libvirt_interface_destroy(VALUE s) {
164
- gen_call_void(virInterfaceDestroy, conn(s), interface_get(s), 0);
79
+ static VALUE libvirt_interface_destroy(int argc, VALUE *argv, VALUE s) {
80
+ VALUE flags;
81
+
82
+ rb_scan_args(argc, argv, "01", &flags);
83
+ if (NIL_P(flags))
84
+ flags = INT2FIX(0);
85
+
86
+ gen_call_void(virInterfaceDestroy, conn(s), interface_get(s),
87
+ NUM2UINT(flags));
165
88
  }
166
89
 
167
90
  #if HAVE_VIRINTERFACEISACTIVE
@@ -170,6 +93,7 @@ static VALUE libvirt_interface_destroy(VALUE s) {
170
93
  * interface.active? -> [true|false]
171
94
  *
172
95
  * Call +virInterfaceIsActive+[http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceIsActive]
96
+ * to determine if this interface is currently active.
173
97
  */
174
98
  static VALUE libvirt_interface_active_p(VALUE p) {
175
99
  gen_call_truefalse(virInterfaceIsActive, conn(p), interface_get(p));
@@ -181,6 +105,7 @@ static VALUE libvirt_interface_active_p(VALUE p) {
181
105
  * interface.name -> string
182
106
  *
183
107
  * Call +virInterfaceGetName+[http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceGetName]
108
+ * to retrieve the name of this interface.
184
109
  */
185
110
  static VALUE libvirt_interface_name(VALUE s) {
186
111
  gen_call_string(virInterfaceGetName, conn(s), 0, interface_get(s));
@@ -191,6 +116,7 @@ static VALUE libvirt_interface_name(VALUE s) {
191
116
  * interface.mac -> string
192
117
  *
193
118
  * Call +virInterfaceGetMACString+[http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceGetMACString]
119
+ * to retrieve the MAC address of this interface.
194
120
  */
195
121
  static VALUE libvirt_interface_mac(VALUE s) {
196
122
  gen_call_string(virInterfaceGetMACString, conn(s), 0, interface_get(s));
@@ -201,6 +127,7 @@ static VALUE libvirt_interface_mac(VALUE s) {
201
127
  * interface.xml_desc -> string
202
128
  *
203
129
  * Call +virInterfaceGetXMLDesc+[http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceGetXMLDesc]
130
+ * to retrieve the XML of this interface.
204
131
  */
205
132
  static VALUE libvirt_interface_xml_desc(int argc, VALUE *argv, VALUE s) {
206
133
  VALUE flags;
@@ -214,6 +141,16 @@ static VALUE libvirt_interface_xml_desc(int argc, VALUE *argv, VALUE s) {
214
141
  NUM2UINT(flags));
215
142
  }
216
143
 
144
+ /*
145
+ * call-seq:
146
+ * interface.free -> nil
147
+ *
148
+ * Call +virInterfaceFree+[http://www.libvirt.org/html/libvirt-libvirt.html#virInterfaceFree]
149
+ * to free this interface. The object will no longer be valid after this call.
150
+ */
151
+ static VALUE libvirt_interface_free(VALUE s) {
152
+ gen_call_free(Interface, s);
153
+ }
217
154
  #endif
218
155
 
219
156
  /*
@@ -223,28 +160,12 @@ void init_interface()
223
160
  {
224
161
  #if HAVE_TYPE_VIRINTERFACEPTR
225
162
  c_interface = rb_define_class_under(m_libvirt, "Interface", rb_cObject);
226
- #ifdef VIR_INTERFACE_XML_INACTIVE
163
+ #if HAVE_CONST_VIR_INTERFACE_XML_INACTIVE
227
164
  rb_define_const(c_interface, "XML_INACTIVE",
228
165
  INT2NUM(VIR_INTERFACE_XML_INACTIVE));
229
166
  #endif
230
167
  rb_define_attr(c_interface, "connection", 1, 0);
231
168
 
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
169
  /* Interface object methods */
249
170
  rb_define_method(c_interface, "name", libvirt_interface_name, 0);
250
171
  rb_define_method(c_interface, "mac", libvirt_interface_mac, 0);
@@ -252,6 +173,7 @@ void init_interface()
252
173
  rb_define_method(c_interface, "undefine", libvirt_interface_undefine, 0);
253
174
  rb_define_method(c_interface, "create", libvirt_interface_create, -1);
254
175
  rb_define_method(c_interface, "destroy", libvirt_interface_destroy, -1);
176
+ rb_define_method(c_interface, "free", libvirt_interface_free, 0);
255
177
  #if HAVE_VIRINTERFACEISACTIVE
256
178
  rb_define_method(c_interface, "active?", libvirt_interface_active_p, 0);
257
179
  #endif
@@ -36,119 +36,16 @@ static virNetworkPtr network_get(VALUE s) {
36
36
  generic_get(Network, s);
37
37
  }
38
38
 
39
- static VALUE network_new(virNetworkPtr n, VALUE conn) {
39
+ VALUE network_new(virNetworkPtr n, VALUE conn) {
40
40
  return generic_new(c_network, n, conn, network_free);
41
41
  }
42
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
43
  /*
148
44
  * call-seq:
149
45
  * net.undefine -> nil
150
46
  *
151
47
  * Call +virNetworkUndefine+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkUndefine]
48
+ * to undefine this network.
152
49
  */
153
50
  static VALUE libvirt_netw_undefine(VALUE s) {
154
51
  gen_call_void(virNetworkUndefine, conn(s), network_get(s));
@@ -159,6 +56,7 @@ static VALUE libvirt_netw_undefine(VALUE s) {
159
56
  * net.create -> nil
160
57
  *
161
58
  * Call +virNetworkCreate+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkCreate]
59
+ * to start this network.
162
60
  */
163
61
  static VALUE libvirt_netw_create(VALUE s) {
164
62
  gen_call_void(virNetworkCreate, conn(s), network_get(s));
@@ -169,6 +67,7 @@ static VALUE libvirt_netw_create(VALUE s) {
169
67
  * net.destroy -> nil
170
68
  *
171
69
  * Call +virNetworkDestroy+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkDestroy]
70
+ * to shutdown this network.
172
71
  */
173
72
  static VALUE libvirt_netw_destroy(VALUE s) {
174
73
  gen_call_void(virNetworkDestroy, conn(s), network_get(s));
@@ -179,6 +78,7 @@ static VALUE libvirt_netw_destroy(VALUE s) {
179
78
  * net.name -> string
180
79
  *
181
80
  * Call +virNetworkGetName+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkGetName]
81
+ * to retrieve the name of this network.
182
82
  */
183
83
  static VALUE libvirt_netw_name(VALUE s) {
184
84
  gen_call_string(virNetworkGetName, conn(s), 0, network_get(s));
@@ -189,6 +89,7 @@ static VALUE libvirt_netw_name(VALUE s) {
189
89
  * net.uuid -> string
190
90
  *
191
91
  * Call +virNetworkGetUUIDString+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkGetUUIDString]
92
+ * to retrieve the UUID of this network.
192
93
  */
193
94
  static VALUE libvirt_netw_uuid(VALUE s) {
194
95
  virNetworkPtr netw = network_get(s);
@@ -196,16 +97,18 @@ static VALUE libvirt_netw_uuid(VALUE s) {
196
97
  int r;
197
98
 
198
99
  r = virNetworkGetUUIDString(netw, uuid);
199
- _E(r < 0, create_error(e_RetrieveError, "virNetworkGetUUIDString", "", conn(s)));
100
+ _E(r < 0, create_error(e_RetrieveError, "virNetworkGetUUIDString",
101
+ conn(s)));
200
102
 
201
103
  return rb_str_new2((char *) uuid);
202
104
  }
203
105
 
204
106
  /*
205
107
  * call-seq:
206
- * net.xml_desc -> string
108
+ * net.xml_desc(flags=0) -> string
207
109
  *
208
110
  * Call +virNetworkGetXMLDesc+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkGetXMLDesc]
111
+ * to retrieve the XML for this network.
209
112
  */
210
113
  static VALUE libvirt_netw_xml_desc(int argc, VALUE *argv, VALUE s) {
211
114
  VALUE flags;
@@ -224,6 +127,7 @@ static VALUE libvirt_netw_xml_desc(int argc, VALUE *argv, VALUE s) {
224
127
  * net.bridge_name -> string
225
128
  *
226
129
  * Call +virNetworkGetBridgeName+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkGetBridgeName]
130
+ * to retrieve the bridge name for this network.
227
131
  */
228
132
  static VALUE libvirt_netw_bridge_name(VALUE s) {
229
133
  gen_call_string(virNetworkGetBridgeName, conn(s), 1, network_get(s));
@@ -234,24 +138,30 @@ static VALUE libvirt_netw_bridge_name(VALUE s) {
234
138
  * net.autostart? -> [true|false]
235
139
  *
236
140
  * Call +virNetworkGetAutostart+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkGetAutostart]
141
+ * to determine if this network will be autostarted when libvirtd starts.
237
142
  */
238
143
  static VALUE libvirt_netw_autostart(VALUE s){
239
144
  virNetworkPtr netw = network_get(s);
240
145
  int r, autostart;
241
146
 
242
147
  r = virNetworkGetAutostart(netw, &autostart);
243
- _E(r < 0, create_error(e_RetrieveError, "virNetworkAutostart", "", conn(s)));
148
+ _E(r < 0, create_error(e_RetrieveError, "virNetworkAutostart", conn(s)));
244
149
 
245
150
  return autostart ? Qtrue : Qfalse;
246
151
  }
247
152
 
248
153
  /*
249
154
  * call-seq:
250
- * net.autostart_set -> nil
155
+ * net.autostart = [true|false]
251
156
  *
252
157
  * Call +virNetworkSetAutostart+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkSetAutostart]
158
+ * to set this network to be autostarted when libvirtd starts.
253
159
  */
254
160
  static VALUE libvirt_netw_autostart_set(VALUE s, VALUE autostart) {
161
+ if (autostart != Qtrue && autostart != Qfalse)
162
+ rb_raise(rb_eTypeError,
163
+ "wrong argument type (expected TrueClass or FalseClass)");
164
+
255
165
  gen_call_void(virNetworkSetAutostart, conn(s), network_get(s),
256
166
  RTEST(autostart) ? 1 : 0);
257
167
  }
@@ -261,6 +171,7 @@ static VALUE libvirt_netw_autostart_set(VALUE s, VALUE autostart) {
261
171
  * net.free -> nil
262
172
  *
263
173
  * Call +virNetworkFree+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkFree]
174
+ * to free this network. The object will no longer be valid after this call.
264
175
  */
265
176
  static VALUE libvirt_netw_free(VALUE s) {
266
177
  gen_call_free(Network, s);
@@ -272,6 +183,7 @@ static VALUE libvirt_netw_free(VALUE s) {
272
183
  * net.active? -> [true|false]
273
184
  *
274
185
  * Call +virNetworkIsActive+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkIsActive]
186
+ * to determine if this network is currently active.
275
187
  */
276
188
  static VALUE libvirt_netw_active_p(VALUE s) {
277
189
  gen_call_truefalse(virNetworkIsActive, conn(s), network_get(s));
@@ -284,6 +196,7 @@ static VALUE libvirt_netw_active_p(VALUE s) {
284
196
  * net.persistent? -> [true|false]
285
197
  *
286
198
  * Call +virNetworkIsPersistent+[http://www.libvirt.org/html/libvirt-libvirt.html#virNetworkIsPersistent]
199
+ * to determine if this network is persistent.
287
200
  */
288
201
  static VALUE libvirt_netw_persistent_p(VALUE s) {
289
202
  gen_call_truefalse(virNetworkIsPersistent, conn(s), network_get(s));
@@ -301,22 +214,6 @@ void init_network()
301
214
  c_network = rb_define_class_under(m_libvirt, "Network", rb_cObject);
302
215
  rb_define_attr(c_network, "connection", 1, 0);
303
216
 
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
217
  rb_define_method(c_network, "undefine", libvirt_netw_undefine, 0);
321
218
  rb_define_method(c_network, "create", libvirt_netw_create, 0);
322
219
  rb_define_method(c_network, "destroy", libvirt_netw_destroy, 0);