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,75 @@
|
|
1
|
+
/*
|
2
|
+
* common.c: Common utilities for the ruby libvirt bindings
|
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
|
+
|
25
|
+
/* Error handling */
|
26
|
+
VALUE create_error(VALUE error, const char* method, const char* msg,
|
27
|
+
virConnectPtr conn) {
|
28
|
+
VALUE ruby_errinfo;
|
29
|
+
virErrorPtr err;
|
30
|
+
|
31
|
+
if (msg == NULL || strlen(msg) == 0) {
|
32
|
+
char *defmsg;
|
33
|
+
size_t len;
|
34
|
+
len = snprintf(NULL, 0, "Call to function %s failed", method) + 1;
|
35
|
+
defmsg = ALLOC_N(char, len);
|
36
|
+
snprintf(defmsg, len, "Call to function %s failed", method);
|
37
|
+
ruby_errinfo = rb_exc_new2(error, defmsg);
|
38
|
+
free(defmsg);
|
39
|
+
} else {
|
40
|
+
ruby_errinfo = rb_exc_new2(error, msg);
|
41
|
+
}
|
42
|
+
rb_iv_set(ruby_errinfo, "@libvirt_function_name", rb_str_new2(method));
|
43
|
+
|
44
|
+
if (conn == NULL)
|
45
|
+
err = virGetLastError();
|
46
|
+
else
|
47
|
+
err = virConnGetLastError(conn);
|
48
|
+
|
49
|
+
if (err != NULL) {
|
50
|
+
rb_iv_set(ruby_errinfo, "@libvirt_code", INT2FIX(err->code));
|
51
|
+
if (err->message != NULL)
|
52
|
+
rb_iv_set(ruby_errinfo, "@libvirt_message", rb_str_new2(err->message));
|
53
|
+
}
|
54
|
+
|
55
|
+
return ruby_errinfo;
|
56
|
+
};
|
57
|
+
|
58
|
+
char *get_string_or_nil(VALUE arg)
|
59
|
+
{
|
60
|
+
if (TYPE(arg) == T_NIL)
|
61
|
+
return NULL;
|
62
|
+
else if (TYPE(arg) == T_STRING)
|
63
|
+
return StringValueCStr(arg);
|
64
|
+
else
|
65
|
+
rb_raise(rb_eTypeError, "wrong argument type (expected String or nil)"); return NULL;
|
66
|
+
}
|
67
|
+
|
68
|
+
VALUE generic_new(VALUE klass, void *ptr, VALUE conn,
|
69
|
+
RUBY_DATA_FUNC free_func) {
|
70
|
+
VALUE result;
|
71
|
+
result = Data_Wrap_Struct(klass, NULL, free_func, ptr);
|
72
|
+
rb_iv_set(result, "@connection", conn);
|
73
|
+
return result;
|
74
|
+
}
|
75
|
+
|
@@ -0,0 +1,155 @@
|
|
1
|
+
#ifndef COMMON_H
|
2
|
+
#define COMMON_H
|
3
|
+
|
4
|
+
/* Macros to ease some of the boilerplate */
|
5
|
+
VALUE generic_new(VALUE klass, void *ptr, VALUE conn,
|
6
|
+
RUBY_DATA_FUNC free_func);
|
7
|
+
|
8
|
+
#define generic_get(kind, v) \
|
9
|
+
do { \
|
10
|
+
vir##kind##Ptr ptr; \
|
11
|
+
Data_Get_Struct(v, vir##kind, ptr); \
|
12
|
+
if (!ptr) \
|
13
|
+
rb_raise(rb_eArgError, #kind " has been freed"); \
|
14
|
+
return ptr; \
|
15
|
+
} while (0);
|
16
|
+
|
17
|
+
#define generic_free(kind, p) \
|
18
|
+
do { \
|
19
|
+
int r; \
|
20
|
+
r = vir##kind##Free((vir##kind##Ptr) p); \
|
21
|
+
if (r < 0) \
|
22
|
+
rb_raise(rb_eSystemCallError, # kind " free failed"); \
|
23
|
+
} while(0);
|
24
|
+
|
25
|
+
VALUE create_error(VALUE error, const char* method, const char* msg,
|
26
|
+
virConnectPtr conn);
|
27
|
+
|
28
|
+
/*
|
29
|
+
* Code generating macros.
|
30
|
+
*
|
31
|
+
* We only generate function bodies, not the whole function
|
32
|
+
* declaration.
|
33
|
+
*/
|
34
|
+
|
35
|
+
/* Generate a call to a function FUNC which returns a string. The Ruby
|
36
|
+
* function will return the string on success and throw an exception on
|
37
|
+
* error. The string returned by FUNC is freed if dealloc is true.
|
38
|
+
*/
|
39
|
+
#define gen_call_string(func, conn, dealloc, args...) \
|
40
|
+
do { \
|
41
|
+
const char *str; \
|
42
|
+
VALUE result; \
|
43
|
+
\
|
44
|
+
str = func(args); \
|
45
|
+
_E(str == NULL, create_error(e_Error, # func, "", conn)); \
|
46
|
+
\
|
47
|
+
result = rb_str_new2(str); \
|
48
|
+
if (dealloc) \
|
49
|
+
free((void *) str); \
|
50
|
+
return result; \
|
51
|
+
} while(0)
|
52
|
+
|
53
|
+
/* Generate a call to vir##KIND##Free and return Qnil. Set the the embedded
|
54
|
+
* vir##KIND##Ptr to NULL. If that pointer is already NULL, do nothing.
|
55
|
+
*/
|
56
|
+
#define gen_call_free(kind, s) \
|
57
|
+
do { \
|
58
|
+
vir##kind##Ptr ptr; \
|
59
|
+
Data_Get_Struct(s, vir##kind, ptr); \
|
60
|
+
if (ptr != NULL) { \
|
61
|
+
int r = vir##kind##Free(ptr); \
|
62
|
+
_E(r < 0, create_error(e_Error, "vir" #kind "Free", "", conn(s))); \
|
63
|
+
DATA_PTR(s) = NULL; \
|
64
|
+
} \
|
65
|
+
return Qnil; \
|
66
|
+
} while (0)
|
67
|
+
|
68
|
+
/* Generate a call to a function FUNC which returns an int error, where -1
|
69
|
+
* indicates error and 0 success. The Ruby function will return Qnil on
|
70
|
+
* success and throw an exception on error.
|
71
|
+
*/
|
72
|
+
#define gen_call_void(func, conn, args...) \
|
73
|
+
do { \
|
74
|
+
int _r_##func; \
|
75
|
+
_r_##func = func(args); \
|
76
|
+
_E(_r_##func < 0, create_error(e_Error, #func, "", conn)); \
|
77
|
+
return Qnil; \
|
78
|
+
} while(0)
|
79
|
+
|
80
|
+
/*
|
81
|
+
* Generate a call to a virConnectNumOf... function. C is the Ruby VALUE
|
82
|
+
* holding the connection and OBJS is a token indicating what objects to
|
83
|
+
* get the number of, e.g. 'Domains'
|
84
|
+
*/
|
85
|
+
#define gen_conn_num_of(c, objs) \
|
86
|
+
do { \
|
87
|
+
int result; \
|
88
|
+
virConnectPtr conn = connect_get(c); \
|
89
|
+
\
|
90
|
+
result = virConnectNumOf##objs(conn); \
|
91
|
+
_E(result < 0, create_error(e_RetrieveError, "virConnectNumOf" # objs, "", conn)); \
|
92
|
+
\
|
93
|
+
return INT2NUM(result); \
|
94
|
+
} while(0)
|
95
|
+
|
96
|
+
/*
|
97
|
+
* Generate a call to a virConnectList... function. S is the Ruby VALUE
|
98
|
+
* holding the connection and OBJS is a token indicating what objects to
|
99
|
+
* get the number of, e.g. 'Domains' The list function must return an array
|
100
|
+
* of strings, which is returned as a Ruby array
|
101
|
+
*/
|
102
|
+
#define gen_conn_list_names(s, objs) \
|
103
|
+
do { \
|
104
|
+
int i, r, num; \
|
105
|
+
char **names; \
|
106
|
+
virConnectPtr conn = connect_get(s); \
|
107
|
+
VALUE result; \
|
108
|
+
\
|
109
|
+
num = virConnectNumOf##objs(conn); \
|
110
|
+
_E(num < 0, create_error(e_RetrieveError, "virConnectNumOf" # objs, "", conn)); \
|
111
|
+
if (num == 0) { \
|
112
|
+
/* if num is 0, don't call virConnectList* function */ \
|
113
|
+
result = rb_ary_new2(num); \
|
114
|
+
return result; \
|
115
|
+
} \
|
116
|
+
names = ALLOC_N(char *, num); \
|
117
|
+
r = virConnectList##objs(conn, names, num); \
|
118
|
+
if (r < 0) { \
|
119
|
+
free(names); \
|
120
|
+
_E(r < 0, create_error(e_RetrieveError, "virConnectList" # objs, "", conn)); \
|
121
|
+
} \
|
122
|
+
\
|
123
|
+
result = rb_ary_new2(num); \
|
124
|
+
for (i=0; i<num; i++) { \
|
125
|
+
rb_ary_push(result, rb_str_new2(names[i])); \
|
126
|
+
free(names[i]); \
|
127
|
+
} \
|
128
|
+
free(names); \
|
129
|
+
return result; \
|
130
|
+
} while(0)
|
131
|
+
|
132
|
+
/* Generate a call to a function FUNC which returns an int; -1 indicates
|
133
|
+
* error, 0 indicates Qfalse, and 1 indicates Qtrue.
|
134
|
+
*/
|
135
|
+
#define gen_call_truefalse(func, conn, args...) \
|
136
|
+
do { \
|
137
|
+
int _r_##func; \
|
138
|
+
_r_##func = func(args); \
|
139
|
+
_E(_r_##func < 0, create_error(e_Error, #func, "", conn)); \
|
140
|
+
return _r_##func ? Qtrue : Qfalse; \
|
141
|
+
} while(0)
|
142
|
+
|
143
|
+
/* Error handling */
|
144
|
+
#define _E(cond, excep) \
|
145
|
+
do { if (cond) rb_exc_raise(excep); } while(0)
|
146
|
+
|
147
|
+
extern VALUE e_RetrieveError;
|
148
|
+
extern VALUE e_Error;
|
149
|
+
extern VALUE e_DefinitionError;
|
150
|
+
|
151
|
+
extern VALUE m_libvirt;
|
152
|
+
|
153
|
+
char *get_string_or_nil(VALUE arg);
|
154
|
+
|
155
|
+
#endif
|
@@ -0,0 +1,392 @@
|
|
1
|
+
/*
|
2
|
+
* connect.c: virConnect 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 "extconf.h"
|
25
|
+
#include "common.h"
|
26
|
+
|
27
|
+
VALUE c_connect;
|
28
|
+
static VALUE c_node_security_model;
|
29
|
+
static VALUE c_node_info;
|
30
|
+
|
31
|
+
static void connect_close(void *p) {
|
32
|
+
int r;
|
33
|
+
|
34
|
+
if (!p)
|
35
|
+
return;
|
36
|
+
r = virConnectClose((virConnectPtr) p);
|
37
|
+
_E(r < 0, create_error(rb_eSystemCallError, "virConnectClose",
|
38
|
+
"Connection close failed", p));
|
39
|
+
}
|
40
|
+
|
41
|
+
VALUE connect_new(virConnectPtr p) {
|
42
|
+
return Data_Wrap_Struct(c_connect, NULL, connect_close, p);
|
43
|
+
}
|
44
|
+
|
45
|
+
virConnectPtr connect_get(VALUE s) {
|
46
|
+
generic_get(Connect, s);
|
47
|
+
}
|
48
|
+
|
49
|
+
VALUE conn_attr(VALUE s) {
|
50
|
+
if (rb_obj_is_instance_of(s, c_connect) != Qtrue) {
|
51
|
+
s = rb_iv_get(s, "@connection");
|
52
|
+
}
|
53
|
+
if (rb_obj_is_instance_of(s, c_connect) != Qtrue) {
|
54
|
+
rb_raise(rb_eArgError, "Expected Connection object");
|
55
|
+
}
|
56
|
+
return s;
|
57
|
+
}
|
58
|
+
|
59
|
+
virConnectPtr conn(VALUE s) {
|
60
|
+
virConnectPtr conn;
|
61
|
+
|
62
|
+
s = conn_attr(s);
|
63
|
+
Data_Get_Struct(s, virConnect, conn);
|
64
|
+
if (!conn)
|
65
|
+
rb_raise(rb_eArgError, "Connection has been closed");
|
66
|
+
return conn;
|
67
|
+
}
|
68
|
+
|
69
|
+
/*
|
70
|
+
* call-seq:
|
71
|
+
* conn.close -> nil
|
72
|
+
*
|
73
|
+
* Close the connection
|
74
|
+
*/
|
75
|
+
static VALUE libvirt_conn_close(VALUE s) {
|
76
|
+
virConnectPtr conn;
|
77
|
+
Data_Get_Struct(s, virConnect, conn);
|
78
|
+
if (conn) {
|
79
|
+
connect_close(conn);
|
80
|
+
DATA_PTR(s) = NULL;
|
81
|
+
}
|
82
|
+
return Qnil;
|
83
|
+
}
|
84
|
+
|
85
|
+
/*
|
86
|
+
* call-seq:
|
87
|
+
* conn.closed? -> [True|False]
|
88
|
+
*
|
89
|
+
* Return +true+ if the connection is closed, +false+ if it is open
|
90
|
+
*/
|
91
|
+
static VALUE libvirt_conn_closed_p(VALUE s) {
|
92
|
+
virConnectPtr conn;
|
93
|
+
|
94
|
+
Data_Get_Struct(s, virConnect, conn);
|
95
|
+
return (conn==NULL) ? Qtrue : Qfalse;
|
96
|
+
}
|
97
|
+
|
98
|
+
/*
|
99
|
+
* call-seq:
|
100
|
+
* conn.type -> string
|
101
|
+
*
|
102
|
+
* Call +virConnectGetType+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectGetType]
|
103
|
+
*/
|
104
|
+
static VALUE libvirt_conn_type(VALUE s) {
|
105
|
+
gen_call_string(virConnectGetType, conn(s), 0, connect_get(s));
|
106
|
+
}
|
107
|
+
|
108
|
+
/*
|
109
|
+
* call-seq:
|
110
|
+
* conn.version -> fixnum
|
111
|
+
*
|
112
|
+
* Call +virConnectGetVersion+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectGetVersion]
|
113
|
+
*/
|
114
|
+
static VALUE libvirt_conn_version(VALUE s) {
|
115
|
+
int r;
|
116
|
+
unsigned long v;
|
117
|
+
virConnectPtr conn = connect_get(s);
|
118
|
+
|
119
|
+
r = virConnectGetVersion(conn, &v);
|
120
|
+
_E(r < 0, create_error(e_RetrieveError, "virConnectGetVersion", "", conn));
|
121
|
+
|
122
|
+
return ULONG2NUM(v);
|
123
|
+
}
|
124
|
+
|
125
|
+
#if HAVE_VIRCONNECTGETLIBVERSION
|
126
|
+
/*
|
127
|
+
* call-seq:
|
128
|
+
* conn.libversion -> fixnum
|
129
|
+
*
|
130
|
+
* Call +virConnectGetLibVersion+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectGetLibVersion]
|
131
|
+
*/
|
132
|
+
static VALUE libvirt_conn_libversion(VALUE s) {
|
133
|
+
int r;
|
134
|
+
unsigned long v;
|
135
|
+
virConnectPtr conn = connect_get(s);
|
136
|
+
|
137
|
+
r = virConnectGetLibVersion(conn, &v);
|
138
|
+
_E(r < 0, create_error(e_RetrieveError, "virConnectGetLibVersion",
|
139
|
+
"", conn));
|
140
|
+
|
141
|
+
return ULONG2NUM(v);
|
142
|
+
}
|
143
|
+
#endif
|
144
|
+
|
145
|
+
/*
|
146
|
+
* call-seq:
|
147
|
+
* conn.hostname -> string
|
148
|
+
*
|
149
|
+
* Call +virConnectGetHostname+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectGetHostname]
|
150
|
+
*/
|
151
|
+
static VALUE libvirt_conn_hostname(VALUE s) {
|
152
|
+
gen_call_string(virConnectGetHostname, conn(s), 1, connect_get(s));
|
153
|
+
}
|
154
|
+
|
155
|
+
/*
|
156
|
+
* call-seq:
|
157
|
+
* conn.uri -> string
|
158
|
+
*
|
159
|
+
* Call +virConnectGetURI+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectGetURI]
|
160
|
+
*/
|
161
|
+
static VALUE libvirt_conn_uri(VALUE s) {
|
162
|
+
gen_call_string(virConnectGetURI, conn(s), 1, connect_get(s));
|
163
|
+
}
|
164
|
+
|
165
|
+
/*
|
166
|
+
* call-seq:
|
167
|
+
* conn.max_vcpus -> fixnum
|
168
|
+
*
|
169
|
+
* Call +virConnectGetMaxVcpus+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectGetMaxVcpus]
|
170
|
+
*/
|
171
|
+
static VALUE libvirt_conn_max_vcpus(int argc, VALUE *argv, VALUE s) {
|
172
|
+
int result;
|
173
|
+
virConnectPtr conn = connect_get(s);
|
174
|
+
VALUE type;
|
175
|
+
|
176
|
+
rb_scan_args(argc, argv, "01", &type);
|
177
|
+
|
178
|
+
result = virConnectGetMaxVcpus(conn, get_string_or_nil(type));
|
179
|
+
_E(result < 0, create_error(e_RetrieveError, "virConnectGetMaxVcpus",
|
180
|
+
"", conn));
|
181
|
+
|
182
|
+
return INT2NUM(result);
|
183
|
+
}
|
184
|
+
|
185
|
+
/*
|
186
|
+
* call-seq:
|
187
|
+
* conn.node_get_info -> Libvirt::Connect::Nodeinfo
|
188
|
+
*
|
189
|
+
* Call +virNodeGetInfo+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeGetInfo]
|
190
|
+
*/
|
191
|
+
static VALUE libvirt_conn_node_get_info(VALUE s) {
|
192
|
+
int r;
|
193
|
+
virConnectPtr conn = connect_get(s);
|
194
|
+
virNodeInfo nodeinfo;
|
195
|
+
VALUE result;
|
196
|
+
|
197
|
+
r = virNodeGetInfo(conn, &nodeinfo);
|
198
|
+
_E(r < 0, create_error(e_RetrieveError, "virNodeGetInfo", "", conn));
|
199
|
+
|
200
|
+
result = rb_class_new_instance(0, NULL, c_node_info);
|
201
|
+
rb_iv_set(result, "@model", rb_str_new2(nodeinfo.model));
|
202
|
+
rb_iv_set(result, "@memory", ULONG2NUM(nodeinfo.memory));
|
203
|
+
rb_iv_set(result, "@cpus", UINT2NUM(nodeinfo.cpus));
|
204
|
+
rb_iv_set(result, "@mhz", UINT2NUM(nodeinfo.mhz));
|
205
|
+
rb_iv_set(result, "@nodes", UINT2NUM(nodeinfo.nodes));
|
206
|
+
rb_iv_set(result, "@sockets", UINT2NUM(nodeinfo.sockets));
|
207
|
+
rb_iv_set(result, "@cores", UINT2NUM(nodeinfo.cores));
|
208
|
+
rb_iv_set(result, "@threads", UINT2NUM(nodeinfo.threads));
|
209
|
+
|
210
|
+
return result;
|
211
|
+
}
|
212
|
+
|
213
|
+
/*
|
214
|
+
* call-seq:
|
215
|
+
* conn.node_free_memory -> fixnum
|
216
|
+
*
|
217
|
+
* Call +virNodeGetFreeMemory+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeGetFreeMemory]
|
218
|
+
*/
|
219
|
+
static VALUE libvirt_conn_node_free_memory(VALUE s) {
|
220
|
+
virConnectPtr conn = connect_get(s);
|
221
|
+
unsigned long long freemem;
|
222
|
+
|
223
|
+
freemem = virNodeGetFreeMemory(conn);
|
224
|
+
_E(freemem == 0, create_error(e_RetrieveError, "virNodeGetFreeMemory",
|
225
|
+
"", conn));
|
226
|
+
|
227
|
+
return ULL2NUM(freemem);
|
228
|
+
}
|
229
|
+
|
230
|
+
/*
|
231
|
+
* call-seq:
|
232
|
+
* conn.node_cells_free_memory -> list
|
233
|
+
*
|
234
|
+
* Call +virNodeGetCellsFreeMemory+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeGetCellsFreeMemory]
|
235
|
+
*/
|
236
|
+
static VALUE libvirt_conn_node_cells_free_memory(int argc, VALUE *argv, VALUE s) {
|
237
|
+
int r;
|
238
|
+
virConnectPtr conn = connect_get(s);
|
239
|
+
VALUE cells;
|
240
|
+
VALUE startCell, maxCells;
|
241
|
+
unsigned long long *freeMems;
|
242
|
+
virNodeInfo nodeinfo;
|
243
|
+
int i;
|
244
|
+
|
245
|
+
rb_scan_args(argc, argv, "02", &startCell, &maxCells);
|
246
|
+
|
247
|
+
if (NIL_P(startCell))
|
248
|
+
startCell = INT2FIX(0);
|
249
|
+
if (NIL_P(maxCells)) {
|
250
|
+
r = virNodeGetInfo(conn, &nodeinfo);
|
251
|
+
_E(r < 0, create_error(e_RetrieveError, "virNodeGetInfo", "", conn));
|
252
|
+
freeMems = ALLOC_N(unsigned long long, nodeinfo.nodes);
|
253
|
+
maxCells = INT2FIX(nodeinfo.nodes);
|
254
|
+
}
|
255
|
+
else
|
256
|
+
freeMems = ALLOC_N(unsigned long long, NUM2UINT(maxCells));
|
257
|
+
|
258
|
+
r = virNodeGetCellsFreeMemory(conn, freeMems, NUM2INT(startCell),
|
259
|
+
NUM2INT(maxCells));
|
260
|
+
_E(r < 0, create_error(e_RetrieveError, "virNodeGetCellsFreeMemory", "", conn));
|
261
|
+
|
262
|
+
cells = rb_ary_new2(r);
|
263
|
+
for (i = 0; i < r; i++)
|
264
|
+
rb_ary_push(cells, ULL2NUM(freeMems[i]));
|
265
|
+
free(freeMems);
|
266
|
+
|
267
|
+
return cells;
|
268
|
+
}
|
269
|
+
|
270
|
+
/*
|
271
|
+
* call-seq:
|
272
|
+
* conn.node_get_security_model -> Libvirt::Connect::NodeSecurityModel
|
273
|
+
*
|
274
|
+
* Call +virNodeGetSecurityInfo+[http://www.libvirt.org/html/libvirt-libvirt.html#virNodeGetSecurityInfo]
|
275
|
+
*/
|
276
|
+
static VALUE libvirt_conn_node_get_security_model(VALUE s) {
|
277
|
+
virSecurityModel secmodel;
|
278
|
+
virConnectPtr conn = connect_get(s);
|
279
|
+
int r;
|
280
|
+
VALUE result;
|
281
|
+
|
282
|
+
r = virNodeGetSecurityModel(conn, &secmodel);
|
283
|
+
_E(r < 0, create_error(e_RetrieveError, "virNodeGetSecurityModel", "", conn));
|
284
|
+
|
285
|
+
result = rb_class_new_instance(0, NULL, c_node_security_model);
|
286
|
+
rb_iv_set(result, "@model", rb_str_new2(secmodel.model));
|
287
|
+
rb_iv_set(result, "@doi", rb_str_new2(secmodel.doi));
|
288
|
+
|
289
|
+
return result;
|
290
|
+
}
|
291
|
+
|
292
|
+
#if HAVE_VIRCONNECTISENCRYPTED
|
293
|
+
/*
|
294
|
+
* call-seq:
|
295
|
+
* conn.encrypted?
|
296
|
+
*
|
297
|
+
* Return +true+ if the connection is encrypted, +false+ if it is not
|
298
|
+
*/
|
299
|
+
static VALUE libvirt_conn_encrypted_p(VALUE s) {
|
300
|
+
gen_call_truefalse(virConnectIsEncrypted, conn(s), connect_get(s));
|
301
|
+
}
|
302
|
+
#endif
|
303
|
+
|
304
|
+
#if HAVE_VIRCONNECTISSECURE
|
305
|
+
/*
|
306
|
+
* call-seq:
|
307
|
+
* conn.secure?
|
308
|
+
*
|
309
|
+
* Return +true+ if the connection is secure, +false+ if it is not
|
310
|
+
*/
|
311
|
+
static VALUE libvirt_conn_secure_p(VALUE s) {
|
312
|
+
gen_call_truefalse(virConnectIsSecure, conn(s), connect_get(s));
|
313
|
+
}
|
314
|
+
#endif
|
315
|
+
|
316
|
+
/*
|
317
|
+
* call-seq:
|
318
|
+
* conn.capabilities -> string
|
319
|
+
*
|
320
|
+
* Call +virConnectGetCapabilities+[http://www.libvirt.org/html/libvirt-libvirt.html#virConnectGetCapabilities]
|
321
|
+
*/
|
322
|
+
static VALUE libvirt_conn_capabilities(VALUE s) {
|
323
|
+
gen_call_string(virConnectGetCapabilities, conn(s), 1, connect_get(s));
|
324
|
+
}
|
325
|
+
|
326
|
+
/*
|
327
|
+
* Class Libvirt::Connect
|
328
|
+
*/
|
329
|
+
void init_connect()
|
330
|
+
{
|
331
|
+
c_connect = rb_define_class_under(m_libvirt, "Connect", rb_cObject);
|
332
|
+
|
333
|
+
/*
|
334
|
+
* Class Libvirt::Connect::Nodeinfo
|
335
|
+
*/
|
336
|
+
c_node_info = rb_define_class_under(c_connect, "Nodeinfo", rb_cObject);
|
337
|
+
rb_define_attr(c_node_info, "model", 1, 0);
|
338
|
+
rb_define_attr(c_node_info, "memory", 1, 0);
|
339
|
+
rb_define_attr(c_node_info, "cpus", 1, 0);
|
340
|
+
rb_define_attr(c_node_info, "mhz", 1, 0);
|
341
|
+
rb_define_attr(c_node_info, "nodes", 1, 0);
|
342
|
+
rb_define_attr(c_node_info, "sockets", 1, 0);
|
343
|
+
rb_define_attr(c_node_info, "cores", 1, 0);
|
344
|
+
rb_define_attr(c_node_info, "threads", 1, 0);
|
345
|
+
|
346
|
+
/*
|
347
|
+
* Class Libvirt::Connect::NodeSecurityModel
|
348
|
+
*/
|
349
|
+
c_node_security_model = rb_define_class_under(c_connect,
|
350
|
+
"NodeSecurityModel",
|
351
|
+
rb_cObject);
|
352
|
+
rb_define_attr(c_node_security_model, "model", 1, 0);
|
353
|
+
rb_define_attr(c_node_security_model, "doi", 1, 0);
|
354
|
+
|
355
|
+
rb_define_method(c_connect, "close", libvirt_conn_close, 0);
|
356
|
+
rb_define_method(c_connect, "closed?", libvirt_conn_closed_p, 0);
|
357
|
+
rb_define_method(c_connect, "type", libvirt_conn_type, 0);
|
358
|
+
rb_define_method(c_connect, "version", libvirt_conn_version, 0);
|
359
|
+
#if HAVE_VIRCONNECTGETLIBVERSION
|
360
|
+
rb_define_method(c_connect, "libversion", libvirt_conn_libversion, 0);
|
361
|
+
#endif
|
362
|
+
rb_define_method(c_connect, "hostname", libvirt_conn_hostname, 0);
|
363
|
+
rb_define_method(c_connect, "uri", libvirt_conn_uri, 0);
|
364
|
+
rb_define_method(c_connect, "max_vcpus", libvirt_conn_max_vcpus, -1);
|
365
|
+
rb_define_method(c_connect, "node_get_info", libvirt_conn_node_get_info, 0);
|
366
|
+
rb_define_method(c_connect, "node_free_memory",
|
367
|
+
libvirt_conn_node_free_memory, 0);
|
368
|
+
rb_define_method(c_connect, "node_cells_free_memory",
|
369
|
+
libvirt_conn_node_cells_free_memory, -1);
|
370
|
+
rb_define_method(c_connect, "node_get_security_model",
|
371
|
+
libvirt_conn_node_get_security_model, 0);
|
372
|
+
#if HAVE_VIRCONNECTISENCRYPTED
|
373
|
+
rb_define_method(c_connect, "encrypted?", libvirt_conn_encrypted_p, 0);
|
374
|
+
#endif
|
375
|
+
#if HAVE_VIRCONNECTISSECURE
|
376
|
+
rb_define_method(c_connect, "secure?", libvirt_conn_secure_p, 0);
|
377
|
+
#endif
|
378
|
+
rb_define_method(c_connect, "capabilities", libvirt_conn_capabilities, 0);
|
379
|
+
|
380
|
+
/* FIXME: implement these */
|
381
|
+
//rb_define_method(c_connect, "domain_event_register",
|
382
|
+
// libvirt_conn_domain_event_register", -1);
|
383
|
+
//rb_define_method(c_connect, "Domain_event_deregister",
|
384
|
+
// libvirt_conn_domain_event_deregister, -1);
|
385
|
+
//rb_define_method(c_connect, "domain_event_register_any",
|
386
|
+
// libvirt_conn_domain_event_register_any, -1);
|
387
|
+
//rb_define_method(c_connect, "domain_event_deregister_any",
|
388
|
+
// libvirt_conn_domain_event_deregister_any, -1);
|
389
|
+
//rb_define_method(c_connect, "baseline_cpu", libvirt_conn_baseline_cpu, -1);
|
390
|
+
//rb_define_method(c_connect, "compare_cpu", libvirt_conn_compare_cpu, -1);
|
391
|
+
//rb_define_method(c_connect, "event_register_impl", libvirt_conn_event_register_impl, -1);
|
392
|
+
}
|