/* * call-seq: * secret.value(flags=0) -> String * * Call virSecretGetValue[http://www.libvirt.org/html/libvirt-libvirt-secret.html#virSecretGetValue] * to retrieve the value from this secret. */ static VALUE libvirt_secret_value(int argc, VALUE *argv, VALUE s) { VALUE flags, ret; unsigned char *val; size_t value_size; int exception = 0; struct ruby_libvirt_str_new_arg args; rb_scan_args(argc, argv, "01", &flags); val = virSecretGetValue(secret_get(s), &value_size, ruby_libvirt_value_to_uint(flags)); ruby_libvirt_raise_error_if(val == NULL, e_RetrieveError, "virSecretGetValue", ruby_libvirt_connect_get(s)); args.val = (char *)val; args.size = value_size; ret = rb_protect(ruby_libvirt_str_new_wrap, (VALUE)&args, &exception); free(val); if (exception) { rb_jump_tag(exception); } return ret; }
VALUE ruby_libvirt_get_parameters(VALUE d, unsigned int flags, void *opaque, unsigned int typesize, const char *(*nparams_cb)(VALUE d, unsigned int flags, void *opaque, int *nparams), const char *(*get_cb)(VALUE d, unsigned int flags, void *voidparams, int *nparams, void *opaque), void (*hash_set)(void *voidparams, int i, VALUE result)) { int nparams = 0; void *params; VALUE result; const char *errname; int i; errname = nparams_cb(d, flags, opaque, &nparams); ruby_libvirt_raise_error_if(errname != NULL, e_RetrieveError, errname, ruby_libvirt_connect_get(d)); result = rb_hash_new(); if (nparams == 0) { return result; } params = alloca(typesize * nparams); errname = get_cb(d, flags, params, &nparams, opaque); ruby_libvirt_raise_error_if(errname != NULL, e_RetrieveError, errname, ruby_libvirt_connect_get(d)); for (i = 0; i < nparams; i++) { hash_set(params, i, result); } return result; }
int ruby_libvirt_get_maxcpus(virConnectPtr conn) { int maxcpu = -1; virNodeInfo nodeinfo; #if HAVE_VIRNODEGETCPUMAP maxcpu = virNodeGetCPUMap(conn, NULL, NULL, 0); #endif if (maxcpu < 0) { /* fall back to nodeinfo */ ruby_libvirt_raise_error_if(virNodeGetInfo(conn, &nodeinfo) < 0, e_RetrieveError, "virNodeGetInfo", conn); maxcpu = VIR_NODEINFO_MAXCPUS(nodeinfo); } return maxcpu; }
VALUE ruby_libvirt_set_typed_parameters(VALUE d, VALUE input, unsigned int flags, void *opaque, struct ruby_libvirt_typed_param *allowed, unsigned int num_allowed, const char *(*set_cb)(VALUE d, unsigned int flags, virTypedParameterPtr params, int nparams, void *opaque)) { const char *errname; struct ruby_libvirt_parameter_assign_args args; unsigned long hashsize; /* make sure input is a hash */ Check_Type(input, T_HASH); hashsize = RHASH_SIZE(input); if (hashsize == 0) { return Qnil; } args.allowed = allowed; args.num_allowed = num_allowed; args.params = alloca(sizeof(virTypedParameter) * hashsize); args.i = 0; rb_hash_foreach(input, ruby_libvirt_typed_parameter_assign, (VALUE)&args); errname = set_cb(d, flags, args.params, args.i, opaque); ruby_libvirt_raise_error_if(errname != NULL, e_RetrieveError, errname, ruby_libvirt_connect_get(d)); return Qnil; }