ruby-libvirt 0.2.0 → 0.3.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.
@@ -1,6 +1,7 @@
1
1
  #ifndef NETWORK_H
2
2
  #define NETWORK_H
3
3
 
4
+ VALUE network_new(virNetworkPtr n, VALUE conn);
4
5
  void init_network();
5
6
 
6
7
  #endif
@@ -25,6 +25,7 @@
25
25
  #include "connect.h"
26
26
  #include "extconf.h"
27
27
 
28
+ #if HAVE_TYPE_VIRNODEDEVICEPTR
28
29
  static VALUE c_nodedevice;
29
30
 
30
31
  static void nodedevice_free(void *s) {
@@ -35,123 +36,16 @@ static virNodeDevicePtr nodedevice_get(VALUE s) {
35
36
  generic_get(NodeDevice, s);
36
37
  }
37
38
 
38
- static VALUE nodedevice_new(virNodeDevicePtr s, VALUE conn) {
39
+ VALUE nodedevice_new(virNodeDevicePtr s, VALUE conn) {
39
40
  return generic_new(c_nodedevice, s, conn, nodedevice_free);
40
41
  }
41
42
 
42
- /*
43
- * call-seq:
44
- * conn.num_of_nodedevices -> fixnum
45
- *
46
- * Call +virNodeNumOfDevices+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeNumOfDevices]
47
- */
48
- static VALUE libvirt_conn_num_of_nodedevices(int argc, VALUE *argv, VALUE c) {
49
- int result;
50
- virConnectPtr conn = connect_get(c);
51
- VALUE cap, flags;
52
-
53
- rb_scan_args(argc, argv, "02", &cap, &flags);
54
-
55
- if (NIL_P(flags))
56
- flags = INT2FIX(0);
57
-
58
- result = virNodeNumOfDevices(conn, get_string_or_nil(cap), NUM2UINT(flags));
59
- _E(result < 0, create_error(e_RetrieveError, "virNodeNumOfDevices", "",
60
- conn));
61
-
62
- return INT2NUM(result);
63
- }
64
-
65
- /*
66
- * call-seq:
67
- * conn.list_nodedevices -> list
68
- *
69
- * Call +virNodeListDevices+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeListDevices]
70
- */
71
- static VALUE libvirt_conn_list_nodedevices(int argc, VALUE *argv, VALUE c) {
72
- int i, r, num;
73
- virConnectPtr conn = connect_get(c);
74
- VALUE cap, flags;
75
- char *capstr;
76
- VALUE result;
77
- char **names;
78
-
79
- rb_scan_args(argc, argv, "02", &cap, &flags);
80
-
81
- if (NIL_P(flags))
82
- flags = INT2FIX(0);
83
-
84
- capstr = get_string_or_nil(cap);
85
-
86
- num = virNodeNumOfDevices(conn, capstr, 0);
87
- _E(num < 0, create_error(e_RetrieveError, "virNodeNumOfDevices", "", conn));
88
- if (num == 0) {
89
- /* if num is 0, don't call virNodeListDevices function */
90
- result = rb_ary_new2(num);
91
- return result;
92
- }
93
- names = ALLOC_N(char *, num);
94
- r = virNodeListDevices(conn, capstr, names, num, NUM2UINT(flags));
95
- if (r < 0) {
96
- free(names);
97
- _E(r < 0, create_error(e_RetrieveError, "virNodeListDevices", "", conn));
98
- }
99
-
100
- result = rb_ary_new2(num);
101
- for (i=0; i<num; i++) {
102
- rb_ary_push(result, rb_str_new2(names[i]));
103
- free(names[i]);
104
- }
105
- free(names);
106
- return result;
107
- }
108
-
109
- /*
110
- * call-seq:
111
- * conn.lookup_nodedevice_by_name -> Libvirt::NodeDevice
112
- *
113
- * Call +virNodeDeviceLookupByName+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceLookupByName]
114
- */
115
- static VALUE libvirt_conn_lookup_nodedevice_by_name(VALUE c, VALUE name) {
116
- virNodeDevicePtr nodedev;
117
- virConnectPtr conn = connect_get(c);
118
-
119
- nodedev = virNodeDeviceLookupByName(conn, StringValueCStr(name));
120
- _E(nodedev == NULL, create_error(e_RetrieveError, "virNodeDeviceLookupByName", "", conn));
121
-
122
- return nodedevice_new(nodedev, c);
123
-
124
- }
125
-
126
- #if HAVE_VIRNODEDEVICECREATEXML
127
- /*
128
- * call-seq:
129
- * conn.create_nodedevice_xml -> Libvirt::NodeDevice
130
- *
131
- * Call +virNodeDeviceCreateXML+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceCreateXML]
132
- */
133
- static VALUE libvirt_conn_create_nodedevice_xml(int argc, VALUE *argv, VALUE c) {
134
- virNodeDevicePtr nodedev;
135
- virConnectPtr conn = connect_get(c);
136
- VALUE xml, flags;
137
-
138
- rb_scan_args(argc, argv, "11", &xml, &flags);
139
-
140
- if (NIL_P(flags))
141
- flags = INT2FIX(0);
142
-
143
- nodedev = virNodeDeviceCreateXML(conn, StringValueCStr(xml), NUM2UINT(flags));
144
- _E(nodedev == NULL, create_error(e_Error, "virNodeDeviceCreateXML", "", conn));
145
-
146
- return nodedevice_new(nodedev, c);
147
- }
148
- #endif
149
-
150
43
  /*
151
44
  * call-seq:
152
45
  * nodedevice.name -> string
153
46
  *
154
47
  * Call +virNodeDeviceGetName+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceGetName]
48
+ * to retrieve the name of the node device.
155
49
  */
156
50
  static VALUE libvirt_nodedevice_name(VALUE c) {
157
51
  gen_call_string(virNodeDeviceGetName, conn(c), 0, nodedevice_get(c));
@@ -162,6 +56,7 @@ static VALUE libvirt_nodedevice_name(VALUE c) {
162
56
  * nodedevice.parent -> string
163
57
  *
164
58
  * Call +virNodeDeviceGetParent+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceGetParent]
59
+ * to retrieve the parent of the node device.
165
60
  */
166
61
  static VALUE libvirt_nodedevice_parent(VALUE c) {
167
62
  /* unfortunately we can't use gen_call_string() here because
@@ -183,14 +78,10 @@ static VALUE libvirt_nodedevice_parent(VALUE c) {
183
78
  * nodedevice.num_of_caps -> fixnum
184
79
  *
185
80
  * Call +virNodeDeviceNumOfCaps+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceNumOfCaps]
81
+ * to retrieve the number of capabilities of the node device.
186
82
  */
187
83
  static VALUE libvirt_nodedevice_num_of_caps(VALUE c) {
188
- int result;
189
-
190
- result = virNodeDeviceNumOfCaps(nodedevice_get(c));
191
- _E(result < 0, create_error(e_RetrieveError, "virNodeNumOfDevices", "", connect_get(c)));
192
-
193
- return INT2NUM(result);
84
+ gen_call_int(virNodeDeviceNumOfCaps, conn(c), nodedevice_get(c));
194
85
  }
195
86
 
196
87
  /*
@@ -198,42 +89,37 @@ static VALUE libvirt_nodedevice_num_of_caps(VALUE c) {
198
89
  * nodedevice.list_caps -> list
199
90
  *
200
91
  * Call +virNodeDeviceListCaps+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceListCaps]
92
+ * to retrieve a list of capabilities of the node device.
201
93
  */
202
94
  static VALUE libvirt_nodedevice_list_caps(VALUE c) {
203
- int i, r, num;
95
+ int r, num;
204
96
  virConnectPtr conn = connect_get(c);
205
97
  virNodeDevicePtr nodedev = nodedevice_get(c);
206
- VALUE result;
207
98
  char **names;
208
99
 
209
100
  num = virNodeDeviceNumOfCaps(nodedev);
210
- _E(num < 0, create_error(e_RetrieveError, "virNodeDeviceNumOfCaps", "", conn));
211
- if (num == 0) {
101
+ _E(num < 0, create_error(e_RetrieveError, "virNodeDeviceNumOfCaps", conn));
102
+ if (num == 0)
212
103
  /* if num is 0, don't call virNodeDeviceListCaps function */
213
- result = rb_ary_new2(num);
214
- return result;
215
- }
104
+ return rb_ary_new2(num);
105
+
216
106
  names = ALLOC_N(char *, num);
217
107
  r = virNodeDeviceListCaps(nodedev, names, num);
218
108
  if (r < 0) {
219
- free(names);
220
- _E(r < 0, create_error(e_RetrieveError, "virNodeDeviceListCaps", "", conn));
109
+ xfree(names);
110
+ rb_exc_raise(create_error(e_RetrieveError, "virNodeDeviceListCaps",
111
+ conn));
221
112
  }
222
113
 
223
- result = rb_ary_new2(num);
224
- for (i=0; i<num; i++) {
225
- rb_ary_push(result, rb_str_new2(names[i]));
226
- free(names[i]);
227
- }
228
- free(names);
229
- return result;
114
+ return gen_list(num, &names);
230
115
  }
231
116
 
232
117
  /*
233
118
  * call-seq:
234
- * nodedevice.xml_desc -> string
119
+ * nodedevice.xml_desc(flags=0) -> string
235
120
  *
236
121
  * Call +virNodeDeviceGetXMLDesc+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceGetXMLDesc]
122
+ * to retrieve the XML for the node device.
237
123
  */
238
124
  static VALUE libvirt_nodedevice_xml_desc(int argc, VALUE *argv, VALUE s) {
239
125
  VALUE flags;
@@ -252,6 +138,7 @@ static VALUE libvirt_nodedevice_xml_desc(int argc, VALUE *argv, VALUE s) {
252
138
  * nodedevice.detach -> nil
253
139
  *
254
140
  * Call +virNodeDeviceDettach+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceDettach]
141
+ * to detach the node device from the node.
255
142
  */
256
143
  static VALUE libvirt_nodedevice_detach(VALUE s) {
257
144
  gen_call_void(virNodeDeviceDettach, conn(s), nodedevice_get(s));
@@ -262,6 +149,7 @@ static VALUE libvirt_nodedevice_detach(VALUE s) {
262
149
  * nodedevice.reattach -> nil
263
150
  *
264
151
  * Call +virNodeDeviceReAttach+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceReAttach]
152
+ * to reattach the node device to the node.
265
153
  */
266
154
  static VALUE libvirt_nodedevice_reattach(VALUE s) {
267
155
  gen_call_void(virNodeDeviceReAttach, conn(s), nodedevice_get(s));
@@ -272,6 +160,7 @@ static VALUE libvirt_nodedevice_reattach(VALUE s) {
272
160
  * nodedevice.reset -> nil
273
161
  *
274
162
  * Call +virNodeDeviceReset+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceReset]
163
+ * to reset the node device.
275
164
  */
276
165
  static VALUE libvirt_nodedevice_reset(VALUE s) {
277
166
  gen_call_void(virNodeDeviceReset, conn(s), nodedevice_get(s));
@@ -283,6 +172,7 @@ static VALUE libvirt_nodedevice_reset(VALUE s) {
283
172
  * nodedevice.destroy -> nil
284
173
  *
285
174
  * Call +virNodeDeviceDestroy+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceDestroy]
175
+ * to shutdown the node device.
286
176
  */
287
177
  static VALUE libvirt_nodedevice_destroy(VALUE s) {
288
178
  gen_call_void(virNodeDeviceDestroy, conn(s), nodedevice_get(s));
@@ -294,27 +184,21 @@ static VALUE libvirt_nodedevice_destroy(VALUE s) {
294
184
  * nodedevice.free -> nil
295
185
  *
296
186
  * Call +virNodeDeviceFree+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeDeviceFree]
187
+ * to free the node device object. After this call the node device object is
188
+ * no longer valid.
297
189
  */
298
190
  static VALUE libvirt_nodedevice_free(VALUE s) {
299
191
  gen_call_free(NodeDevice, s);
300
192
  }
193
+ #endif
301
194
 
302
195
  /*
303
196
  * Class Libvirt::NodeDevice
304
197
  */
305
198
  void init_nodedevice()
306
199
  {
200
+ #if HAVE_TYPE_VIRNODEDEVICEPTR
307
201
  c_nodedevice = rb_define_class_under(m_libvirt, "NodeDevice", rb_cObject);
308
- rb_define_method(c_connect, "num_of_nodedevices",
309
- libvirt_conn_num_of_nodedevices, -1);
310
- rb_define_method(c_connect, "list_nodedevices",
311
- libvirt_conn_list_nodedevices, -1);
312
- rb_define_method(c_connect, "lookup_nodedevice_by_name",
313
- libvirt_conn_lookup_nodedevice_by_name, 1);
314
- #if HAVE_VIRNODEDEVICECREATEXML
315
- rb_define_method(c_connect, "create_nodedevice_xml",
316
- libvirt_conn_create_nodedevice_xml, -1);
317
- #endif
318
202
 
319
203
  rb_define_method(c_nodedevice, "name", libvirt_nodedevice_name, 0);
320
204
  rb_define_method(c_nodedevice, "parent", libvirt_nodedevice_parent, 0);
@@ -330,4 +214,5 @@ void init_nodedevice()
330
214
  rb_define_method(c_nodedevice, "destroy", libvirt_nodedevice_destroy, 0);
331
215
  #endif
332
216
  rb_define_method(c_nodedevice, "free", libvirt_nodedevice_free, 0);
217
+ #endif
333
218
  }
@@ -36,83 +36,16 @@ static virNWFilterPtr nwfilter_get(VALUE nw) {
36
36
  generic_get(NWFilter, nw);
37
37
  }
38
38
 
39
- static VALUE nwfilter_new(virNWFilterPtr nw, VALUE conn) {
39
+ VALUE nwfilter_new(virNWFilterPtr nw, VALUE conn) {
40
40
  return generic_new(c_nwfilter, nw, conn, nwfilter_free);
41
41
  }
42
42
 
43
- /*
44
- * call-seq:
45
- * conn.num_of_nwfilters -> fixnum
46
- *
47
- * Call +virConnectNumOfNWFilters+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectNumOfNWFilters]
48
- */
49
- static VALUE libvirt_conn_num_of_nwfilters(VALUE s) {
50
- gen_conn_num_of(s, NWFilters);
51
- }
52
-
53
- /*
54
- * call-seq:
55
- * conn.list_nwfilters -> list
56
- *
57
- * Call +virConnectListNWFilters+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectListNWFilters]
58
- */
59
- static VALUE libvirt_conn_list_nwfilters(VALUE s) {
60
- gen_conn_list_names(s, NWFilters);
61
- }
62
-
63
- /*
64
- * call-seq:
65
- * conn.lookup_nwfilter_by_name -> Libvirt::NWFilter
66
- *
67
- * Call +virNWFilterLookupByName+[http://www.libvirt.org/html/libvirt-libvirt.html#virNWFilterLookupByName]
68
- */
69
- static VALUE libvirt_conn_lookup_nwfilter_by_name(VALUE c, VALUE name) {
70
- virNWFilterPtr nwfilter;
71
- virConnectPtr conn = connect_get(c);
72
-
73
- nwfilter = virNWFilterLookupByName(conn, StringValueCStr(name));
74
- _E(nwfilter == NULL, create_error(e_RetrieveError, "virNWFilterLookupByName", "", conn));
75
-
76
- return nwfilter_new(nwfilter, c);
77
- }
78
-
79
- /*
80
- * call-seq:
81
- * conn.lookup_nwfilter_by_uuid -> Libvirt::NWFilter
82
- *
83
- * Call +virNWFilterLookupByUUIDString+[http://www.libvirt.org/html/libvirt-libvirt.html#virNWFilterLookupByUUIDString]
84
- */
85
- static VALUE libvirt_conn_lookup_nwfilter_by_uuid(VALUE c, VALUE uuid) {
86
- virNWFilterPtr nwfilter;
87
- virConnectPtr conn = connect_get(c);
88
-
89
- nwfilter = virNWFilterLookupByUUIDString(conn, StringValueCStr(uuid));
90
- _E(nwfilter == NULL, create_error(e_RetrieveError, "virNWFilterLookupByUUIDString", "", conn));
91
-
92
- return nwfilter_new(nwfilter, c);
93
- }
94
-
95
- /*
96
- * call-seq:
97
- * conn.define_nwfilter_xml -> Libvirt::NWFilter
98
- *
99
- * Call +virNWFilterDefineXML+[http://www.libvirt.org/html/libvirt-libvirt.html#virNWFilterDefineXML]
100
- */
101
- static VALUE libvirt_conn_define_nwfilter_xml(VALUE c, VALUE xml) {
102
- virNWFilterPtr nwfilter;
103
- virConnectPtr conn = connect_get(c);
104
-
105
- nwfilter = virNWFilterDefineXML(conn, StringValueCStr(xml));
106
- _E(nwfilter == NULL, create_error(e_DefinitionError, "virNWFilterDefineXML", "", conn));
107
-
108
- return nwfilter_new(nwfilter, c);
109
- }
110
-
111
43
  /*
112
44
  * call-seq:
113
45
  * nwfilter.undefine -> nil
114
46
  *
115
47
  * Call +virNWFilterUndefine+[http://www.libvirt.org/html/libvirt-libvirt.html#virNWFilterUndefine]
48
+ * to undefine the network filter.
116
49
  */
117
50
  static VALUE libvirt_nwfilter_undefine(VALUE s) {
118
51
  gen_call_void(virNWFilterUndefine, conn(s), nwfilter_get(s));
@@ -123,6 +56,7 @@ static VALUE libvirt_nwfilter_undefine(VALUE s) {
123
56
  * nwfilter.name -> string
124
57
  *
125
58
  * Call +virNWFilterGetName+[http://www.libvirt.org/html/libvirt-libvirt.html#virNWFilterGetName]
59
+ * to retrieve the network filter name.
126
60
  */
127
61
  static VALUE libvirt_nwfilter_name(VALUE s) {
128
62
  gen_call_string(virNWFilterGetName, conn(s), 0, nwfilter_get(s));
@@ -133,6 +67,7 @@ static VALUE libvirt_nwfilter_name(VALUE s) {
133
67
  * nwfilter.uuid -> string
134
68
  *
135
69
  * Call +virNWFilterGetUUIDString+[http://www.libvirt.org/html/libvirt-libvirt.html#virNWFilterGetUUIDString]
70
+ * to retrieve the network filter UUID.
136
71
  */
137
72
  static VALUE libvirt_nwfilter_uuid(VALUE s) {
138
73
  virNWFilterPtr nwfilter = nwfilter_get(s);
@@ -140,16 +75,18 @@ static VALUE libvirt_nwfilter_uuid(VALUE s) {
140
75
  char uuid[VIR_UUID_STRING_BUFLEN];
141
76
 
142
77
  r = virNWFilterGetUUIDString(nwfilter, uuid);
143
- _E(r < 0, create_error(e_RetrieveError, "virNWFilterGetUUIDString", "", conn(s)));
78
+ _E(r < 0, create_error(e_RetrieveError, "virNWFilterGetUUIDString",
79
+ conn(s)));
144
80
 
145
81
  return rb_str_new2((char *)uuid);
146
82
  }
147
83
 
148
84
  /*
149
85
  * call-seq:
150
- * nwfilter.xml_desc -> string
86
+ * nwfilter.xml_desc(flags=0) -> string
151
87
  *
152
88
  * Call +virNWFilterGetXMLDesc+[http://www.libvirt.org/html/libvirt-libvirt.html#virNWFilterGetXMLDesc]
89
+ * to retrieve the XML for this network filter.
153
90
  */
154
91
  static VALUE libvirt_nwfilter_xml_desc(int argc, VALUE *argv, VALUE s) {
155
92
  VALUE flags;
@@ -168,6 +105,8 @@ static VALUE libvirt_nwfilter_xml_desc(int argc, VALUE *argv, VALUE s) {
168
105
  * nwfilter.free -> nil
169
106
  *
170
107
  * Call +virNWFilterFree+[http://www.libvirt.org/html/libvirt-libvirt.html#virNWFilterFree]
108
+ * to free this network filter. After this call the network filter object is
109
+ * no longer valid.
171
110
  */
172
111
  static VALUE libvirt_nwfilter_free(VALUE s) {
173
112
  gen_call_free(NWFilter, s);
@@ -184,18 +123,6 @@ void init_nwfilter()
184
123
  c_nwfilter = rb_define_class_under(m_libvirt, "NWFilter", rb_cObject);
185
124
  rb_define_attr(c_nwfilter, "connection", 1, 0);
186
125
 
187
- /* NWFilter lookup/creation methods */
188
- rb_define_method(c_connect, "num_of_nwfilters",
189
- libvirt_conn_num_of_nwfilters, 0);
190
- rb_define_method(c_connect, "list_nwfilters",
191
- libvirt_conn_list_nwfilters, 0);
192
- rb_define_method(c_connect, "lookup_nwfilter_by_name",
193
- libvirt_conn_lookup_nwfilter_by_name, 1);
194
- rb_define_method(c_connect, "lookup_nwfilter_by_uuid",
195
- libvirt_conn_lookup_nwfilter_by_uuid, 1);
196
- rb_define_method(c_connect, "define_nwfilter_xml",
197
- libvirt_conn_define_nwfilter_xml, 1);
198
-
199
126
  /* NWFilter object methods */
200
127
  rb_define_method(c_nwfilter, "undefine", libvirt_nwfilter_undefine, 0);
201
128
  rb_define_method(c_nwfilter, "name", libvirt_nwfilter_name, 0);
@@ -36,92 +36,16 @@ static virSecretPtr secret_get(VALUE s) {
36
36
  generic_get(Secret, s);
37
37
  }
38
38
 
39
- static VALUE secret_new(virSecretPtr s, VALUE conn) {
39
+ VALUE secret_new(virSecretPtr s, VALUE conn) {
40
40
  return generic_new(c_secret, s, conn, secret_free);
41
41
  }
42
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
43
  /*
121
44
  * call-seq:
122
45
  * secret.uuid -> string
123
46
  *
124
47
  * Call +virSecretGetUUIDString+[http://www.libvirt.org/html/libvirt-libvirt.html#virSecretGetUUIDString]
48
+ * to retrieve the UUID for this secret.
125
49
  */
126
50
  static VALUE libvirt_secret_uuid(VALUE s) {
127
51
  virSecretPtr secret = secret_get(s);
@@ -129,7 +53,7 @@ static VALUE libvirt_secret_uuid(VALUE s) {
129
53
  char uuid[VIR_UUID_STRING_BUFLEN];
130
54
 
131
55
  r = virSecretGetUUIDString(secret, uuid);
132
- _E(r < 0, create_error(e_RetrieveError, "virSecretGetUUIDString", "", conn(s)));
56
+ _E(r < 0, create_error(e_RetrieveError, "virSecretGetUUIDString", conn(s)));
133
57
 
134
58
  return rb_str_new2((char *)uuid);
135
59
  }
@@ -139,15 +63,10 @@ static VALUE libvirt_secret_uuid(VALUE s) {
139
63
  * secret.usagetype -> fixnum
140
64
  *
141
65
  * Call +virSecretGetUsageType+[http://www.libvirt.org/html/libvirt-libvirt.html#virSecretGetUsageType]
66
+ * to retrieve the usagetype for this secret.
142
67
  */
143
68
  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);
69
+ gen_call_int(virSecretGetUsageType, conn(s), secret_get(s));
151
70
  }
152
71
 
153
72
  /*
@@ -155,6 +74,7 @@ static VALUE libvirt_secret_usagetype(VALUE s) {
155
74
  * secret.usageid -> string
156
75
  *
157
76
  * Call +virSecretGetUsageID+[http://www.libvirt.org/html/libvirt-libvirt.html#virSecretGetUsageID]
77
+ * to retrieve the usageid for this secret.
158
78
  */
159
79
  static VALUE libvirt_secret_usageid(VALUE s) {
160
80
  gen_call_string(virSecretGetUsageID, conn(s), 0, secret_get(s));
@@ -162,9 +82,10 @@ static VALUE libvirt_secret_usageid(VALUE s) {
162
82
 
163
83
  /*
164
84
  * call-seq:
165
- * secret.xml_desc -> string
85
+ * secret.xml_desc(flags=0) -> string
166
86
  *
167
87
  * Call +virSecretGetXMLDesc+[http://www.libvirt.org/html/libvirt-libvirt.html#virSecretGetXMLDesc]
88
+ * to retrieve the XML for this secret.
168
89
  */
169
90
  static VALUE libvirt_secret_xml_desc(int argc, VALUE *argv, VALUE s) {
170
91
  VALUE flags;
@@ -180,15 +101,14 @@ static VALUE libvirt_secret_xml_desc(int argc, VALUE *argv, VALUE s) {
180
101
 
181
102
  /*
182
103
  * call-seq:
183
- * secret.set_value -> nil
104
+ * secret.set_value(value, flags=0) -> nil
184
105
  *
185
106
  * Call +virSecretSetValue+[http://www.libvirt.org/html/libvirt-libvirt.html#virSecretSetValue]
107
+ * to set a new value in this secret.
186
108
  */
187
109
  static VALUE libvirt_secret_set_value(int argc, VALUE *argv, VALUE s) {
188
- virSecretPtr secret = secret_get(s);
189
110
  VALUE flags;
190
111
  VALUE value;
191
- int r;
192
112
 
193
113
  rb_scan_args(argc, argv, "11", &value, &flags);
194
114
 
@@ -197,36 +117,48 @@ static VALUE libvirt_secret_set_value(int argc, VALUE *argv, VALUE s) {
197
117
 
198
118
  StringValue(value);
199
119
 
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;
120
+ gen_call_void(virSecretSetValue, conn(s), secret_get(s),
121
+ (unsigned char *)RSTRING_PTR(value), RSTRING_LEN(value),
122
+ NUM2UINT(flags));
206
123
  }
207
124
 
208
125
  /*
209
126
  * call-seq:
210
- * secret.get_value -> string
127
+ * secret.get_value(flags=0) -> string
211
128
  *
212
129
  * Call +virSecretGetValue+[http://www.libvirt.org/html/libvirt-libvirt.html#virSecretGetValue]
130
+ * to retrieve the value from this secret.
213
131
  */
214
132
  static VALUE libvirt_secret_get_value(int argc, VALUE *argv, VALUE s) {
215
133
  virSecretPtr secret = secret_get(s);
216
134
  VALUE flags;
217
- unsigned char *ret;
135
+ unsigned char *val;
218
136
  size_t value_size;
137
+ VALUE ret;
138
+ int exception = 0;
139
+ struct rb_str_new_arg args;
219
140
 
220
141
  rb_scan_args(argc, argv, "01", &flags);
221
142
 
222
143
  if (NIL_P(flags))
223
144
  flags = INT2FIX(0);
224
145
 
225
- ret = virSecretGetValue(secret, &value_size, NUM2UINT(flags));
146
+ val = virSecretGetValue(secret, &value_size, NUM2UINT(flags));
226
147
 
227
- _E(ret == NULL, create_error(e_RetrieveError, "virSecretGetValue", "", conn(s)));
148
+ _E(val == NULL, create_error(e_RetrieveError, "virSecretGetValue",
149
+ conn(s)));
228
150
 
229
- return rb_str_new((char *)ret, value_size);
151
+ args.val = (char *)val;
152
+ args.size = value_size;
153
+ ret = rb_protect(rb_str_new_wrap, (VALUE)&args, &exception);
154
+ if (exception) {
155
+ free(val);
156
+ rb_jump_tag(exception);
157
+ }
158
+
159
+ free(val);
160
+
161
+ return ret;
230
162
  }
231
163
 
232
164
  /*
@@ -234,6 +166,7 @@ static VALUE libvirt_secret_get_value(int argc, VALUE *argv, VALUE s) {
234
166
  * secret.undefine -> nil
235
167
  *
236
168
  * Call +virSecretUndefine+[http://www.libvirt.org/html/libvirt-libvirt.html#virSecretUndefine]
169
+ * to undefine this secret.
237
170
  */
238
171
  static VALUE libvirt_secret_undefine(VALUE s) {
239
172
  gen_call_void(virSecretUndefine, conn(s), secret_get(s));
@@ -244,6 +177,7 @@ static VALUE libvirt_secret_undefine(VALUE s) {
244
177
  * secret.free -> nil
245
178
  *
246
179
  * Call +virSecretFree+[http://www.libvirt.org/html/libvirt-libvirt.html#virSecretFree]
180
+ * to free this secret. After this call the secret object is no longer valid.
247
181
  */
248
182
  static VALUE libvirt_secret_free(VALUE s) {
249
183
  gen_call_free(Secret, s);
@@ -263,18 +197,6 @@ void init_secret()
263
197
  INT2NUM(VIR_SECRET_USAGE_TYPE_VOLUME));
264
198
  rb_define_attr(c_secret, "connection", 1, 0);
265
199
 
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
200
  /* Secret object methods */
279
201
  rb_define_method(c_secret, "uuid", libvirt_secret_uuid, 0);
280
202
  rb_define_method(c_secret, "usagetype", libvirt_secret_usagetype, 0);