ruby-libvirt 0.1.0 → 0.2.0
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.
- data/README.rdoc +16 -2
- data/Rakefile +8 -6
- data/ext/libvirt/_libvirt.c +85 -1872
- data/ext/libvirt/common.c +75 -0
- data/ext/libvirt/common.h +155 -0
- data/ext/libvirt/connect.c +392 -0
- data/ext/libvirt/connect.h +12 -0
- data/ext/libvirt/domain.c +1606 -0
- data/ext/libvirt/domain.h +8 -0
- data/ext/libvirt/extconf.rb +30 -1
- data/ext/libvirt/interface.c +259 -0
- data/ext/libvirt/interface.h +6 -0
- data/ext/libvirt/network.c +338 -0
- data/ext/libvirt/network.h +6 -0
- data/ext/libvirt/nodedevice.c +333 -0
- data/ext/libvirt/nodedevice.h +6 -0
- data/ext/libvirt/nwfilter.c +206 -0
- data/ext/libvirt/nwfilter.h +6 -0
- data/ext/libvirt/secret.c +288 -0
- data/ext/libvirt/secret.h +6 -0
- data/ext/libvirt/storage.c +825 -0
- data/ext/libvirt/storage.h +6 -0
- data/tests/tc_connect.rb +1 -1
- data/tests/test_conn.rb +53 -0
- data/tests/test_domain.rb +165 -0
- data/tests/test_interface.rb +35 -0
- data/tests/test_network.rb +40 -0
- data/tests/test_nodedevice.rb +23 -0
- data/tests/test_nwfilter.rb +28 -0
- data/tests/test_open.rb +23 -0
- data/tests/test_secret.rb +33 -0
- data/tests/test_storage.rb +49 -0
- metadata +58 -14
- data/ext/libvirt/extconf.h +0 -6
@@ -0,0 +1,288 @@
|
|
1
|
+
/*
|
2
|
+
* secret.c: virSecret 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_VIRSECRETPTR
|
29
|
+
static VALUE c_secret;
|
30
|
+
|
31
|
+
static void secret_free(void *s) {
|
32
|
+
generic_free(Secret, s);
|
33
|
+
}
|
34
|
+
|
35
|
+
static virSecretPtr secret_get(VALUE s) {
|
36
|
+
generic_get(Secret, s);
|
37
|
+
}
|
38
|
+
|
39
|
+
static VALUE secret_new(virSecretPtr s, VALUE conn) {
|
40
|
+
return generic_new(c_secret, s, conn, secret_free);
|
41
|
+
}
|
42
|
+
|
43
|
+
/*
|
44
|
+
* call-seq:
|
45
|
+
* conn.num_of_secrets -> fixnum
|
46
|
+
*
|
47
|
+
* Call +virConnectNumOfSecrets+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectNumOfSecrets]
|
48
|
+
*/
|
49
|
+
static VALUE libvirt_conn_num_of_secrets(VALUE s) {
|
50
|
+
gen_conn_num_of(s, Secrets);
|
51
|
+
}
|
52
|
+
|
53
|
+
/*
|
54
|
+
* call-seq:
|
55
|
+
* conn.list_secrets -> list
|
56
|
+
*
|
57
|
+
* Call +virConnectListSecrets+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectListSecrets]
|
58
|
+
*/
|
59
|
+
static VALUE libvirt_conn_list_secrets(VALUE s) {
|
60
|
+
gen_conn_list_names(s, Secrets);
|
61
|
+
}
|
62
|
+
|
63
|
+
/*
|
64
|
+
* call-seq:
|
65
|
+
* conn.lookup_secret_by_uuid -> Libvirt::Secret
|
66
|
+
*
|
67
|
+
* Call +virSecretLookupByUUID+[http://www.libvirt.org/html/libvirt-libvirt.html#virSecretLookupByUUID]
|
68
|
+
*/
|
69
|
+
static VALUE libvirt_conn_lookup_secret_by_uuid(VALUE c, VALUE uuid) {
|
70
|
+
virSecretPtr secret;
|
71
|
+
virConnectPtr conn = connect_get(c);
|
72
|
+
|
73
|
+
secret = virSecretLookupByUUIDString(conn, StringValueCStr(uuid));
|
74
|
+
_E(secret == NULL, create_error(e_RetrieveError, "virSecretLookupByUUID", "", conn));
|
75
|
+
|
76
|
+
return secret_new(secret, c);
|
77
|
+
}
|
78
|
+
|
79
|
+
/*
|
80
|
+
* call-seq:
|
81
|
+
* conn.lookup_secret_by_usage -> Libvirt::Secret
|
82
|
+
*
|
83
|
+
* Call +virSecretLookupByUsage+[http://www.libvirt.org/html/libvirt-libvirt.html#virSecretLookupByUsage]
|
84
|
+
*/
|
85
|
+
static VALUE libvirt_conn_lookup_secret_by_usage(int argc, VALUE *argv, VALUE c) {
|
86
|
+
virSecretPtr secret;
|
87
|
+
virConnectPtr conn = connect_get(c);
|
88
|
+
VALUE usageType, usageID;
|
89
|
+
|
90
|
+
rb_scan_args(argc, argv, "11", &usageType, &usageID);
|
91
|
+
|
92
|
+
secret = virSecretLookupByUsage(conn, usageType, StringValueCStr(usageID));
|
93
|
+
_E(secret == NULL, create_error(e_RetrieveError, "virSecretLookupByUsage", "", conn));
|
94
|
+
|
95
|
+
return secret_new(secret, c);
|
96
|
+
}
|
97
|
+
|
98
|
+
/*
|
99
|
+
* call-seq:
|
100
|
+
* conn.define_secret_xml -> Libvirt::Secret
|
101
|
+
*
|
102
|
+
* Call +virSecretDefineXML+[http://www.libvirt.org/html/libvirt-libvirt.html#virSecretDefineXML]
|
103
|
+
*/
|
104
|
+
static VALUE libvirt_conn_define_secret_xml(int argc, VALUE *argv, VALUE c) {
|
105
|
+
virSecretPtr secret;
|
106
|
+
virConnectPtr conn = connect_get(c);
|
107
|
+
VALUE xml, flags;
|
108
|
+
|
109
|
+
rb_scan_args(argc, argv, "11", &xml, &flags);
|
110
|
+
|
111
|
+
if (NIL_P(flags))
|
112
|
+
flags = INT2FIX(0);
|
113
|
+
|
114
|
+
secret = virSecretDefineXML(conn, StringValueCStr(xml), NUM2UINT(flags));
|
115
|
+
_E(secret == NULL, create_error(e_DefinitionError, "virSecretDefineXML", "", conn));
|
116
|
+
|
117
|
+
return secret_new(secret, c);
|
118
|
+
}
|
119
|
+
|
120
|
+
/*
|
121
|
+
* call-seq:
|
122
|
+
* secret.uuid -> string
|
123
|
+
*
|
124
|
+
* Call +virSecretGetUUIDString+[http://www.libvirt.org/html/libvirt-libvirt.html#virSecretGetUUIDString]
|
125
|
+
*/
|
126
|
+
static VALUE libvirt_secret_uuid(VALUE s) {
|
127
|
+
virSecretPtr secret = secret_get(s);
|
128
|
+
int r;
|
129
|
+
char uuid[VIR_UUID_STRING_BUFLEN];
|
130
|
+
|
131
|
+
r = virSecretGetUUIDString(secret, uuid);
|
132
|
+
_E(r < 0, create_error(e_RetrieveError, "virSecretGetUUIDString", "", conn(s)));
|
133
|
+
|
134
|
+
return rb_str_new2((char *)uuid);
|
135
|
+
}
|
136
|
+
|
137
|
+
/*
|
138
|
+
* call-seq:
|
139
|
+
* secret.usagetype -> fixnum
|
140
|
+
*
|
141
|
+
* Call +virSecretGetUsageType+[http://www.libvirt.org/html/libvirt-libvirt.html#virSecretGetUsageType]
|
142
|
+
*/
|
143
|
+
static VALUE libvirt_secret_usagetype(VALUE s) {
|
144
|
+
virSecretPtr secret = secret_get(s);
|
145
|
+
int ret;
|
146
|
+
|
147
|
+
ret = virSecretGetUsageType(secret);
|
148
|
+
_E(ret < 0, create_error(e_RetrieveError, "virSecretGetUsageType", "", conn(s)));
|
149
|
+
|
150
|
+
return INT2NUM(ret);
|
151
|
+
}
|
152
|
+
|
153
|
+
/*
|
154
|
+
* call-seq:
|
155
|
+
* secret.usageid -> string
|
156
|
+
*
|
157
|
+
* Call +virSecretGetUsageID+[http://www.libvirt.org/html/libvirt-libvirt.html#virSecretGetUsageID]
|
158
|
+
*/
|
159
|
+
static VALUE libvirt_secret_usageid(VALUE s) {
|
160
|
+
gen_call_string(virSecretGetUsageID, conn(s), 0, secret_get(s));
|
161
|
+
}
|
162
|
+
|
163
|
+
/*
|
164
|
+
* call-seq:
|
165
|
+
* secret.xml_desc -> string
|
166
|
+
*
|
167
|
+
* Call +virSecretGetXMLDesc+[http://www.libvirt.org/html/libvirt-libvirt.html#virSecretGetXMLDesc]
|
168
|
+
*/
|
169
|
+
static VALUE libvirt_secret_xml_desc(int argc, VALUE *argv, VALUE s) {
|
170
|
+
VALUE flags;
|
171
|
+
|
172
|
+
rb_scan_args(argc, argv, "01", &flags);
|
173
|
+
|
174
|
+
if (NIL_P(flags))
|
175
|
+
flags = INT2FIX(0);
|
176
|
+
|
177
|
+
gen_call_string(virSecretGetXMLDesc, conn(s), 1, secret_get(s),
|
178
|
+
NUM2UINT(flags));
|
179
|
+
}
|
180
|
+
|
181
|
+
/*
|
182
|
+
* call-seq:
|
183
|
+
* secret.set_value -> nil
|
184
|
+
*
|
185
|
+
* Call +virSecretSetValue+[http://www.libvirt.org/html/libvirt-libvirt.html#virSecretSetValue]
|
186
|
+
*/
|
187
|
+
static VALUE libvirt_secret_set_value(int argc, VALUE *argv, VALUE s) {
|
188
|
+
virSecretPtr secret = secret_get(s);
|
189
|
+
VALUE flags;
|
190
|
+
VALUE value;
|
191
|
+
int r;
|
192
|
+
|
193
|
+
rb_scan_args(argc, argv, "11", &value, &flags);
|
194
|
+
|
195
|
+
if (NIL_P(flags))
|
196
|
+
flags = INT2FIX(0);
|
197
|
+
|
198
|
+
StringValue(value);
|
199
|
+
|
200
|
+
r = virSecretSetValue(secret, (unsigned char *)RSTRING(value)->ptr,
|
201
|
+
RSTRING(value)->len, NUM2UINT(flags));
|
202
|
+
|
203
|
+
_E(r < 0, create_error(e_RetrieveError, "virSecretSetValue", "", conn(s)));
|
204
|
+
|
205
|
+
return Qnil;
|
206
|
+
}
|
207
|
+
|
208
|
+
/*
|
209
|
+
* call-seq:
|
210
|
+
* secret.get_value -> string
|
211
|
+
*
|
212
|
+
* Call +virSecretGetValue+[http://www.libvirt.org/html/libvirt-libvirt.html#virSecretGetValue]
|
213
|
+
*/
|
214
|
+
static VALUE libvirt_secret_get_value(int argc, VALUE *argv, VALUE s) {
|
215
|
+
virSecretPtr secret = secret_get(s);
|
216
|
+
VALUE flags;
|
217
|
+
unsigned char *ret;
|
218
|
+
size_t value_size;
|
219
|
+
|
220
|
+
rb_scan_args(argc, argv, "01", &flags);
|
221
|
+
|
222
|
+
if (NIL_P(flags))
|
223
|
+
flags = INT2FIX(0);
|
224
|
+
|
225
|
+
ret = virSecretGetValue(secret, &value_size, NUM2UINT(flags));
|
226
|
+
|
227
|
+
_E(ret == NULL, create_error(e_RetrieveError, "virSecretGetValue", "", conn(s)));
|
228
|
+
|
229
|
+
return rb_str_new((char *)ret, value_size);
|
230
|
+
}
|
231
|
+
|
232
|
+
/*
|
233
|
+
* call-seq:
|
234
|
+
* secret.undefine -> nil
|
235
|
+
*
|
236
|
+
* Call +virSecretUndefine+[http://www.libvirt.org/html/libvirt-libvirt.html#virSecretUndefine]
|
237
|
+
*/
|
238
|
+
static VALUE libvirt_secret_undefine(VALUE s) {
|
239
|
+
gen_call_void(virSecretUndefine, conn(s), secret_get(s));
|
240
|
+
}
|
241
|
+
|
242
|
+
/*
|
243
|
+
* call-seq:
|
244
|
+
* secret.free -> nil
|
245
|
+
*
|
246
|
+
* Call +virSecretFree+[http://www.libvirt.org/html/libvirt-libvirt.html#virSecretFree]
|
247
|
+
*/
|
248
|
+
static VALUE libvirt_secret_free(VALUE s) {
|
249
|
+
gen_call_free(Secret, s);
|
250
|
+
}
|
251
|
+
|
252
|
+
#endif
|
253
|
+
|
254
|
+
/*
|
255
|
+
* Class Libvirt::Secret
|
256
|
+
*/
|
257
|
+
void init_secret()
|
258
|
+
{
|
259
|
+
#if HAVE_TYPE_VIRSECRETPTR
|
260
|
+
c_secret = rb_define_class_under(m_libvirt, "Secret", rb_cObject);
|
261
|
+
|
262
|
+
rb_define_const(c_secret, "USAGE_TYPE_VOLUME",
|
263
|
+
INT2NUM(VIR_SECRET_USAGE_TYPE_VOLUME));
|
264
|
+
rb_define_attr(c_secret, "connection", 1, 0);
|
265
|
+
|
266
|
+
/* Secret lookup/creation methods */
|
267
|
+
rb_define_method(c_connect, "num_of_secrets",
|
268
|
+
libvirt_conn_num_of_secrets, 0);
|
269
|
+
rb_define_method(c_connect, "list_secrets",
|
270
|
+
libvirt_conn_list_secrets, 0);
|
271
|
+
rb_define_method(c_connect, "lookup_secret_by_uuid",
|
272
|
+
libvirt_conn_lookup_secret_by_uuid, 1);
|
273
|
+
rb_define_method(c_connect, "lookup_secret_by_usage",
|
274
|
+
libvirt_conn_lookup_secret_by_usage, -1);
|
275
|
+
rb_define_method(c_connect, "define_secret_xml",
|
276
|
+
libvirt_conn_define_secret_xml, -1);
|
277
|
+
|
278
|
+
/* Secret object methods */
|
279
|
+
rb_define_method(c_secret, "uuid", libvirt_secret_uuid, 0);
|
280
|
+
rb_define_method(c_secret, "usagetype", libvirt_secret_usagetype, 0);
|
281
|
+
rb_define_method(c_secret, "usageid", libvirt_secret_usageid, 0);
|
282
|
+
rb_define_method(c_secret, "xml_desc", libvirt_secret_xml_desc, -1);
|
283
|
+
rb_define_method(c_secret, "set_value", libvirt_secret_set_value, -1);
|
284
|
+
rb_define_method(c_secret, "get_value", libvirt_secret_get_value, -1);
|
285
|
+
rb_define_method(c_secret, "undefine", libvirt_secret_undefine, 0);
|
286
|
+
rb_define_method(c_secret, "free", libvirt_secret_free, 0);
|
287
|
+
#endif
|
288
|
+
}
|
@@ -0,0 +1,825 @@
|
|
1
|
+
/*
|
2
|
+
* storage.c: virStoragePool and virStorageVolume 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_VIRSTORAGEVOLPTR
|
29
|
+
/* this has to be here (as opposed to below with the rest of the volume
|
30
|
+
* stuff) because libvirt_vol_get_pool() relies on it
|
31
|
+
*/
|
32
|
+
static virStorageVolPtr vol_get(VALUE s) {
|
33
|
+
generic_get(StorageVol, s);
|
34
|
+
}
|
35
|
+
#endif
|
36
|
+
|
37
|
+
#if HAVE_TYPE_VIRSTORAGEPOOLPTR
|
38
|
+
static VALUE c_storage_pool;
|
39
|
+
static VALUE c_storage_pool_info;
|
40
|
+
|
41
|
+
/*
|
42
|
+
* Class Libvirt::StoragePool
|
43
|
+
*/
|
44
|
+
|
45
|
+
static void pool_free(void *d) {
|
46
|
+
generic_free(StoragePool, d);
|
47
|
+
}
|
48
|
+
|
49
|
+
static virStoragePoolPtr pool_get(VALUE s) {
|
50
|
+
generic_get(StoragePool, s);
|
51
|
+
}
|
52
|
+
|
53
|
+
static VALUE pool_new(virStoragePoolPtr n, VALUE conn) {
|
54
|
+
return generic_new(c_storage_pool, n, conn, pool_free);
|
55
|
+
}
|
56
|
+
|
57
|
+
/*
|
58
|
+
* call-seq:
|
59
|
+
* conn.list_storage_pools -> list
|
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
|
132
|
+
*
|
133
|
+
* Call +virStoragePoolLookupByVolume+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolLookupByVolume]
|
134
|
+
*/
|
135
|
+
static VALUE libvirt_vol_get_pool(VALUE v) {
|
136
|
+
virStoragePoolPtr pool;
|
137
|
+
|
138
|
+
pool = virStoragePoolLookupByVolume(vol_get(v));
|
139
|
+
_E(pool == NULL, create_error(e_RetrieveError, "virStoragePoolLookupByVolume", "", conn(v)));
|
140
|
+
|
141
|
+
return pool_new(pool, conn_attr(v));
|
142
|
+
}
|
143
|
+
|
144
|
+
/*
|
145
|
+
* call-seq:
|
146
|
+
* conn.create_pool_xml -> Libvirt::StoragePool
|
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
|
210
|
+
*
|
211
|
+
* Call +virStoragePoolBuild+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolBuild]
|
212
|
+
*/
|
213
|
+
static VALUE libvirt_pool_build(int argc, VALUE *argv, VALUE p) {
|
214
|
+
VALUE flags;
|
215
|
+
|
216
|
+
rb_scan_args(argc, argv, "01", &flags);
|
217
|
+
|
218
|
+
if (NIL_P(flags))
|
219
|
+
flags = INT2FIX(0);
|
220
|
+
|
221
|
+
gen_call_void(virStoragePoolBuild, conn(p), pool_get(p), NUM2UINT(flags));
|
222
|
+
}
|
223
|
+
|
224
|
+
/*
|
225
|
+
* call-seq:
|
226
|
+
* pool.undefine -> nil
|
227
|
+
*
|
228
|
+
* Call +virStoragePoolUndefine+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolUndefine]
|
229
|
+
*/
|
230
|
+
static VALUE libvirt_pool_undefine(VALUE p) {
|
231
|
+
gen_call_void(virStoragePoolUndefine, conn(p), pool_get(p));
|
232
|
+
}
|
233
|
+
|
234
|
+
/*
|
235
|
+
* call-seq:
|
236
|
+
* pool.create -> nil
|
237
|
+
*
|
238
|
+
* Call +virStoragePoolCreate+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolCreate]
|
239
|
+
*/
|
240
|
+
static VALUE libvirt_pool_create(int argc, VALUE *argv, VALUE p) {
|
241
|
+
VALUE flags;
|
242
|
+
|
243
|
+
rb_scan_args(argc, argv, "01", &flags);
|
244
|
+
|
245
|
+
if (NIL_P(flags))
|
246
|
+
flags = INT2FIX(0);
|
247
|
+
|
248
|
+
gen_call_void(virStoragePoolCreate, conn(p), pool_get(p), NUM2UINT(flags));
|
249
|
+
}
|
250
|
+
|
251
|
+
/*
|
252
|
+
* call-seq:
|
253
|
+
* pool.destroy -> nil
|
254
|
+
*
|
255
|
+
* Call +virStoragePoolDestroy+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolDestroy]
|
256
|
+
*/
|
257
|
+
static VALUE libvirt_pool_destroy(VALUE p) {
|
258
|
+
gen_call_void(virStoragePoolDestroy, conn(p), pool_get(p));
|
259
|
+
}
|
260
|
+
|
261
|
+
/*
|
262
|
+
* call-seq:
|
263
|
+
* pool.delete -> nil
|
264
|
+
*
|
265
|
+
* Call +virStoragePoolDelete+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolDelete]
|
266
|
+
*/
|
267
|
+
static VALUE libvirt_pool_delete(int argc, VALUE *argv, VALUE p) {
|
268
|
+
VALUE flags;
|
269
|
+
|
270
|
+
rb_scan_args(argc, argv, "01", &flags);
|
271
|
+
|
272
|
+
if (NIL_P(flags))
|
273
|
+
flags = INT2FIX(0);
|
274
|
+
|
275
|
+
gen_call_void(virStoragePoolDelete, conn(p), pool_get(p), NUM2UINT(flags));
|
276
|
+
}
|
277
|
+
|
278
|
+
/*
|
279
|
+
* call-seq:
|
280
|
+
* pool.refresh -> nil
|
281
|
+
*
|
282
|
+
* Call +virStoragePoolRefresh+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolRefresh]
|
283
|
+
*/
|
284
|
+
static VALUE libvirt_pool_refresh(int argc, VALUE *argv, VALUE p) {
|
285
|
+
VALUE flags;
|
286
|
+
|
287
|
+
rb_scan_args(argc, argv, "01", &flags);
|
288
|
+
|
289
|
+
if (NIL_P(flags))
|
290
|
+
flags = INT2FIX(0);
|
291
|
+
|
292
|
+
gen_call_void(virStoragePoolRefresh, conn(p), pool_get(p), NUM2UINT(flags));
|
293
|
+
}
|
294
|
+
|
295
|
+
/*
|
296
|
+
* call-seq:
|
297
|
+
* pool.name -> string
|
298
|
+
*
|
299
|
+
* Call +virStoragePoolGetName+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolGetName]
|
300
|
+
*/
|
301
|
+
static VALUE libvirt_pool_name(VALUE s) {
|
302
|
+
gen_call_string(virStoragePoolGetName, conn(s), 0, pool_get(s));
|
303
|
+
}
|
304
|
+
|
305
|
+
/*
|
306
|
+
* call-seq:
|
307
|
+
* pool.uuid -> string
|
308
|
+
*
|
309
|
+
* Call +virStoragePoolGetUUIDString+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolGetUUIDString]
|
310
|
+
*/
|
311
|
+
static VALUE libvirt_pool_uuid(VALUE s) {
|
312
|
+
char uuid[VIR_UUID_STRING_BUFLEN];
|
313
|
+
int r;
|
314
|
+
|
315
|
+
r = virStoragePoolGetUUIDString(pool_get(s), uuid);
|
316
|
+
_E(r < 0, create_error(e_RetrieveError, "virStoragePoolGetUUIDString", "", conn(s)));
|
317
|
+
|
318
|
+
return rb_str_new2((char *) uuid);
|
319
|
+
}
|
320
|
+
|
321
|
+
/*
|
322
|
+
* call-seq:
|
323
|
+
* pool.info -> Libvirt::StoragePoolInfo
|
324
|
+
*
|
325
|
+
* Call +virStoragePoolGetInfo+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolGetInfo]
|
326
|
+
*/
|
327
|
+
static VALUE libvirt_pool_info(VALUE s) {
|
328
|
+
virStoragePoolInfo info;
|
329
|
+
int r;
|
330
|
+
VALUE result;
|
331
|
+
|
332
|
+
r = virStoragePoolGetInfo(pool_get(s), &info);
|
333
|
+
_E(r < 0, create_error(e_RetrieveError, "virStoragePoolGetInfo", "", conn(s)));
|
334
|
+
|
335
|
+
result = rb_class_new_instance(0, NULL, c_storage_pool_info);
|
336
|
+
rb_iv_set(result, "@state", INT2FIX(info.state));
|
337
|
+
rb_iv_set(result, "@capacity", ULL2NUM(info.capacity));
|
338
|
+
rb_iv_set(result, "@allocation", ULL2NUM(info.allocation));
|
339
|
+
rb_iv_set(result, "@available", ULL2NUM(info.available));
|
340
|
+
|
341
|
+
return result;
|
342
|
+
}
|
343
|
+
|
344
|
+
/*
|
345
|
+
* call-seq:
|
346
|
+
* pool.xml_desc -> string
|
347
|
+
*
|
348
|
+
* Call +virStoragePoolGetXMLDesc+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolGetXMLDesc]
|
349
|
+
*/
|
350
|
+
static VALUE libvirt_pool_xml_desc(int argc, VALUE *argv, VALUE s) {
|
351
|
+
VALUE flags;
|
352
|
+
|
353
|
+
rb_scan_args(argc, argv, "01", &flags);
|
354
|
+
|
355
|
+
if (NIL_P(flags))
|
356
|
+
flags = INT2FIX(0);
|
357
|
+
|
358
|
+
gen_call_string(virStoragePoolGetXMLDesc, conn(s), 1, pool_get(s),
|
359
|
+
NUM2UINT(flags));
|
360
|
+
}
|
361
|
+
|
362
|
+
/*
|
363
|
+
* call-seq:
|
364
|
+
* pool.autostart? -> [true|false]
|
365
|
+
*
|
366
|
+
* Call +virStoragePoolGetAutostart+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolGetAutostart]
|
367
|
+
*/
|
368
|
+
static VALUE libvirt_pool_autostart(VALUE s){
|
369
|
+
int r, autostart;
|
370
|
+
|
371
|
+
r = virStoragePoolGetAutostart(pool_get(s), &autostart);
|
372
|
+
_E(r < 0, create_error(e_RetrieveError, "virStoragePoolGetAutostart", "", conn(s)));
|
373
|
+
|
374
|
+
return autostart ? Qtrue : Qfalse;
|
375
|
+
}
|
376
|
+
|
377
|
+
/*
|
378
|
+
* call-seq:
|
379
|
+
* pool.autostart_set -> nil
|
380
|
+
*
|
381
|
+
* Call +virStoragePoolSetAutostart+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolSetAutostart]
|
382
|
+
*/
|
383
|
+
static VALUE libvirt_pool_autostart_set(VALUE s, VALUE autostart) {
|
384
|
+
gen_call_void(virStoragePoolSetAutostart, conn(s), pool_get(s),
|
385
|
+
RTEST(autostart) ? 1 : 0);
|
386
|
+
}
|
387
|
+
|
388
|
+
/*
|
389
|
+
* call-seq:
|
390
|
+
* pool.num_of_volumes -> fixnum
|
391
|
+
*
|
392
|
+
* Call +virStoragePoolNumOfVolumes+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolNumOfVolumes]
|
393
|
+
*/
|
394
|
+
static VALUE libvirt_pool_num_of_volumes(VALUE s) {
|
395
|
+
int n = virStoragePoolNumOfVolumes(pool_get(s));
|
396
|
+
_E(n < 0, create_error(e_RetrieveError, "virStoragePoolNumOfVolumes", "", conn(s)));
|
397
|
+
|
398
|
+
return INT2FIX(n);
|
399
|
+
}
|
400
|
+
|
401
|
+
/*
|
402
|
+
* call-seq:
|
403
|
+
* pool.list_volumes -> list
|
404
|
+
*
|
405
|
+
* Call +virStoragePoolListVolumes+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolListVolumes]
|
406
|
+
*/
|
407
|
+
static VALUE libvirt_pool_list_volumes(VALUE s) {
|
408
|
+
int i, r, num;
|
409
|
+
char **names;
|
410
|
+
virStoragePoolPtr pool = pool_get(s);
|
411
|
+
VALUE result;
|
412
|
+
|
413
|
+
num = virStoragePoolNumOfVolumes(pool);
|
414
|
+
_E(num < 0, create_error(e_RetrieveError, "virStoragePoolNumOfVolumes", "", conn(s)));
|
415
|
+
if (num == 0) {
|
416
|
+
result = rb_ary_new2(num);
|
417
|
+
return result;
|
418
|
+
}
|
419
|
+
|
420
|
+
names = ALLOC_N(char *, num);
|
421
|
+
r = virStoragePoolListVolumes(pool, names, num);
|
422
|
+
if (r < 0) {
|
423
|
+
free(names);
|
424
|
+
_E(r < 0, create_error(e_RetrieveError, "virStoragePoolListVolumes", "", conn(s)));
|
425
|
+
}
|
426
|
+
|
427
|
+
result = rb_ary_new2(num);
|
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;
|
434
|
+
}
|
435
|
+
|
436
|
+
/*
|
437
|
+
* call-seq:
|
438
|
+
* pool.free -> nil
|
439
|
+
*
|
440
|
+
* Call +virStoragePoolFree+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolFree]
|
441
|
+
*/
|
442
|
+
static VALUE libvirt_pool_free(VALUE s) {
|
443
|
+
gen_call_free(StoragePool, s);
|
444
|
+
}
|
445
|
+
#endif
|
446
|
+
|
447
|
+
#if HAVE_TYPE_VIRSTORAGEVOLPTR
|
448
|
+
/*
|
449
|
+
* Libvirt::StorageVol
|
450
|
+
*/
|
451
|
+
static VALUE c_storage_vol;
|
452
|
+
static VALUE c_storage_vol_info;
|
453
|
+
|
454
|
+
static void vol_free(void *d) {
|
455
|
+
generic_free(StorageVol, d);
|
456
|
+
}
|
457
|
+
|
458
|
+
static VALUE vol_new(virStorageVolPtr n, VALUE conn) {
|
459
|
+
return generic_new(c_storage_vol, n, conn, vol_free);
|
460
|
+
}
|
461
|
+
|
462
|
+
/*
|
463
|
+
* call-seq:
|
464
|
+
* pool.lookup_vol_by_name -> Libvirt::StorageVol
|
465
|
+
*
|
466
|
+
* Call +virStorageVolLookupByName+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolLookupByName]
|
467
|
+
*/
|
468
|
+
static VALUE libvirt_pool_lookup_vol_by_name(VALUE p, VALUE name) {
|
469
|
+
virStorageVolPtr vol;
|
470
|
+
|
471
|
+
vol = virStorageVolLookupByName(pool_get(p), StringValueCStr(name));
|
472
|
+
_E(vol == NULL, create_error(e_RetrieveError, "virStorageVolLookupByName", "", conn(p)));
|
473
|
+
|
474
|
+
return vol_new(vol, conn_attr(p));
|
475
|
+
}
|
476
|
+
|
477
|
+
/*
|
478
|
+
* call-seq:
|
479
|
+
* pool.lookup_vol_by_key -> Libvirt::StorageVol
|
480
|
+
*
|
481
|
+
* Call +virStorageVolLookupByKey+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolLookupByKey]
|
482
|
+
*/
|
483
|
+
static VALUE libvirt_pool_lookup_vol_by_key(VALUE p, VALUE key) {
|
484
|
+
virStorageVolPtr vol;
|
485
|
+
|
486
|
+
// FIXME: Why does this take a connection, not a pool ?
|
487
|
+
vol = virStorageVolLookupByKey(conn(p), StringValueCStr(key));
|
488
|
+
_E(vol == NULL, create_error(e_RetrieveError, "virStorageVolLookupByKey", "", conn(p)));
|
489
|
+
|
490
|
+
return vol_new(vol, conn_attr(p));
|
491
|
+
}
|
492
|
+
|
493
|
+
/*
|
494
|
+
* call-seq:
|
495
|
+
* pool.lookup_vol_by_path -> Libvirt::StorageVol
|
496
|
+
*
|
497
|
+
* Call +virStorageVolLookupByPath+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolLookupByPath]
|
498
|
+
*/
|
499
|
+
static VALUE libvirt_pool_lookup_vol_by_path(VALUE p, VALUE path) {
|
500
|
+
virStorageVolPtr vol;
|
501
|
+
|
502
|
+
// FIXME: Why does this take a connection, not a pool ?
|
503
|
+
vol = virStorageVolLookupByPath(conn(p), StringValueCStr(path));
|
504
|
+
_E(vol == NULL, create_error(e_RetrieveError, "virStorageVolLookupByPath", "", conn(p)));
|
505
|
+
|
506
|
+
return vol_new(vol, conn_attr(p));
|
507
|
+
}
|
508
|
+
|
509
|
+
/*
|
510
|
+
* call-seq:
|
511
|
+
* vol.name -> string
|
512
|
+
*
|
513
|
+
* Call +virStorageVolGetName+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolGetName]
|
514
|
+
*/
|
515
|
+
static VALUE libvirt_vol_name(VALUE v) {
|
516
|
+
gen_call_string(virStorageVolGetName, conn(v), 0, vol_get(v));
|
517
|
+
}
|
518
|
+
|
519
|
+
/*
|
520
|
+
* call-seq:
|
521
|
+
* vol.key -> string
|
522
|
+
*
|
523
|
+
* Call +virStorageVolGetKey+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolGetKey]
|
524
|
+
*/
|
525
|
+
static VALUE libvirt_vol_key(VALUE v) {
|
526
|
+
gen_call_string(virStorageVolGetKey, conn(v), 0, vol_get(v));
|
527
|
+
}
|
528
|
+
|
529
|
+
/*
|
530
|
+
* call-seq:
|
531
|
+
* pool.vol_create_xml -> Libvirt::StorageVol
|
532
|
+
*
|
533
|
+
* Call +virStorageVolCreateXML+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolCreateXML]
|
534
|
+
*/
|
535
|
+
static VALUE libvirt_pool_vol_create_xml(int argc, VALUE *argv, VALUE p) {
|
536
|
+
virStorageVolPtr vol;
|
537
|
+
virConnectPtr c = conn(p);
|
538
|
+
VALUE xml, flags;
|
539
|
+
|
540
|
+
rb_scan_args(argc, argv, "11", &xml, &flags);
|
541
|
+
|
542
|
+
if (NIL_P(flags))
|
543
|
+
flags = INT2FIX(0);
|
544
|
+
|
545
|
+
vol = virStorageVolCreateXML(pool_get(p), StringValueCStr(xml),
|
546
|
+
NUM2UINT(flags));
|
547
|
+
_E(vol == NULL, create_error(e_Error, "virNetworkCreateXML", "", c));
|
548
|
+
|
549
|
+
return vol_new(vol, conn_attr(p));
|
550
|
+
}
|
551
|
+
|
552
|
+
/*
|
553
|
+
* call-seq:
|
554
|
+
* pool.vol_create_xml_from -> Libvirt::StorageVol
|
555
|
+
*
|
556
|
+
* Call +virStorageVolCreateXML+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolCreateXML]
|
557
|
+
*/
|
558
|
+
static VALUE libvirt_pool_vol_create_xml_from(int argc, VALUE *argv, VALUE p) {
|
559
|
+
virStorageVolPtr vol;
|
560
|
+
virConnectPtr c = conn(p);
|
561
|
+
VALUE xml, flags, cloneval;
|
562
|
+
|
563
|
+
rb_scan_args(argc, argv, "21", &xml, &cloneval, &flags);
|
564
|
+
|
565
|
+
if (NIL_P(flags))
|
566
|
+
flags = INT2FIX(0);
|
567
|
+
|
568
|
+
vol = virStorageVolCreateXMLFrom(pool_get(p), StringValueCStr(xml),
|
569
|
+
vol_get(cloneval), NUM2UINT(flags));
|
570
|
+
_E(vol == NULL, create_error(e_Error, "virNetworkCreateXMLFrom", "", c));
|
571
|
+
|
572
|
+
return vol_new(vol, conn_attr(p));
|
573
|
+
}
|
574
|
+
|
575
|
+
#if HAVE_VIRSTORAGEPOOLISACTIVE
|
576
|
+
/*
|
577
|
+
* call-seq:
|
578
|
+
* pool.active? -> [true|false]
|
579
|
+
*
|
580
|
+
* Call +virStoragePoolIsActive+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolIsActive]
|
581
|
+
*/
|
582
|
+
static VALUE libvirt_pool_active_p(VALUE p) {
|
583
|
+
gen_call_truefalse(virStoragePoolIsActive, conn(p), pool_get(p));
|
584
|
+
}
|
585
|
+
#endif
|
586
|
+
|
587
|
+
#if HAVE_VIRSTORAGEPOOLISPERSISTENT
|
588
|
+
/*
|
589
|
+
* call-seq:
|
590
|
+
* pool.persistent? -> [true|false]
|
591
|
+
*
|
592
|
+
* Call +virStoragePoolIsPersistent+[http://www.libvirt.org/html/libvirt-libvirt.html#virStoragePoolIsPersistent]
|
593
|
+
*/
|
594
|
+
static VALUE libvirt_pool_persistent_p(VALUE p) {
|
595
|
+
gen_call_truefalse(virStoragePoolIsPersistent, conn(p), pool_get(p));
|
596
|
+
}
|
597
|
+
#endif
|
598
|
+
|
599
|
+
/*
|
600
|
+
* call-seq:
|
601
|
+
* vol.delete -> nil
|
602
|
+
*
|
603
|
+
* Call +virStorageVolDelete+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolDelete]
|
604
|
+
*/
|
605
|
+
static VALUE libvirt_vol_delete(int argc, VALUE *argv, VALUE v) {
|
606
|
+
VALUE flags;
|
607
|
+
|
608
|
+
rb_scan_args(argc, argv, "01", &flags);
|
609
|
+
|
610
|
+
if (NIL_P(flags))
|
611
|
+
flags = INT2FIX(0);
|
612
|
+
|
613
|
+
gen_call_void(virStorageVolDelete, conn(v), vol_get(v), NUM2UINT(flags));
|
614
|
+
}
|
615
|
+
|
616
|
+
#if HAVE_VIRSTORAGEVOLWIPE
|
617
|
+
/*
|
618
|
+
* call-seq:
|
619
|
+
* vol.wipe -> nil
|
620
|
+
*
|
621
|
+
* Call +virStorageVolWipe+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolWipe]
|
622
|
+
*/
|
623
|
+
static VALUE libvirt_vol_wipe(int argc, VALUE *argv, VALUE v) {
|
624
|
+
VALUE flags;
|
625
|
+
|
626
|
+
rb_scan_args(argc, argv, "01", &flags);
|
627
|
+
|
628
|
+
if (NIL_P(flags))
|
629
|
+
flags = INT2FIX(0);
|
630
|
+
|
631
|
+
gen_call_void(virStorageVolWipe, conn(v), vol_get(v), NUM2UINT(flags));
|
632
|
+
}
|
633
|
+
#endif
|
634
|
+
|
635
|
+
/*
|
636
|
+
* call-seq:
|
637
|
+
* vol.info -> Libvirt::StorageVolInfo
|
638
|
+
*
|
639
|
+
* Call +virStorageVolGetInfo+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolGetInfo]
|
640
|
+
*/
|
641
|
+
static VALUE libvirt_vol_info(VALUE v) {
|
642
|
+
virStorageVolInfo info;
|
643
|
+
int r;
|
644
|
+
VALUE result;
|
645
|
+
|
646
|
+
r = virStorageVolGetInfo(vol_get(v), &info);
|
647
|
+
_E(r < 0, create_error(e_RetrieveError, "virStorageVolGetInfo", "", conn(v)));
|
648
|
+
|
649
|
+
result = rb_class_new_instance(0, NULL, c_storage_vol_info);
|
650
|
+
rb_iv_set(result, "@type", INT2NUM(info.type));
|
651
|
+
rb_iv_set(result, "@capacity", ULL2NUM(info.capacity));
|
652
|
+
rb_iv_set(result, "@allocation", ULL2NUM(info.allocation));
|
653
|
+
|
654
|
+
return result;
|
655
|
+
}
|
656
|
+
|
657
|
+
/*
|
658
|
+
* call-seq:
|
659
|
+
* vol.xml_desc -> string
|
660
|
+
*
|
661
|
+
* Call +virStorageVolGetXMLDesc+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolGetXMLDesc]
|
662
|
+
*/
|
663
|
+
static VALUE libvirt_vol_xml_desc(int argc, VALUE *argv, VALUE v) {
|
664
|
+
VALUE flags;
|
665
|
+
|
666
|
+
rb_scan_args(argc, argv, "01", &flags);
|
667
|
+
|
668
|
+
if (NIL_P(flags))
|
669
|
+
flags = INT2FIX(0);
|
670
|
+
|
671
|
+
gen_call_string(virStorageVolGetXMLDesc, conn(v), 1, vol_get(v),
|
672
|
+
NUM2UINT(flags));
|
673
|
+
}
|
674
|
+
|
675
|
+
/*
|
676
|
+
* call-seq:
|
677
|
+
* vol.path -> string
|
678
|
+
*
|
679
|
+
* Call +virStorageVolGetPath+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolGetPath]
|
680
|
+
*/
|
681
|
+
static VALUE libvirt_vol_path(VALUE v) {
|
682
|
+
gen_call_string(virStorageVolGetPath, conn(v), 1, vol_get(v));
|
683
|
+
}
|
684
|
+
|
685
|
+
/*
|
686
|
+
* call-seq:
|
687
|
+
* vol.free -> nil
|
688
|
+
*
|
689
|
+
* Call +virStorageVolFree+[http://www.libvirt.org/html/libvirt-libvirt.html#virStorageVolFree]
|
690
|
+
*/
|
691
|
+
static VALUE libvirt_vol_free(VALUE s) {
|
692
|
+
gen_call_free(StorageVol, s);
|
693
|
+
}
|
694
|
+
#endif
|
695
|
+
|
696
|
+
void init_storage(void) {
|
697
|
+
/*
|
698
|
+
* Class Libvirt::StoragePool and Libvirt::StoragePoolInfo
|
699
|
+
*/
|
700
|
+
#if HAVE_TYPE_VIRSTORAGEPOOLPTR
|
701
|
+
c_storage_pool_info = rb_define_class_under(m_libvirt, "StoragePoolInfo",
|
702
|
+
rb_cObject);
|
703
|
+
rb_define_attr(c_storage_pool_info, "state", 1, 0);
|
704
|
+
rb_define_attr(c_storage_pool_info, "capacity", 1, 0);
|
705
|
+
rb_define_attr(c_storage_pool_info, "allocation", 1, 0);
|
706
|
+
rb_define_attr(c_storage_pool_info, "available", 1, 0);
|
707
|
+
|
708
|
+
c_storage_pool = rb_define_class_under(m_libvirt, "StoragePool",
|
709
|
+
rb_cObject);
|
710
|
+
#define DEF_POOLCONST(name) \
|
711
|
+
rb_define_const(c_storage_pool, #name, INT2NUM(VIR_STORAGE_POOL_##name))
|
712
|
+
/* virStoragePoolState */
|
713
|
+
DEF_POOLCONST(INACTIVE);
|
714
|
+
DEF_POOLCONST(BUILDING);
|
715
|
+
DEF_POOLCONST(RUNNING);
|
716
|
+
DEF_POOLCONST(DEGRADED);
|
717
|
+
#ifdef VIR_STORAGE_POOL_INACCESSIBLE
|
718
|
+
DEF_POOLCONST(INACCESSIBLE);
|
719
|
+
#endif
|
720
|
+
/* virStoragePoolBuildFlags */
|
721
|
+
DEF_POOLCONST(BUILD_NEW);
|
722
|
+
DEF_POOLCONST(BUILD_REPAIR);
|
723
|
+
DEF_POOLCONST(BUILD_RESIZE);
|
724
|
+
/* virStoragePoolDeleteFlags */
|
725
|
+
DEF_POOLCONST(DELETE_NORMAL);
|
726
|
+
DEF_POOLCONST(DELETE_ZEROED);
|
727
|
+
#undef DEF_POOLCONST
|
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);
|
748
|
+
|
749
|
+
/* Creating/destroying pools */
|
750
|
+
rb_define_method(c_storage_pool, "build", libvirt_pool_build, -1);
|
751
|
+
rb_define_method(c_storage_pool, "undefine", libvirt_pool_undefine, 0);
|
752
|
+
rb_define_method(c_storage_pool, "create", libvirt_pool_create, -1);
|
753
|
+
rb_define_method(c_storage_pool, "destroy", libvirt_pool_destroy, 0);
|
754
|
+
rb_define_method(c_storage_pool, "delete", libvirt_pool_delete, -1);
|
755
|
+
rb_define_method(c_storage_pool, "refresh", libvirt_pool_refresh, -1);
|
756
|
+
/* StoragePool information */
|
757
|
+
rb_define_method(c_storage_pool, "name", libvirt_pool_name, 0);
|
758
|
+
rb_define_method(c_storage_pool, "uuid", libvirt_pool_uuid, 0);
|
759
|
+
rb_define_method(c_storage_pool, "info", libvirt_pool_info, 0);
|
760
|
+
rb_define_method(c_storage_pool, "xml_desc", libvirt_pool_xml_desc, -1);
|
761
|
+
rb_define_method(c_storage_pool, "autostart", libvirt_pool_autostart, 0);
|
762
|
+
rb_define_method(c_storage_pool, "autostart?", libvirt_pool_autostart, 0);
|
763
|
+
rb_define_method(c_storage_pool, "autostart=",
|
764
|
+
libvirt_pool_autostart_set, 1);
|
765
|
+
/* List/lookup storage volumes within a pool */
|
766
|
+
rb_define_method(c_storage_pool, "num_of_volumes",
|
767
|
+
libvirt_pool_num_of_volumes, 0);
|
768
|
+
rb_define_method(c_storage_pool, "list_volumes",
|
769
|
+
libvirt_pool_list_volumes, 0);
|
770
|
+
/* Lookup volumes based on various attributes */
|
771
|
+
rb_define_method(c_storage_pool, "lookup_volume_by_name",
|
772
|
+
libvirt_pool_lookup_vol_by_name, 1);
|
773
|
+
rb_define_method(c_storage_pool, "lookup_volume_by_key",
|
774
|
+
libvirt_pool_lookup_vol_by_key, 1);
|
775
|
+
rb_define_method(c_storage_pool, "lookup_volume_by_path",
|
776
|
+
libvirt_pool_lookup_vol_by_path, 1);
|
777
|
+
rb_define_method(c_storage_pool, "free", libvirt_pool_free, 0);
|
778
|
+
rb_define_method(c_storage_pool, "create_vol_xml",
|
779
|
+
libvirt_pool_vol_create_xml, -1);
|
780
|
+
rb_define_method(c_storage_pool, "create_vol_xml_from",
|
781
|
+
libvirt_pool_vol_create_xml_from, -1);
|
782
|
+
#if HAVE_VIRSTORAGEPOOLISACTIVE
|
783
|
+
rb_define_method(c_storage_pool, "active?", libvirt_pool_active_p, 0);
|
784
|
+
#endif
|
785
|
+
#if HAVE_VIRSTORAGEPOOLISPERSISTENT
|
786
|
+
rb_define_method(c_storage_pool, "persistent?",
|
787
|
+
libvirt_pool_persistent_p, 0);
|
788
|
+
#endif
|
789
|
+
#endif
|
790
|
+
|
791
|
+
#if HAVE_TYPE_VIRSTORAGEVOLPTR
|
792
|
+
/*
|
793
|
+
* Class Libvirt::StorageVol and Libvirt::StorageVolInfo
|
794
|
+
*/
|
795
|
+
c_storage_vol_info = rb_define_class_under(m_libvirt, "StorageVolInfo",
|
796
|
+
rb_cObject);
|
797
|
+
rb_define_attr(c_storage_vol_info, "type", 1, 0);
|
798
|
+
rb_define_attr(c_storage_vol_info, "capacity", 1, 0);
|
799
|
+
rb_define_attr(c_storage_vol_info, "allocation", 1, 0);
|
800
|
+
|
801
|
+
c_storage_vol = rb_define_class_under(m_libvirt, "StorageVol",
|
802
|
+
rb_cObject);
|
803
|
+
#define DEF_VOLCONST(name) \
|
804
|
+
rb_define_const(c_storage_vol, #name, INT2NUM(VIR_STORAGE_VOL_##name))
|
805
|
+
/* virStorageVolType */
|
806
|
+
DEF_VOLCONST(FILE);
|
807
|
+
DEF_VOLCONST(BLOCK);
|
808
|
+
/* virStorageVolDeleteFlags */
|
809
|
+
DEF_VOLCONST(DELETE_NORMAL);
|
810
|
+
DEF_VOLCONST(DELETE_ZEROED);
|
811
|
+
#undef DEF_VOLCONST
|
812
|
+
|
813
|
+
rb_define_method(c_storage_vol, "pool", libvirt_vol_get_pool, 0);
|
814
|
+
rb_define_method(c_storage_vol, "name", libvirt_vol_name, 0);
|
815
|
+
rb_define_method(c_storage_vol, "key", libvirt_vol_key, 0);
|
816
|
+
rb_define_method(c_storage_vol, "delete", libvirt_vol_delete, -1);
|
817
|
+
#if HAVE_VIRSTORAGEVOLWIPE
|
818
|
+
rb_define_method(c_storage_vol, "wipe", libvirt_vol_wipe, -1);
|
819
|
+
#endif
|
820
|
+
rb_define_method(c_storage_vol, "info", libvirt_vol_info, 0);
|
821
|
+
rb_define_method(c_storage_vol, "xml_desc", libvirt_vol_xml_desc, -1);
|
822
|
+
rb_define_method(c_storage_vol, "path", libvirt_vol_path, 0);
|
823
|
+
rb_define_method(c_storage_vol, "free", libvirt_vol_free, 0);
|
824
|
+
#endif
|
825
|
+
}
|