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.
- data/NEWS +43 -0
- data/README +40 -2
- data/README.rdoc +3 -1
- data/Rakefile +3 -25
- data/ext/libvirt/_libvirt.c +636 -35
- data/ext/libvirt/common.c +142 -16
- data/ext/libvirt/common.h +78 -22
- data/ext/libvirt/connect.c +1811 -95
- data/ext/libvirt/connect.h +0 -1
- data/ext/libvirt/domain.c +880 -424
- data/ext/libvirt/domain.h +4 -0
- data/ext/libvirt/extconf.rb +90 -0
- data/ext/libvirt/interface.c +40 -118
- data/ext/libvirt/network.c +22 -125
- data/ext/libvirt/network.h +1 -0
- data/ext/libvirt/nodedevice.c +27 -142
- data/ext/libvirt/nwfilter.c +10 -83
- data/ext/libvirt/secret.c +35 -113
- data/ext/libvirt/storage.c +125 -223
- data/tests/test_conn.rb +193 -43
- data/tests/test_domain.rb +1067 -102
- data/tests/test_interface.rb +156 -19
- data/tests/test_network.rb +237 -26
- data/tests/test_nodedevice.rb +103 -15
- data/tests/test_nwfilter.rb +97 -14
- data/tests/test_open.rb +186 -6
- data/tests/test_secret.rb +126 -14
- data/tests/test_storage.rb +513 -40
- data/tests/test_utils.rb +73 -0
- metadata +5 -6
- data/tests/node.xml +0 -110
- data/tests/tc_connect.rb +0 -178
data/ext/libvirt/storage.c
CHANGED
@@ -50,165 +50,33 @@ static virStoragePoolPtr pool_get(VALUE s) {
|
|
50
50
|
generic_get(StoragePool, s);
|
51
51
|
}
|
52
52
|
|
53
|
-
|
53
|
+
VALUE pool_new(virStoragePoolPtr n, VALUE conn) {
|
54
54
|
return generic_new(c_storage_pool, n, conn, pool_free);
|
55
55
|
}
|
56
56
|
|
57
57
|
/*
|
58
58
|
* call-seq:
|
59
|
-
*
|
60
|
-
*
|
61
|
-
* Call +virConnectListStoragePools+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectListStoragePools]
|
62
|
-
*/
|
63
|
-
static VALUE libvirt_conn_list_storage_pools(VALUE s) {
|
64
|
-
gen_conn_list_names(s, StoragePools);
|
65
|
-
}
|
66
|
-
|
67
|
-
/*
|
68
|
-
* call-seq:
|
69
|
-
* conn.num_of_storage_pools -> fixnum
|
70
|
-
*
|
71
|
-
* Call +virConnectNumOfStoragePools+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectNumOfStoragePools]
|
72
|
-
*/
|
73
|
-
static VALUE libvirt_conn_num_of_storage_pools(VALUE s) {
|
74
|
-
gen_conn_num_of(s, StoragePools);
|
75
|
-
}
|
76
|
-
|
77
|
-
/*
|
78
|
-
* call-seq:
|
79
|
-
* conn.list_defined_storage_pools -> list
|
80
|
-
*
|
81
|
-
* Call +virConnectListDefinedStoragePools+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectListDefinedStoragePools]
|
82
|
-
*/
|
83
|
-
static VALUE libvirt_conn_list_defined_storage_pools(VALUE s) {
|
84
|
-
gen_conn_list_names(s, DefinedStoragePools);
|
85
|
-
}
|
86
|
-
|
87
|
-
/*
|
88
|
-
* call-seq:
|
89
|
-
* conn.num_of_defined_storage_pools -> fixnum
|
90
|
-
*
|
91
|
-
* Call +virConnectNumOfDefinedStoragePools+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectNumOfDefinedStoragePools]
|
92
|
-
*/
|
93
|
-
static VALUE libvirt_conn_num_of_defined_storage_pools(VALUE s) {
|
94
|
-
gen_conn_num_of(s, DefinedStoragePools);
|
95
|
-
}
|
96
|
-
|
97
|
-
/*
|
98
|
-
* call-seq:
|
99
|
-
* conn.lookup_pool_by_name -> Libvirt::StoragePool
|
100
|
-
*
|
101
|
-
* Call +virStoragePoolLookupByName+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolLookupByName]
|
102
|
-
*/
|
103
|
-
static VALUE libvirt_conn_lookup_pool_by_name(VALUE c, VALUE name) {
|
104
|
-
virStoragePoolPtr pool;
|
105
|
-
virConnectPtr conn = connect_get(c);
|
106
|
-
|
107
|
-
pool = virStoragePoolLookupByName(conn, StringValueCStr(name));
|
108
|
-
_E(pool == NULL, create_error(e_RetrieveError, "virStoragePoolLookupByName", "", conn));
|
109
|
-
|
110
|
-
return pool_new(pool, c);
|
111
|
-
}
|
112
|
-
|
113
|
-
/*
|
114
|
-
* call-seq:
|
115
|
-
* conn.lookup_pool_by_uuid -> Libvirt::StoragePool
|
116
|
-
*
|
117
|
-
* Call +virStoragePoolLookupByUUIDString+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolLookupByUUIDString]
|
118
|
-
*/
|
119
|
-
static VALUE libvirt_conn_lookup_pool_by_uuid(VALUE c, VALUE uuid) {
|
120
|
-
virStoragePoolPtr pool;
|
121
|
-
virConnectPtr conn = connect_get(c);
|
122
|
-
|
123
|
-
pool = virStoragePoolLookupByUUIDString(conn, StringValueCStr(uuid));
|
124
|
-
_E(pool == NULL, create_error(e_RetrieveError, "virStoragePoolLookupByUUID", "", conn));
|
125
|
-
|
126
|
-
return pool_new(pool, c);
|
127
|
-
}
|
128
|
-
|
129
|
-
/*
|
130
|
-
* call-seq:
|
131
|
-
* vol.get_pool -> Libvirt::StoragePool
|
59
|
+
* vol.pool -> Libvirt::StoragePool
|
132
60
|
*
|
133
61
|
* Call +virStoragePoolLookupByVolume+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolLookupByVolume]
|
62
|
+
* to retrieve the storage pool for this volume.
|
134
63
|
*/
|
135
64
|
static VALUE libvirt_vol_get_pool(VALUE v) {
|
136
65
|
virStoragePoolPtr pool;
|
137
66
|
|
138
67
|
pool = virStoragePoolLookupByVolume(vol_get(v));
|
139
|
-
_E(pool == NULL, create_error(e_RetrieveError,
|
68
|
+
_E(pool == NULL, create_error(e_RetrieveError,
|
69
|
+
"virStoragePoolLookupByVolume", conn(v)));
|
140
70
|
|
141
71
|
return pool_new(pool, conn_attr(v));
|
142
72
|
}
|
143
73
|
|
144
74
|
/*
|
145
75
|
* call-seq:
|
146
|
-
*
|
147
|
-
*
|
148
|
-
* Call +virStoragePoolCreateXML+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolCreateXML]
|
149
|
-
*/
|
150
|
-
static VALUE libvirt_conn_create_pool_xml(int argc, VALUE *argv, VALUE c) {
|
151
|
-
virStoragePoolPtr pool;
|
152
|
-
virConnectPtr conn = connect_get(c);
|
153
|
-
VALUE xml, flags;
|
154
|
-
|
155
|
-
rb_scan_args(argc, argv, "11", &xml, &flags);
|
156
|
-
|
157
|
-
if (NIL_P(flags))
|
158
|
-
flags = INT2FIX(0);
|
159
|
-
|
160
|
-
pool = virStoragePoolCreateXML(conn, StringValueCStr(xml), NUM2UINT(flags));
|
161
|
-
_E(pool == NULL, create_error(e_Error, "virStoragePoolCreateXML", "", conn));
|
162
|
-
|
163
|
-
return pool_new(pool, c);
|
164
|
-
}
|
165
|
-
|
166
|
-
/*
|
167
|
-
* call-seq:
|
168
|
-
* conn.define_pool_xml -> Libvirt::StoragePool
|
169
|
-
*
|
170
|
-
* Call +virStoragePoolDefineXML+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolDefineXML]
|
171
|
-
*/
|
172
|
-
static VALUE libvirt_conn_define_pool_xml(int argc, VALUE *argv, VALUE c) {
|
173
|
-
virStoragePoolPtr pool;
|
174
|
-
virConnectPtr conn = connect_get(c);
|
175
|
-
VALUE xml, flags;
|
176
|
-
|
177
|
-
rb_scan_args(argc, argv, "11", &xml, &flags);
|
178
|
-
|
179
|
-
if (NIL_P(flags))
|
180
|
-
flags = INT2FIX(0);
|
181
|
-
|
182
|
-
pool = virStoragePoolDefineXML(conn, StringValueCStr(xml), NUM2UINT(flags));
|
183
|
-
_E(pool == NULL, create_error(e_DefinitionError, "virStoragePoolDefineXML", "", conn));
|
184
|
-
|
185
|
-
return pool_new(pool, c);
|
186
|
-
}
|
187
|
-
|
188
|
-
/*
|
189
|
-
* call-seq:
|
190
|
-
* conn.find_storage_pool_sources -> string
|
191
|
-
*
|
192
|
-
* Call +virConnectFindStoragePoolSources+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectFindStoragePoolSources]
|
193
|
-
*/
|
194
|
-
static VALUE libvirt_conn_find_storage_pool_sources(int argc, VALUE *argv, VALUE c) {
|
195
|
-
VALUE type, srcSpec_val, flags;
|
196
|
-
|
197
|
-
rb_scan_args(argc, argv, "12", &type, &srcSpec_val, &flags);
|
198
|
-
|
199
|
-
if (NIL_P(flags))
|
200
|
-
flags = INT2FIX(0);
|
201
|
-
|
202
|
-
gen_call_string(virConnectFindStoragePoolSources, conn(c), 1,
|
203
|
-
connect_get(c), StringValueCStr(type),
|
204
|
-
get_string_or_nil(srcSpec_val), NUM2UINT(flags));
|
205
|
-
}
|
206
|
-
|
207
|
-
/*
|
208
|
-
* call-seq:
|
209
|
-
* pool.build -> nil
|
76
|
+
* pool.build(flags=0) -> nil
|
210
77
|
*
|
211
78
|
* Call +virStoragePoolBuild+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolBuild]
|
79
|
+
* to build this storage pool.
|
212
80
|
*/
|
213
81
|
static VALUE libvirt_pool_build(int argc, VALUE *argv, VALUE p) {
|
214
82
|
VALUE flags;
|
@@ -226,6 +94,7 @@ static VALUE libvirt_pool_build(int argc, VALUE *argv, VALUE p) {
|
|
226
94
|
* pool.undefine -> nil
|
227
95
|
*
|
228
96
|
* Call +virStoragePoolUndefine+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolUndefine]
|
97
|
+
* to undefine this storage pool.
|
229
98
|
*/
|
230
99
|
static VALUE libvirt_pool_undefine(VALUE p) {
|
231
100
|
gen_call_void(virStoragePoolUndefine, conn(p), pool_get(p));
|
@@ -233,9 +102,10 @@ static VALUE libvirt_pool_undefine(VALUE p) {
|
|
233
102
|
|
234
103
|
/*
|
235
104
|
* call-seq:
|
236
|
-
* pool.create -> nil
|
105
|
+
* pool.create(flags=0) -> nil
|
237
106
|
*
|
238
107
|
* Call +virStoragePoolCreate+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolCreate]
|
108
|
+
* to start this storage pool.
|
239
109
|
*/
|
240
110
|
static VALUE libvirt_pool_create(int argc, VALUE *argv, VALUE p) {
|
241
111
|
VALUE flags;
|
@@ -253,6 +123,7 @@ static VALUE libvirt_pool_create(int argc, VALUE *argv, VALUE p) {
|
|
253
123
|
* pool.destroy -> nil
|
254
124
|
*
|
255
125
|
* Call +virStoragePoolDestroy+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolDestroy]
|
126
|
+
* to shutdown this storage pool.
|
256
127
|
*/
|
257
128
|
static VALUE libvirt_pool_destroy(VALUE p) {
|
258
129
|
gen_call_void(virStoragePoolDestroy, conn(p), pool_get(p));
|
@@ -260,9 +131,11 @@ static VALUE libvirt_pool_destroy(VALUE p) {
|
|
260
131
|
|
261
132
|
/*
|
262
133
|
* call-seq:
|
263
|
-
* pool.delete -> nil
|
134
|
+
* pool.delete(flags=0) -> nil
|
264
135
|
*
|
265
136
|
* Call +virStoragePoolDelete+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolDelete]
|
137
|
+
* to delete the data corresponding to this data pool. This is a destructive
|
138
|
+
* operation.
|
266
139
|
*/
|
267
140
|
static VALUE libvirt_pool_delete(int argc, VALUE *argv, VALUE p) {
|
268
141
|
VALUE flags;
|
@@ -277,9 +150,10 @@ static VALUE libvirt_pool_delete(int argc, VALUE *argv, VALUE p) {
|
|
277
150
|
|
278
151
|
/*
|
279
152
|
* call-seq:
|
280
|
-
* pool.refresh -> nil
|
153
|
+
* pool.refresh(flags=0) -> nil
|
281
154
|
*
|
282
155
|
* Call +virStoragePoolRefresh+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolRefresh]
|
156
|
+
* to refresh the list of volumes in this storage pool.
|
283
157
|
*/
|
284
158
|
static VALUE libvirt_pool_refresh(int argc, VALUE *argv, VALUE p) {
|
285
159
|
VALUE flags;
|
@@ -297,6 +171,7 @@ static VALUE libvirt_pool_refresh(int argc, VALUE *argv, VALUE p) {
|
|
297
171
|
* pool.name -> string
|
298
172
|
*
|
299
173
|
* Call +virStoragePoolGetName+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolGetName]
|
174
|
+
* to retrieve the name of this storage pool.
|
300
175
|
*/
|
301
176
|
static VALUE libvirt_pool_name(VALUE s) {
|
302
177
|
gen_call_string(virStoragePoolGetName, conn(s), 0, pool_get(s));
|
@@ -307,13 +182,15 @@ static VALUE libvirt_pool_name(VALUE s) {
|
|
307
182
|
* pool.uuid -> string
|
308
183
|
*
|
309
184
|
* Call +virStoragePoolGetUUIDString+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolGetUUIDString]
|
185
|
+
* to retrieve the UUID of this storage pool.
|
310
186
|
*/
|
311
187
|
static VALUE libvirt_pool_uuid(VALUE s) {
|
312
188
|
char uuid[VIR_UUID_STRING_BUFLEN];
|
313
189
|
int r;
|
314
190
|
|
315
191
|
r = virStoragePoolGetUUIDString(pool_get(s), uuid);
|
316
|
-
_E(r < 0, create_error(e_RetrieveError, "virStoragePoolGetUUIDString",
|
192
|
+
_E(r < 0, create_error(e_RetrieveError, "virStoragePoolGetUUIDString",
|
193
|
+
conn(s)));
|
317
194
|
|
318
195
|
return rb_str_new2((char *) uuid);
|
319
196
|
}
|
@@ -323,6 +200,7 @@ static VALUE libvirt_pool_uuid(VALUE s) {
|
|
323
200
|
* pool.info -> Libvirt::StoragePoolInfo
|
324
201
|
*
|
325
202
|
* Call +virStoragePoolGetInfo+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolGetInfo]
|
203
|
+
* to retrieve information about this storage pool.
|
326
204
|
*/
|
327
205
|
static VALUE libvirt_pool_info(VALUE s) {
|
328
206
|
virStoragePoolInfo info;
|
@@ -330,7 +208,7 @@ static VALUE libvirt_pool_info(VALUE s) {
|
|
330
208
|
VALUE result;
|
331
209
|
|
332
210
|
r = virStoragePoolGetInfo(pool_get(s), &info);
|
333
|
-
_E(r < 0, create_error(e_RetrieveError, "virStoragePoolGetInfo",
|
211
|
+
_E(r < 0, create_error(e_RetrieveError, "virStoragePoolGetInfo", conn(s)));
|
334
212
|
|
335
213
|
result = rb_class_new_instance(0, NULL, c_storage_pool_info);
|
336
214
|
rb_iv_set(result, "@state", INT2FIX(info.state));
|
@@ -343,9 +221,10 @@ static VALUE libvirt_pool_info(VALUE s) {
|
|
343
221
|
|
344
222
|
/*
|
345
223
|
* call-seq:
|
346
|
-
* pool.xml_desc -> string
|
224
|
+
* pool.xml_desc(flags=0) -> string
|
347
225
|
*
|
348
226
|
* Call +virStoragePoolGetXMLDesc+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolGetXMLDesc]
|
227
|
+
* to retrieve the XML for this storage pool.
|
349
228
|
*/
|
350
229
|
static VALUE libvirt_pool_xml_desc(int argc, VALUE *argv, VALUE s) {
|
351
230
|
VALUE flags;
|
@@ -364,23 +243,30 @@ static VALUE libvirt_pool_xml_desc(int argc, VALUE *argv, VALUE s) {
|
|
364
243
|
* pool.autostart? -> [true|false]
|
365
244
|
*
|
366
245
|
* Call +virStoragePoolGetAutostart+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolGetAutostart]
|
246
|
+
* to determine whether this storage pool will autostart when libvirtd starts.
|
367
247
|
*/
|
368
248
|
static VALUE libvirt_pool_autostart(VALUE s){
|
369
249
|
int r, autostart;
|
370
250
|
|
371
251
|
r = virStoragePoolGetAutostart(pool_get(s), &autostart);
|
372
|
-
_E(r < 0, create_error(e_RetrieveError, "virStoragePoolGetAutostart",
|
252
|
+
_E(r < 0, create_error(e_RetrieveError, "virStoragePoolGetAutostart",
|
253
|
+
conn(s)));
|
373
254
|
|
374
255
|
return autostart ? Qtrue : Qfalse;
|
375
256
|
}
|
376
257
|
|
377
258
|
/*
|
378
259
|
* call-seq:
|
379
|
-
* pool.
|
260
|
+
* pool.autostart = [true|false]
|
380
261
|
*
|
381
262
|
* Call +virStoragePoolSetAutostart+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolSetAutostart]
|
263
|
+
* to make this storage pool start when libvirtd starts.
|
382
264
|
*/
|
383
265
|
static VALUE libvirt_pool_autostart_set(VALUE s, VALUE autostart) {
|
266
|
+
if (autostart != Qtrue && autostart != Qfalse)
|
267
|
+
rb_raise(rb_eTypeError,
|
268
|
+
"wrong argument type (expected TrueClass or FalseClass)");
|
269
|
+
|
384
270
|
gen_call_void(virStoragePoolSetAutostart, conn(s), pool_get(s),
|
385
271
|
RTEST(autostart) ? 1 : 0);
|
386
272
|
}
|
@@ -390,12 +276,14 @@ static VALUE libvirt_pool_autostart_set(VALUE s, VALUE autostart) {
|
|
390
276
|
* pool.num_of_volumes -> fixnum
|
391
277
|
*
|
392
278
|
* Call +virStoragePoolNumOfVolumes+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolNumOfVolumes]
|
279
|
+
* to retrieve the number of volumes in this storage pool.
|
393
280
|
*/
|
394
281
|
static VALUE libvirt_pool_num_of_volumes(VALUE s) {
|
395
282
|
int n = virStoragePoolNumOfVolumes(pool_get(s));
|
396
|
-
_E(n < 0, create_error(e_RetrieveError, "virStoragePoolNumOfVolumes",
|
283
|
+
_E(n < 0, create_error(e_RetrieveError, "virStoragePoolNumOfVolumes",
|
284
|
+
conn(s)));
|
397
285
|
|
398
|
-
return
|
286
|
+
return INT2NUM(n);
|
399
287
|
}
|
400
288
|
|
401
289
|
/*
|
@@ -403,34 +291,28 @@ static VALUE libvirt_pool_num_of_volumes(VALUE s) {
|
|
403
291
|
* pool.list_volumes -> list
|
404
292
|
*
|
405
293
|
* Call +virStoragePoolListVolumes+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolListVolumes]
|
294
|
+
* to retrieve a list of volume names in this storage pools.
|
406
295
|
*/
|
407
296
|
static VALUE libvirt_pool_list_volumes(VALUE s) {
|
408
|
-
int
|
297
|
+
int r, num;
|
409
298
|
char **names;
|
410
299
|
virStoragePoolPtr pool = pool_get(s);
|
411
|
-
VALUE result;
|
412
300
|
|
413
301
|
num = virStoragePoolNumOfVolumes(pool);
|
414
|
-
_E(num < 0, create_error(e_RetrieveError, "virStoragePoolNumOfVolumes",
|
415
|
-
|
416
|
-
|
417
|
-
return
|
418
|
-
}
|
302
|
+
_E(num < 0, create_error(e_RetrieveError, "virStoragePoolNumOfVolumes",
|
303
|
+
conn(s)));
|
304
|
+
if (num == 0)
|
305
|
+
return rb_ary_new2(num);
|
419
306
|
|
420
307
|
names = ALLOC_N(char *, num);
|
421
308
|
r = virStoragePoolListVolumes(pool, names, num);
|
422
309
|
if (r < 0) {
|
423
|
-
|
424
|
-
|
310
|
+
xfree(names);
|
311
|
+
rb_exc_raise(create_error(e_RetrieveError, "virStoragePoolListVolumes",
|
312
|
+
conn(s)));
|
425
313
|
}
|
426
314
|
|
427
|
-
|
428
|
-
for (i=0; i<num; i++) {
|
429
|
-
rb_ary_push(result, rb_str_new2(names[i]));
|
430
|
-
free(names[i]);
|
431
|
-
}
|
432
|
-
free(names);
|
433
|
-
return result;
|
315
|
+
return gen_list(num, &names);
|
434
316
|
}
|
435
317
|
|
436
318
|
/*
|
@@ -438,6 +320,8 @@ static VALUE libvirt_pool_list_volumes(VALUE s) {
|
|
438
320
|
* pool.free -> nil
|
439
321
|
*
|
440
322
|
* Call +virStoragePoolFree+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolFree]
|
323
|
+
* to free this storage pool object. After this call the storage pool object
|
324
|
+
* is no longer valid.
|
441
325
|
*/
|
442
326
|
static VALUE libvirt_pool_free(VALUE s) {
|
443
327
|
gen_call_free(StoragePool, s);
|
@@ -461,47 +345,53 @@ static VALUE vol_new(virStorageVolPtr n, VALUE conn) {
|
|
461
345
|
|
462
346
|
/*
|
463
347
|
* call-seq:
|
464
|
-
* pool.
|
348
|
+
* pool.lookup_volume_by_name(name) -> Libvirt::StorageVol
|
465
349
|
*
|
466
350
|
* Call +virStorageVolLookupByName+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolLookupByName]
|
351
|
+
* to retrieve a storage volume object by name.
|
467
352
|
*/
|
468
353
|
static VALUE libvirt_pool_lookup_vol_by_name(VALUE p, VALUE name) {
|
469
354
|
virStorageVolPtr vol;
|
470
355
|
|
471
356
|
vol = virStorageVolLookupByName(pool_get(p), StringValueCStr(name));
|
472
|
-
_E(vol == NULL, create_error(e_RetrieveError, "virStorageVolLookupByName",
|
357
|
+
_E(vol == NULL, create_error(e_RetrieveError, "virStorageVolLookupByName",
|
358
|
+
conn(p)));
|
473
359
|
|
474
360
|
return vol_new(vol, conn_attr(p));
|
475
361
|
}
|
476
362
|
|
477
363
|
/*
|
478
364
|
* call-seq:
|
479
|
-
* pool.
|
365
|
+
* pool.lookup_volume_by_key(key) -> Libvirt::StorageVol
|
480
366
|
*
|
481
367
|
* Call +virStorageVolLookupByKey+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolLookupByKey]
|
368
|
+
* to retrieve a storage volume object by key.
|
482
369
|
*/
|
483
370
|
static VALUE libvirt_pool_lookup_vol_by_key(VALUE p, VALUE key) {
|
484
371
|
virStorageVolPtr vol;
|
485
372
|
|
486
|
-
|
373
|
+
/* FIXME: Why does this take a connection, not a pool? */
|
487
374
|
vol = virStorageVolLookupByKey(conn(p), StringValueCStr(key));
|
488
|
-
_E(vol == NULL, create_error(e_RetrieveError, "virStorageVolLookupByKey",
|
375
|
+
_E(vol == NULL, create_error(e_RetrieveError, "virStorageVolLookupByKey",
|
376
|
+
conn(p)));
|
489
377
|
|
490
378
|
return vol_new(vol, conn_attr(p));
|
491
379
|
}
|
492
380
|
|
493
381
|
/*
|
494
382
|
* call-seq:
|
495
|
-
* pool.
|
383
|
+
* pool.lookup_volume_by_path(path) -> Libvirt::StorageVol
|
496
384
|
*
|
497
385
|
* Call +virStorageVolLookupByPath+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolLookupByPath]
|
386
|
+
* to retrieve a storage volume object by path.
|
498
387
|
*/
|
499
388
|
static VALUE libvirt_pool_lookup_vol_by_path(VALUE p, VALUE path) {
|
500
389
|
virStorageVolPtr vol;
|
501
390
|
|
502
|
-
|
391
|
+
/* FIXME: Why does this take a connection, not a pool? */
|
503
392
|
vol = virStorageVolLookupByPath(conn(p), StringValueCStr(path));
|
504
|
-
_E(vol == NULL, create_error(e_RetrieveError, "virStorageVolLookupByPath",
|
393
|
+
_E(vol == NULL, create_error(e_RetrieveError, "virStorageVolLookupByPath",
|
394
|
+
conn(p)));
|
505
395
|
|
506
396
|
return vol_new(vol, conn_attr(p));
|
507
397
|
}
|
@@ -511,6 +401,7 @@ static VALUE libvirt_pool_lookup_vol_by_path(VALUE p, VALUE path) {
|
|
511
401
|
* vol.name -> string
|
512
402
|
*
|
513
403
|
* Call +virStorageVolGetName+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolGetName]
|
404
|
+
* to retrieve the name of this storage volume.
|
514
405
|
*/
|
515
406
|
static VALUE libvirt_vol_name(VALUE v) {
|
516
407
|
gen_call_string(virStorageVolGetName, conn(v), 0, vol_get(v));
|
@@ -521,6 +412,7 @@ static VALUE libvirt_vol_name(VALUE v) {
|
|
521
412
|
* vol.key -> string
|
522
413
|
*
|
523
414
|
* Call +virStorageVolGetKey+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolGetKey]
|
415
|
+
* to retrieve the key for this storage volume.
|
524
416
|
*/
|
525
417
|
static VALUE libvirt_vol_key(VALUE v) {
|
526
418
|
gen_call_string(virStorageVolGetKey, conn(v), 0, vol_get(v));
|
@@ -528,9 +420,10 @@ static VALUE libvirt_vol_key(VALUE v) {
|
|
528
420
|
|
529
421
|
/*
|
530
422
|
* call-seq:
|
531
|
-
* pool.
|
423
|
+
* pool.create_volume_xml(xml, flags=0) -> Libvirt::StorageVol
|
532
424
|
*
|
533
425
|
* Call +virStorageVolCreateXML+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolCreateXML]
|
426
|
+
* to create a new storage volume from xml.
|
534
427
|
*/
|
535
428
|
static VALUE libvirt_pool_vol_create_xml(int argc, VALUE *argv, VALUE p) {
|
536
429
|
virStorageVolPtr vol;
|
@@ -544,16 +437,19 @@ static VALUE libvirt_pool_vol_create_xml(int argc, VALUE *argv, VALUE p) {
|
|
544
437
|
|
545
438
|
vol = virStorageVolCreateXML(pool_get(p), StringValueCStr(xml),
|
546
439
|
NUM2UINT(flags));
|
547
|
-
_E(vol == NULL, create_error(e_Error, "virNetworkCreateXML",
|
440
|
+
_E(vol == NULL, create_error(e_Error, "virNetworkCreateXML", c));
|
548
441
|
|
549
442
|
return vol_new(vol, conn_attr(p));
|
550
443
|
}
|
551
444
|
|
445
|
+
#if HAVE_VIRSTORAGEVOLCREATEXMLFROM
|
552
446
|
/*
|
553
447
|
* call-seq:
|
554
|
-
* pool.
|
448
|
+
* pool.create_volume_xml_from(xml, clonevol, flags=0) -> Libvirt::StorageVol
|
555
449
|
*
|
556
|
-
* Call +
|
450
|
+
* Call +virStorageVolCreateXMLFrom+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolCreateXMLFrom]
|
451
|
+
* to clone a volume from an existing volume with the properties specified in
|
452
|
+
* xml.
|
557
453
|
*/
|
558
454
|
static VALUE libvirt_pool_vol_create_xml_from(int argc, VALUE *argv, VALUE p) {
|
559
455
|
virStorageVolPtr vol;
|
@@ -567,10 +463,11 @@ static VALUE libvirt_pool_vol_create_xml_from(int argc, VALUE *argv, VALUE p) {
|
|
567
463
|
|
568
464
|
vol = virStorageVolCreateXMLFrom(pool_get(p), StringValueCStr(xml),
|
569
465
|
vol_get(cloneval), NUM2UINT(flags));
|
570
|
-
_E(vol == NULL, create_error(e_Error, "virNetworkCreateXMLFrom",
|
466
|
+
_E(vol == NULL, create_error(e_Error, "virNetworkCreateXMLFrom", c));
|
571
467
|
|
572
468
|
return vol_new(vol, conn_attr(p));
|
573
469
|
}
|
470
|
+
#endif
|
574
471
|
|
575
472
|
#if HAVE_VIRSTORAGEPOOLISACTIVE
|
576
473
|
/*
|
@@ -578,6 +475,7 @@ static VALUE libvirt_pool_vol_create_xml_from(int argc, VALUE *argv, VALUE p) {
|
|
578
475
|
* pool.active? -> [true|false]
|
579
476
|
*
|
580
477
|
* Call +virStoragePoolIsActive+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolIsActive]
|
478
|
+
* to determine if this storage pool is active.
|
581
479
|
*/
|
582
480
|
static VALUE libvirt_pool_active_p(VALUE p) {
|
583
481
|
gen_call_truefalse(virStoragePoolIsActive, conn(p), pool_get(p));
|
@@ -590,6 +488,7 @@ static VALUE libvirt_pool_active_p(VALUE p) {
|
|
590
488
|
* pool.persistent? -> [true|false]
|
591
489
|
*
|
592
490
|
* Call +virStoragePoolIsPersistent+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolIsPersistent]
|
491
|
+
* to determine if this storage pool is persistent.
|
593
492
|
*/
|
594
493
|
static VALUE libvirt_pool_persistent_p(VALUE p) {
|
595
494
|
gen_call_truefalse(virStoragePoolIsPersistent, conn(p), pool_get(p));
|
@@ -598,9 +497,10 @@ static VALUE libvirt_pool_persistent_p(VALUE p) {
|
|
598
497
|
|
599
498
|
/*
|
600
499
|
* call-seq:
|
601
|
-
* vol.delete -> nil
|
500
|
+
* vol.delete(flags=0) -> nil
|
602
501
|
*
|
603
502
|
* Call +virStorageVolDelete+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolDelete]
|
503
|
+
* to delete this volume. This is a destructive operation.
|
604
504
|
*/
|
605
505
|
static VALUE libvirt_vol_delete(int argc, VALUE *argv, VALUE v) {
|
606
506
|
VALUE flags;
|
@@ -616,9 +516,10 @@ static VALUE libvirt_vol_delete(int argc, VALUE *argv, VALUE v) {
|
|
616
516
|
#if HAVE_VIRSTORAGEVOLWIPE
|
617
517
|
/*
|
618
518
|
* call-seq:
|
619
|
-
* vol.wipe -> nil
|
519
|
+
* vol.wipe(flags=0) -> nil
|
620
520
|
*
|
621
521
|
* Call +virStorageVolWipe+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolWipe]
|
522
|
+
* to wipe the data from this storage volume. This is a destructive operation.
|
622
523
|
*/
|
623
524
|
static VALUE libvirt_vol_wipe(int argc, VALUE *argv, VALUE v) {
|
624
525
|
VALUE flags;
|
@@ -637,6 +538,7 @@ static VALUE libvirt_vol_wipe(int argc, VALUE *argv, VALUE v) {
|
|
637
538
|
* vol.info -> Libvirt::StorageVolInfo
|
638
539
|
*
|
639
540
|
* Call +virStorageVolGetInfo+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolGetInfo]
|
541
|
+
* to retrieve information about this storage volume.
|
640
542
|
*/
|
641
543
|
static VALUE libvirt_vol_info(VALUE v) {
|
642
544
|
virStorageVolInfo info;
|
@@ -644,7 +546,7 @@ static VALUE libvirt_vol_info(VALUE v) {
|
|
644
546
|
VALUE result;
|
645
547
|
|
646
548
|
r = virStorageVolGetInfo(vol_get(v), &info);
|
647
|
-
_E(r < 0, create_error(e_RetrieveError, "virStorageVolGetInfo",
|
549
|
+
_E(r < 0, create_error(e_RetrieveError, "virStorageVolGetInfo", conn(v)));
|
648
550
|
|
649
551
|
result = rb_class_new_instance(0, NULL, c_storage_vol_info);
|
650
552
|
rb_iv_set(result, "@type", INT2NUM(info.type));
|
@@ -656,9 +558,10 @@ static VALUE libvirt_vol_info(VALUE v) {
|
|
656
558
|
|
657
559
|
/*
|
658
560
|
* call-seq:
|
659
|
-
* vol.xml_desc -> string
|
561
|
+
* vol.xml_desc(flags=0) -> string
|
660
562
|
*
|
661
563
|
* Call +virStorageVolGetXMLDesc+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolGetXMLDesc]
|
564
|
+
* to retrieve the xml for this storage volume.
|
662
565
|
*/
|
663
566
|
static VALUE libvirt_vol_xml_desc(int argc, VALUE *argv, VALUE v) {
|
664
567
|
VALUE flags;
|
@@ -677,6 +580,7 @@ static VALUE libvirt_vol_xml_desc(int argc, VALUE *argv, VALUE v) {
|
|
677
580
|
* vol.path -> string
|
678
581
|
*
|
679
582
|
* Call +virStorageVolGetPath+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolGetPath]
|
583
|
+
* to retrieve the path for this storage volume.
|
680
584
|
*/
|
681
585
|
static VALUE libvirt_vol_path(VALUE v) {
|
682
586
|
gen_call_string(virStorageVolGetPath, conn(v), 1, vol_get(v));
|
@@ -687,6 +591,8 @@ static VALUE libvirt_vol_path(VALUE v) {
|
|
687
591
|
* vol.free -> nil
|
688
592
|
*
|
689
593
|
* Call +virStorageVolFree+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolFree]
|
594
|
+
* to free the storage volume object. After this call the storage volume object
|
595
|
+
* is no longer valid.
|
690
596
|
*/
|
691
597
|
static VALUE libvirt_vol_free(VALUE s) {
|
692
598
|
gen_call_free(StorageVol, s);
|
@@ -707,44 +613,34 @@ void init_storage(void) {
|
|
707
613
|
|
708
614
|
c_storage_pool = rb_define_class_under(m_libvirt, "StoragePool",
|
709
615
|
rb_cObject);
|
710
|
-
|
711
|
-
rb_define_const(c_storage_pool, #name, INT2NUM(VIR_STORAGE_POOL_##name))
|
616
|
+
|
712
617
|
/* virStoragePoolState */
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
618
|
+
rb_define_const(c_storage_pool, "INACTIVE",
|
619
|
+
INT2NUM(VIR_STORAGE_POOL_INACTIVE));
|
620
|
+
rb_define_const(c_storage_pool, "BUILDING",
|
621
|
+
INT2NUM(VIR_STORAGE_POOL_BUILDING));
|
622
|
+
rb_define_const(c_storage_pool, "RUNNING",
|
623
|
+
INT2NUM(VIR_STORAGE_POOL_RUNNING));
|
624
|
+
rb_define_const(c_storage_pool, "DEGRADED",
|
625
|
+
INT2NUM(VIR_STORAGE_POOL_DEGRADED));
|
626
|
+
#if HAVE_CONST_VIR_STORAGE_POOL_INACCESSIBLE
|
627
|
+
rb_define_const(c_storage_pool, "INACCESSIBLE",
|
628
|
+
INT2NUM(VIR_STORAGE_POOL_INACCESSIBLE));
|
719
629
|
#endif
|
630
|
+
|
720
631
|
/* virStoragePoolBuildFlags */
|
721
|
-
|
722
|
-
|
723
|
-
|
632
|
+
rb_define_const(c_storage_pool, "BUILD_NEW",
|
633
|
+
INT2NUM(VIR_STORAGE_POOL_BUILD_NEW));
|
634
|
+
rb_define_const(c_storage_pool, "BUILD_REPAIR",
|
635
|
+
INT2NUM(VIR_STORAGE_POOL_BUILD_REPAIR));
|
636
|
+
rb_define_const(c_storage_pool, "BUILD_RESIZE",
|
637
|
+
INT2NUM(VIR_STORAGE_POOL_BUILD_RESIZE));
|
638
|
+
|
724
639
|
/* virStoragePoolDeleteFlags */
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
/* StoragePool lookup/creation methods */
|
730
|
-
rb_define_method(c_connect, "num_of_storage_pools",
|
731
|
-
libvirt_conn_num_of_storage_pools, 0);
|
732
|
-
rb_define_method(c_connect, "list_storage_pools",
|
733
|
-
libvirt_conn_list_storage_pools, 0);
|
734
|
-
rb_define_method(c_connect, "num_of_defined_storage_pools",
|
735
|
-
libvirt_conn_num_of_defined_storage_pools, 0);
|
736
|
-
rb_define_method(c_connect, "list_defined_storage_pools",
|
737
|
-
libvirt_conn_list_defined_storage_pools, 0);
|
738
|
-
rb_define_method(c_connect, "lookup_storage_pool_by_name",
|
739
|
-
libvirt_conn_lookup_pool_by_name, 1);
|
740
|
-
rb_define_method(c_connect, "lookup_storage_pool_by_uuid",
|
741
|
-
libvirt_conn_lookup_pool_by_uuid, 1);
|
742
|
-
rb_define_method(c_connect, "create_storage_pool_xml",
|
743
|
-
libvirt_conn_create_pool_xml, -1);
|
744
|
-
rb_define_method(c_connect, "define_storage_pool_xml",
|
745
|
-
libvirt_conn_define_pool_xml, -1);
|
746
|
-
rb_define_method(c_connect, "discover_storage_pool_sources",
|
747
|
-
libvirt_conn_find_storage_pool_sources, -1);
|
640
|
+
rb_define_const(c_storage_pool, "DELETE_NORMAL",
|
641
|
+
INT2NUM(VIR_STORAGE_POOL_DELETE_NORMAL));
|
642
|
+
rb_define_const(c_storage_pool, "DELETE_ZEROED",
|
643
|
+
INT2NUM(VIR_STORAGE_POOL_DELETE_ZEROED));
|
748
644
|
|
749
645
|
/* Creating/destroying pools */
|
750
646
|
rb_define_method(c_storage_pool, "build", libvirt_pool_build, -1);
|
@@ -777,8 +673,13 @@ void init_storage(void) {
|
|
777
673
|
rb_define_method(c_storage_pool, "free", libvirt_pool_free, 0);
|
778
674
|
rb_define_method(c_storage_pool, "create_vol_xml",
|
779
675
|
libvirt_pool_vol_create_xml, -1);
|
676
|
+
rb_define_alias(c_storage_pool, "create_volume_xml", "create_vol_xml");
|
677
|
+
#if HAVE_VIRSTORAGEVOLCREATEXMLFROM
|
780
678
|
rb_define_method(c_storage_pool, "create_vol_xml_from",
|
781
679
|
libvirt_pool_vol_create_xml_from, -1);
|
680
|
+
rb_define_alias(c_storage_pool, "create_volume_xml_from",
|
681
|
+
"create_vol_xml_from");
|
682
|
+
#endif
|
782
683
|
#if HAVE_VIRSTORAGEPOOLISACTIVE
|
783
684
|
rb_define_method(c_storage_pool, "active?", libvirt_pool_active_p, 0);
|
784
685
|
#endif
|
@@ -800,15 +701,16 @@ void init_storage(void) {
|
|
800
701
|
|
801
702
|
c_storage_vol = rb_define_class_under(m_libvirt, "StorageVol",
|
802
703
|
rb_cObject);
|
803
|
-
|
804
|
-
rb_define_const(c_storage_vol, #name, INT2NUM(VIR_STORAGE_VOL_##name))
|
704
|
+
|
805
705
|
/* virStorageVolType */
|
806
|
-
|
807
|
-
|
706
|
+
rb_define_const(c_storage_vol, "FILE", INT2NUM(VIR_STORAGE_VOL_FILE));
|
707
|
+
rb_define_const(c_storage_vol, "BLOCK", INT2NUM(VIR_STORAGE_VOL_BLOCK));
|
708
|
+
|
808
709
|
/* virStorageVolDeleteFlags */
|
809
|
-
|
810
|
-
|
811
|
-
|
710
|
+
rb_define_const(c_storage_vol, "DELETE_NORMAL",
|
711
|
+
INT2NUM(VIR_STORAGE_VOL_DELETE_NORMAL));
|
712
|
+
rb_define_const(c_storage_vol, "DELETE_ZEROED",
|
713
|
+
INT2NUM(VIR_STORAGE_VOL_DELETE_ZEROED));
|
812
714
|
|
813
715
|
rb_define_method(c_storage_vol, "pool", libvirt_vol_get_pool, 0);
|
814
716
|
rb_define_method(c_storage_vol, "name", libvirt_vol_name, 0);
|