2 * Copyright (C) 2008 Daniel Hokka Zakrisson
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * vim:set ts=2 sw=2 expandtab:
24 #include <sys/types.h>
25 #include <sys/socket.h>
26 #include <arpa/inet.h>
35 static inline PyObject *NONE(void)
42 pyvserver_get_version(PyObject UNUSED *self, PyObject UNUSED *args)
44 int ver = vc_get_version();
46 return PyErr_SetFromErrno(PyExc_OSError);
48 return Py_BuildValue("i", ver);
52 pyvserver_get_vci(PyObject UNUSED *self, PyObject UNUSED *args)
54 vc_vci_t vci = vc_get_vci();
55 if (vci == (vc_vci_t)-1)
56 return PyErr_SetFromErrno(PyExc_OSError);
58 return Py_BuildValue("K", vci);
62 pyvserver_ctx_create(PyObject UNUSED *self, PyObject *args)
65 struct vc_ctx_flags flags = { .mask = 0 };
67 if (!PyArg_ParseTuple(args, "I|KK", &xid, &flags.flagword, &flags.mask))
70 if (flags.flagword && !flags.mask)
71 flags.mask = flags.flagword;
73 ret = vc_ctx_create(xid, &flags);
75 return PyErr_SetFromErrno(PyExc_OSError);
77 return Py_BuildValue("I", ret);
81 pyvserver_ctx_migrate(PyObject UNUSED *self, PyObject *args)
86 if (!PyArg_ParseTuple(args, "IK", &xid, &flags))
89 if (vc_ctx_migrate(xid, flags) == -1)
90 return PyErr_SetFromErrno(PyExc_OSError);
96 pyvserver_ctx_stat(PyObject UNUSED *self, PyObject *args)
99 struct vc_ctx_stat stats;
101 if (!PyArg_ParseTuple(args, "I", &xid))
104 if (vc_ctx_stat(xid, &stats) == -1)
105 return PyErr_SetFromErrno(PyExc_OSError);
107 return Py_BuildValue("(II)", stats.usecnt, stats.tasks);
111 pyvserver_virt_stat(PyObject UNUSED *self, PyObject *args)
114 struct vc_virt_stat stats;
116 if (!PyArg_ParseTuple(args, "I", &xid))
119 if (vc_virt_stat(xid, &stats) == -1)
120 return PyErr_SetFromErrno(PyExc_OSError);
122 return Py_BuildValue("(KKIIIIIIII)", stats.offset, stats.uptime,
123 stats.nr_threads, stats.nr_running,
124 stats.nr_uninterruptible, stats.nr_onhold,
125 stats.nr_forks, stats.load[0], stats.load[1],
130 pyvserver_ctx_kill(PyObject UNUSED *self, PyObject *args)
136 if (!PyArg_ParseTuple(args, "Iii", &xid, &pid, &signal))
139 if (vc_ctx_kill(xid, pid, signal) == -1)
140 return PyErr_SetFromErrno(PyExc_OSError);
146 pyvserver_get_cflags(PyObject UNUSED *self, PyObject *args)
149 struct vc_ctx_flags flags;
151 if (!PyArg_ParseTuple(args, "I", &xid))
154 if (vc_get_cflags(xid, &flags) == -1)
155 return PyErr_SetFromErrno(PyExc_OSError);
157 return Py_BuildValue("(KK)", flags.flagword, flags.mask);
161 pyvserver_set_cflags(PyObject UNUSED *self, PyObject *args)
164 struct vc_ctx_flags flags;
166 if (!PyArg_ParseTuple(args, "I(KK)", &xid, flags.flagword, flags.mask))
169 if (vc_set_cflags(xid, &flags) == -1)
170 return PyErr_SetFromErrno(PyExc_OSError);
176 pyvserver_get_ccaps(PyObject UNUSED *self, PyObject *args)
179 struct vc_ctx_caps caps;
181 if (!PyArg_ParseTuple(args, "I", &xid))
184 if (vc_get_ccaps(xid, &caps) == -1)
185 return PyErr_SetFromErrno(PyExc_OSError);
187 return Py_BuildValue("(KKKK)", caps.bcaps, caps.bmask, caps.ccaps,
192 pyvserver_set_ccaps(PyObject UNUSED *self, PyObject *args)
195 struct vc_ctx_caps caps;
197 if (!PyArg_ParseTuple(args, "I(KKKK)", &xid, &caps.bcaps, &caps.bmask,
198 &caps.ccaps, &caps.cmask))
201 if (vc_set_ccaps(xid, &caps) == -1)
202 return PyErr_SetFromErrno(PyExc_OSError);
208 pyvserver_get_vx_info(PyObject UNUSED *self, PyObject *args)
211 struct vc_vx_info info;
213 if (!PyArg_ParseTuple(args, "I", &xid))
216 if (vc_get_vx_info(xid, &info) == -1)
217 return PyErr_SetFromErrno(PyExc_OSError);
219 return Py_BuildValue("(Ii)", info.xid, info.initpid);
223 pyvserver_get_task_xid(PyObject UNUSED *self, PyObject *args)
228 if (!PyArg_ParseTuple(args, "i", &pid))
231 xid = vc_get_task_xid(pid);
233 return PyErr_SetFromErrno(PyExc_OSError);
235 return Py_BuildValue("I", xid);
239 pyvserver_wait_exit(PyObject UNUSED *self, PyObject *args)
243 if (!PyArg_ParseTuple(args, "I", &xid))
246 if (vc_wait_exit(xid) == -1)
253 pyvserver_get_rlimit_mask(PyObject UNUSED *self, PyObject *args)
256 struct vc_rlimit_mask mask;
258 if (!PyArg_ParseTuple(args, "I", &xid))
261 if (vc_get_rlimit_mask(xid, &mask) == -1)
262 return PyErr_SetFromErrno(PyExc_OSError);
264 return Py_BuildValue("(III)", mask.min, mask.soft, mask.hard);
268 pyvserver_get_rlimit(PyObject UNUSED *self, PyObject *args)
272 struct vc_rlimit limit = { .min = 0 };
274 if (!PyArg_ParseTuple(args, "Ii", &xid, &resource))
277 if (vc_get_rlimit(xid, resource, &limit) == -1)
278 return PyErr_SetFromErrno(PyExc_OSError);
280 return Py_BuildValue("(LLL)", limit.min, limit.soft, limit.hard);
284 pyvserver_set_rlimit(PyObject UNUSED *self, PyObject *args)
288 struct vc_rlimit limit = {
294 if (!PyArg_ParseTuple(args, "Ii(KKK)", &xid, &resource, &limit.min,
295 &limit.soft, &limit.hard))
298 if (vc_set_rlimit(xid, resource, &limit) == -1)
299 return PyErr_SetFromErrno(PyExc_OSError);
305 pyvserver_rlimit_stat(PyObject UNUSED *self, PyObject *args)
309 struct vc_rlimit_stat stats;
311 if (!PyArg_ParseTuple(args, "Ii", &xid, &resource))
314 if (vc_rlimit_stat(xid, resource, &stats) == -1)
315 return PyErr_SetFromErrno(PyExc_OSError);
317 return Py_BuildValue("(IKKK)", stats.hits, stats.value, stats.minimum,
322 pyvserver_reset_minmax(PyObject UNUSED *self, PyObject *args)
326 if (!PyArg_ParseTuple(args, "I", &xid))
329 if (vc_reset_minmax(xid) == -1)
330 return PyErr_SetFromErrno(PyExc_OSError);
336 pyvserver_get_task_nid(PyObject UNUSED *self, PyObject *args)
341 if (!PyArg_ParseTuple(args, "i", &pid))
344 nid = vc_get_task_nid(pid);
346 return PyErr_SetFromErrno(PyExc_OSError);
348 return Py_BuildValue("I", nid);
352 pyvserver_get_nx_info(PyObject UNUSED *self, PyObject *args)
355 struct vc_nx_info info;
357 if (!PyArg_ParseTuple(args, "I", &nid))
360 if (vc_get_nx_info(nid, &info) == -1)
361 return PyErr_SetFromErrno(PyExc_OSError);
363 return Py_BuildValue("(I)", info.nid);
367 pyvserver_net_create(PyObject UNUSED *self, PyObject *args)
371 if (!PyArg_ParseTuple(args, "I", &nid))
374 ret = vc_net_create(nid);
376 return PyErr_SetFromErrno(PyExc_OSError);
378 return Py_BuildValue("I", ret);
382 pyvserver_net_migrate(PyObject UNUSED *self, PyObject *args)
386 if (!PyArg_ParseTuple(args, "I", &nid))
389 if (vc_net_migrate(nid) == -1)
390 return PyErr_SetFromErrno(PyExc_OSError);
396 pyvserver_net_handle(PyObject UNUSED *self, PyObject *args,
397 int (*func)(nid_t nid, struct vc_net_addr const *addr))
400 struct vc_net_addr addr;
401 char *ip1, *ip2, *mask;
403 if (!PyArg_ParseTuple(args, "I(HHHHsss)", &nid, &addr.vna_type,
404 &addr.vna_flags, &addr.vna_prefix, &addr.vna_parent,
408 if (addr.vna_type & VC_NXA_TYPE_IPV6) {
409 if (inet_pton(AF_INET6, ip1, &addr.vna_v6_ip) <= 0 ||
410 inet_pton(AF_INET6, ip2, &addr.vna_v6_ip2) <= 0 ||
411 inet_pton(AF_INET6, mask, &addr.vna_v6_mask) <= 0) {
412 PyErr_SetString(PyExc_ValueError, "invalid IPv6 addresses");
416 else if (addr.vna_type & VC_NXA_TYPE_IPV4) {
417 if (inet_pton(AF_INET, ip1, &addr.vna_v4_ip) <= 0 ||
418 inet_pton(AF_INET, ip2, &addr.vna_v4_ip2) <= 0 ||
419 inet_pton(AF_INET, mask, &addr.vna_v4_mask) <= 0) {
420 PyErr_SetString(PyExc_ValueError, "invalid IPv4 addresses");
424 else if (addr.vna_type != VC_NXA_TYPE_ANY) {
425 PyErr_SetString(PyExc_ValueError, "type");
429 if (func(nid, &addr) == -1)
430 return PyErr_SetFromErrno(PyExc_OSError);
436 pyvserver_net_add(PyObject UNUSED *self, PyObject *args)
438 return pyvserver_net_handle(self, args, vc_net_add);
442 pyvserver_net_remove(PyObject UNUSED *self, PyObject *args)
444 return pyvserver_net_handle(self, args, vc_net_remove);
448 pyvserver_get_nflags(PyObject UNUSED *self, PyObject *args)
451 struct vc_net_flags flags;
453 if (!PyArg_ParseTuple(args, "I", &nid))
456 if (vc_get_nflags(nid, &flags) == -1)
457 return PyErr_SetFromErrno(PyExc_OSError);
459 return Py_BuildValue("(KK)", flags.flagword, flags.mask);
463 pyvserver_set_nflags(PyObject UNUSED *self, PyObject *args)
466 struct vc_net_flags flags;
468 if (!PyArg_ParseTuple(args, "I(KK)", &nid, &flags.flagword, &flags.mask))
471 if (vc_set_nflags(nid, &flags) == -1)
472 return PyErr_SetFromErrno(PyExc_OSError);
478 pyvserver_get_ncaps(PyObject UNUSED *self, PyObject *args)
481 struct vc_net_caps caps;
483 if (!PyArg_ParseTuple(args, "I", &nid))
486 if (vc_get_ncaps(nid, &caps) == -1)
487 return PyErr_SetFromErrno(PyExc_OSError);
489 return Py_BuildValue("(KK)", caps.ncaps, caps.cmask);
493 pyvserver_set_ncaps(PyObject UNUSED *self, PyObject *args)
496 struct vc_net_caps caps;
498 if (!PyArg_ParseTuple(args, "I(KK)", &nid, &caps.ncaps, &caps.cmask))
501 if (vc_set_ncaps(nid, &caps) == -1)
502 return PyErr_SetFromErrno(PyExc_OSError);
508 pyvserver_set_iattr(PyObject UNUSED *self, PyObject *args)
510 char const *filename;
512 uint_least32_t flags, mask;
514 if (!PyArg_ParseTuple(args, "sIII", &filename, &tag, &flags, &mask))
517 if (vc_set_iattr(filename, tag, flags, mask) == -1)
518 return PyErr_SetFromErrno(PyExc_OSError);
524 pyvserver_fset_iattr(PyObject UNUSED *self, PyObject *args)
528 uint_least32_t flags, mask;
530 if (!PyArg_ParseTuple(args, "iIII", &fd, &tag, &flags, &mask))
533 if (vc_fset_iattr(fd, tag, flags, mask) == -1)
534 return PyErr_SetFromErrno(PyExc_OSError);
540 pyvserver_get_iattr(PyObject UNUSED *self, PyObject *args)
542 char const *filename;
544 uint_least32_t flags, mask;
546 if (!PyArg_ParseTuple(args, "sI", &filename, &mask))
549 if (vc_get_iattr(filename, &tag, &flags, &mask) == -1)
550 return PyErr_SetFromErrno(PyExc_OSError);
552 return Py_BuildValue("(III)", tag, flags, mask);
556 pyvserver_fget_iattr(PyObject UNUSED *self, PyObject *args)
560 uint_least32_t flags, mask;
562 if (!PyArg_ParseTuple(args, "iI", &fd, &mask))
565 if (vc_fget_iattr(fd, &tag, &flags, &mask) == -1)
566 return PyErr_SetFromErrno(PyExc_OSError);
568 return Py_BuildValue("(III)", tag, flags, mask);
572 pyvserver_set_vhi_name(PyObject UNUSED *self, PyObject *args)
579 if (!PyArg_ParseTuple(args, "Iis#", &xid, &type, &val, &len))
582 if (vc_set_vhi_name(xid, type, val, len) == -1)
583 return PyErr_SetFromErrno(PyExc_OSError);
589 pyvserver_get_vhi_name(PyObject UNUSED *self, PyObject *args)
595 if (!PyArg_ParseTuple(args, "Ii", &xid, &type))
598 if (vc_get_vhi_name(xid, type, val, sizeof(val)) == -1)
599 return PyErr_SetFromErrno(PyExc_OSError);
601 return Py_BuildValue("s#", val, sizeof(val));
605 pyvserver_enter_namespace(PyObject UNUSED *self, PyObject *args)
611 if (!PyArg_ParseTuple(args, "IKI", &xid, &mask, &index))
614 if (vc_enter_namespace(xid, mask, index) == -1)
615 return PyErr_SetFromErrno(PyExc_OSError);
621 pyvserver_set_namespace(PyObject UNUSED *self, PyObject *args)
627 if (!PyArg_ParseTuple(args, "IKI", &xid, &mask, &index))
630 if (vc_set_namespace(xid, mask, index) == -1)
631 return PyErr_SetFromErrno(PyExc_OSError);
637 pyvserver_get_space_mask(PyObject UNUSED *self, PyObject UNUSED *args)
639 uint_least64_t mask = vc_get_space_mask();
640 return Py_BuildValue("K", mask);
644 pyvserver_get_space_default(PyObject UNUSED *self, PyObject UNUSED *args)
646 uint_least64_t mask = vc_get_space_default();
647 return Py_BuildValue("K", mask);
651 pyvserver_add_dlimit(PyObject UNUSED *self, PyObject *args)
653 char const *filename;
655 uint_least32_t flags;
657 if (!PyArg_ParseTuple(args, "sII", &filename, &tag, &flags))
660 if (vc_add_dlimit(filename, tag, flags) == -1)
661 return PyErr_SetFromErrno(PyExc_OSError);
667 pyvserver_rem_dlimit(PyObject UNUSED *self, PyObject *args)
669 char const *filename;
671 uint_least32_t flags;
673 if (!PyArg_ParseTuple(args, "sII", &filename, &tag, &flags))
676 if (vc_rem_dlimit(filename, tag, flags) == -1)
677 return PyErr_SetFromErrno(PyExc_OSError);
683 pyvserver_set_dlimit(PyObject UNUSED *self, PyObject *args)
685 char const *filename;
687 uint_least32_t flags;
688 struct vc_ctx_dlimit limit;
690 if (!PyArg_ParseTuple(args, "sII(IIIII)", &filename, &tag, &flags,
691 &limit.space_used, &limit.space_total,
692 &limit.inodes_used, &limit.inodes_total,
696 if (vc_set_dlimit(filename, tag, flags, &limit) == -1)
697 return PyErr_SetFromErrno(PyExc_OSError);
703 pyvserver_get_dlimit(PyObject UNUSED *self, PyObject *args)
705 char const *filename;
707 uint_least32_t flags;
708 struct vc_ctx_dlimit limit;
710 if (!PyArg_ParseTuple(args, "sII", &filename, &tag, &flags))
713 if (vc_get_dlimit(filename, tag, flags, &limit) == -1)
714 return PyErr_SetFromErrno(PyExc_OSError);
716 return Py_BuildValue("(IIIII)", limit.space_used, limit.space_total,
717 limit.inodes_used, limit.inodes_total, limit.reserved);
721 pyvserver_get_task_tag(PyObject UNUSED *self, PyObject *args)
726 if (!PyArg_ParseTuple(args, "i", &pid))
729 tag = vc_get_task_tag(pid);
730 if (tag == (tag_t) -1)
731 return PyErr_SetFromErrno(PyExc_OSError);
733 return Py_BuildValue("I", tag);
737 pyvserver_tag_create(PyObject UNUSED *self, PyObject *args)
741 if (!PyArg_ParseTuple(args, "I", &tag))
744 if (vc_tag_create(tag) == -1)
745 return PyErr_SetFromErrno(PyExc_OSError);
751 pyvserver_tag_migrate(PyObject UNUSED *self, PyObject *args)
755 if (!PyArg_ParseTuple(args, "I", &tag))
758 if (vc_tag_migrate(tag) == -1)
759 return PyErr_SetFromErrno(PyExc_OSError);
765 pyvserver_set_sched(PyObject UNUSED *self, PyObject *args)
768 struct vc_set_sched sched;
770 if (!PyArg_ParseTuple(args, "I(Iiiiiiiiiii)", &xid, &sched.set_mask,
771 &sched.fill_rate, &sched.interval, &sched.fill_rate2,
772 &sched.interval2, &sched.tokens, &sched.tokens_min,
773 &sched.tokens_max, &sched.priority_bias, &sched.cpu_id,
777 if (vc_set_sched(xid, &sched) == -1)
778 return PyErr_SetFromErrno(PyExc_OSError);
784 pyvserver_get_sched(PyObject UNUSED *self, PyObject *args)
787 struct vc_set_sched sched;
789 if (!PyArg_ParseTuple(args, "Iii", &xid, &sched.cpu_id, &sched.bucket_id))
792 if (vc_get_sched(xid, &sched) == -1)
793 return PyErr_SetFromErrno(PyExc_OSError);
795 return Py_BuildValue("(Iiiiiiiiiii)", sched.set_mask, sched.fill_rate,
796 sched.interval, sched.fill_rate2, sched.interval2,
797 sched.tokens, sched.tokens_min, sched.tokens_max,
798 sched.priority_bias, sched.cpu_id, sched.bucket_id);
802 pyvserver_sched_info(PyObject UNUSED *self, PyObject *args)
805 struct vc_sched_info info;
807 if (!PyArg_ParseTuple(args, "Iii", &xid, &info.cpu_id, &info.bucket_id))
810 if (vc_sched_info(xid, &info) == -1)
811 return PyErr_SetFromErrno(PyExc_OSError);
813 return Py_BuildValue("(iiKKKIi)", info.cpu_id, info.bucket_id,
814 info.user_msec, info.sys_msec, info.hold_msec,
815 info.token_usec, info.vavavoom);
819 pyvserver_set_mapping(PyObject UNUSED *self, PyObject *args)
822 const char *device, *target;
825 if (!PyArg_ParseTuple(args, "IssI", &xid, &device, &target, &flags))
828 if (vc_set_mapping(xid, device, target, flags) == -1)
829 return PyErr_SetFromErrno(PyExc_OSError);
835 pyvserver_unset_mapping(PyObject UNUSED *self, PyObject *args)
838 const char *device, *target;
841 if (!PyArg_ParseTuple(args, "IssI", &xid, &device, &target, &flags))
844 if (vc_unset_mapping(xid, device, target, flags) == -1)
845 return PyErr_SetFromErrno(PyExc_OSError);
851 pyvserver_get_badness(PyObject UNUSED *self, PyObject *args)
856 if (!PyArg_ParseTuple(args, "I", &xid))
859 if (vc_get_badness(xid, &badness) == -1)
860 return PyErr_SetFromErrno(PyExc_OSError);
862 return Py_BuildValue("L", badness);
866 pyvserver_set_badness(PyObject UNUSED *self, PyObject *args)
871 if (!PyArg_ParseTuple(args, "IL", &xid, &badness))
874 if (vc_set_badness(xid, badness) == -1)
875 return PyErr_SetFromErrno(PyExc_OSError);
881 pyvserver_get_insecurebcaps(PyObject UNUSED *self, PyObject UNUSED *args)
883 uint_least64_t bcaps = vc_get_insecurebcaps();
884 return Py_BuildValue("K", bcaps);
888 pyvserver_get_insecureccaps(PyObject UNUSED *self, PyObject UNUSED *args)
890 uint_least64_t ccaps = vc_get_insecureccaps();
891 return Py_BuildValue("K", ccaps);
895 pyvserver_isSupported(PyObject UNUSED *self, PyObject *args)
899 if (!PyArg_ParseTuple(args, "i", &feature))
902 if (vc_isSupported(feature))
909 pyvserver_isSupportedString(PyObject UNUSED *self, PyObject *args)
913 if (!PyArg_ParseTuple(args, "s", &feature))
916 if (vc_isSupportedString(feature))
923 pyvserver_getXIDType(PyObject UNUSED *self, PyObject *args)
927 if (!PyArg_ParseTuple(args, "I", &xid))
930 return Py_BuildValue("i", vc_getXIDType(xid));
934 pyvserver_xidopt2xid(PyObject UNUSED *self, PyObject *args)
937 PyObject *honor_static;
939 char const *err_info;
941 if (!PyArg_ParseTuple(args, "sO", &xidopt, &honor_static))
944 xid = vc_xidopt2xid(xidopt, honor_static != Py_False, &err_info);
945 if (xid == VC_NOXID) {
946 PyErr_SetString(PyExc_OSError, err_info);
950 return Py_BuildValue("I", xid);
954 pyvserver_nidopt2nid(PyObject UNUSED *self, PyObject *args)
957 PyObject *honor_static;
959 char const *err_info;
961 if (!PyArg_ParseTuple(args, "sO", &nidopt, &honor_static))
964 nid = vc_nidopt2nid(nidopt, honor_static != Py_False, &err_info);
965 if (nid == VC_NONID) {
966 PyErr_SetString(PyExc_OSError, err_info);
970 return Py_BuildValue("I", nid);
974 pyvserver_tagopt2tag(PyObject UNUSED *self, PyObject *args)
977 PyObject *honor_static;
979 char const *err_info;
981 if (!PyArg_ParseTuple(args, "sO", &tagopt, &honor_static))
984 tag = vc_tagopt2tag(tagopt, honor_static != Py_False, &err_info);
985 if (tag == (tag_t) -1) {
986 PyErr_SetString(PyExc_OSError, err_info);
990 return Py_BuildValue("I", tag);
993 #define pyvserver_handle_list(name, list_type, flag_member, mask_member) \
995 pyvserver_text2 ## name(PyObject UNUSED *self, PyObject *args) \
999 uint_least64_t val; \
1001 if (!PyArg_ParseTuple(args, "s#", &str, &len)) \
1004 val = vc_text2 ## name(str, len); \
1005 return Py_BuildValue("K", val); \
1009 pyvserver_lo ## name ## 2text(PyObject UNUSED *self, PyObject *args) \
1011 uint_least64_t val; \
1014 if (!PyArg_ParseTuple(args, "K", &val)) \
1017 ret = vc_lo ## name ## 2text(&val); \
1018 return Py_BuildValue("(Kz)", val, ret); \
1022 pyvserver_list2 ## name(PyObject UNUSED *self, PyObject *args) \
1026 struct vc_err_listparser err; \
1027 list_type val = { .mask_member = 0 }; \
1029 if (!PyArg_ParseTuple(args, "s#", &str, &len)) \
1032 if (vc_list2 ## name(str, len, &err, &val) == -1) { \
1034 if (asprintf(&error, "unknown value '%.*s'", (int)err.len, err.ptr) == -1) \
1035 return PyErr_SetFromErrno(PyExc_MemoryError); \
1036 PyErr_SetString(PyExc_ValueError, error); \
1041 return Py_BuildValue("(KK)", val.flag_member, val.mask_member); \
1044 pyvserver_handle_list(bcap, struct vc_ctx_caps, bcaps, bmask)
1045 pyvserver_handle_list(ccap, struct vc_ctx_caps, ccaps, cmask)
1046 pyvserver_handle_list(cflag, struct vc_ctx_flags, flagword, mask)
1047 pyvserver_handle_list(nflag, struct vc_net_flags, flagword, mask)
1048 pyvserver_handle_list(ncap, struct vc_net_caps, ncaps, cmask)
1050 static PyMethodDef methods[] = {
1051 { "vc_get_version", pyvserver_get_version, METH_NOARGS, "FIXME" },
1052 { "vc_get_vci", pyvserver_get_vci, METH_NOARGS, "FIXME" },
1053 { "vc_ctx_create", pyvserver_ctx_create, METH_VARARGS, "FIXME" },
1054 { "vc_ctx_migrate", pyvserver_ctx_migrate, METH_VARARGS, "FIXME" },
1055 { "vc_ctx_stat", pyvserver_ctx_stat, METH_VARARGS, "FIXME" },
1056 { "vc_virt_stat", pyvserver_virt_stat, METH_VARARGS, "FIXME" },
1057 { "vc_ctx_kill", pyvserver_ctx_kill, METH_VARARGS, "FIXME" },
1058 { "vc_get_cflags", pyvserver_get_cflags, METH_VARARGS, "FIXME" },
1059 { "vc_set_cflags", pyvserver_set_cflags, METH_VARARGS, "FIXME" },
1060 { "vc_get_ccaps", pyvserver_get_ccaps, METH_VARARGS, "FIXME" },
1061 { "vc_set_ccaps", pyvserver_set_ccaps, METH_VARARGS, "FIXME" },
1062 { "vc_get_vx_info", pyvserver_get_vx_info, METH_VARARGS, "FIXME" },
1063 { "vc_get_task_xid", pyvserver_get_task_xid, METH_VARARGS, "FIXME" },
1064 { "vc_wait_exit", pyvserver_wait_exit, METH_VARARGS, "FIXME" },
1065 { "vc_get_rlimit_mask", pyvserver_get_rlimit_mask, METH_VARARGS, "FIXME" },
1066 { "vc_get_rlimit", pyvserver_get_rlimit, METH_VARARGS, "FIXME" },
1067 { "vc_set_rlimit", pyvserver_set_rlimit, METH_VARARGS, "FIXME" },
1068 { "vc_rlimit_stat", pyvserver_rlimit_stat, METH_VARARGS, "FIXME" },
1069 { "vc_reset_minmax", pyvserver_reset_minmax, METH_VARARGS, "FIXME" },
1070 { "vc_get_task_nid", pyvserver_get_task_nid, METH_VARARGS, "FIXME" },
1071 { "vc_get_nx_info", pyvserver_get_nx_info, METH_VARARGS, "FIXME" },
1072 { "vc_net_create", pyvserver_net_create, METH_VARARGS, "FIXME" },
1073 { "vc_net_migrate", pyvserver_net_migrate, METH_VARARGS, "FIXME" },
1074 { "vc_net_add", pyvserver_net_add, METH_VARARGS, "FIXME" },
1075 { "vc_net_remove", pyvserver_net_remove, METH_VARARGS, "FIXME" },
1076 { "vc_get_nflags", pyvserver_get_nflags, METH_VARARGS, "FIXME" },
1077 { "vc_set_nflags", pyvserver_set_nflags, METH_VARARGS, "FIXME" },
1078 { "vc_get_ncaps", pyvserver_get_ncaps, METH_VARARGS, "FIXME" },
1079 { "vc_set_ncaps", pyvserver_set_ncaps, METH_VARARGS, "FIXME" },
1080 { "vc_set_iattr", pyvserver_set_iattr, METH_VARARGS, "FIXME" },
1081 { "vc_fset_iattr", pyvserver_fset_iattr, METH_VARARGS, "FIXME" },
1082 { "vc_get_iattr", pyvserver_get_iattr, METH_VARARGS, "FIXME" },
1083 { "vc_fget_iattr", pyvserver_fget_iattr, METH_VARARGS, "FIXME" },
1084 { "vc_set_vhi_name", pyvserver_set_vhi_name, METH_VARARGS, "FIXME" },
1085 { "vc_get_vhi_name", pyvserver_get_vhi_name, METH_VARARGS, "FIXME" },
1086 { "vc_enter_namespace", pyvserver_enter_namespace, METH_VARARGS, "FIXME" },
1087 { "vc_set_namespace", pyvserver_set_namespace, METH_VARARGS, "FIXME" },
1088 { "vc_get_space_mask", pyvserver_get_space_mask, METH_NOARGS, "FIXME" },
1089 { "vc_get_space_default", pyvserver_get_space_default, METH_NOARGS, "FIXME" },
1090 { "vc_add_dlimit", pyvserver_add_dlimit, METH_VARARGS, "FIXME" },
1091 { "vc_rem_dlimit", pyvserver_rem_dlimit, METH_VARARGS, "FIXME" },
1092 { "vc_set_dlimit", pyvserver_set_dlimit, METH_VARARGS, "FIXME" },
1093 { "vc_get_dlimit", pyvserver_get_dlimit, METH_VARARGS, "FIXME" },
1094 { "vc_get_task_tag", pyvserver_get_task_tag, METH_VARARGS, "FIXME" },
1095 { "vc_tag_create", pyvserver_tag_create, METH_VARARGS, "FIXME" },
1096 { "vc_tag_migrate", pyvserver_tag_migrate, METH_VARARGS, "FIXME" },
1097 { "vc_set_sched", pyvserver_set_sched, METH_VARARGS, "FIXME" },
1098 { "vc_get_sched", pyvserver_get_sched, METH_VARARGS, "FIXME" },
1099 { "vc_sched_info", pyvserver_sched_info, METH_VARARGS, "FIXME" },
1100 { "vc_set_mapping", pyvserver_set_mapping, METH_VARARGS, "FIXME" },
1101 { "vc_unset_mapping", pyvserver_unset_mapping, METH_VARARGS, "FIXME" },
1102 { "vc_get_badness", pyvserver_get_badness, METH_VARARGS, "FIXME" },
1103 { "vc_set_badness", pyvserver_set_badness, METH_VARARGS, "FIXME" },
1104 { "vc_get_insecurebcaps", pyvserver_get_insecurebcaps, METH_NOARGS, "FIXME" },
1105 { "vc_get_insecureccaps", pyvserver_get_insecureccaps, METH_NOARGS, "FIXME" },
1106 { "vc_isSupported", pyvserver_isSupported, METH_VARARGS, "FIXME" },
1107 { "vc_isSupportedString", pyvserver_isSupportedString, METH_VARARGS, "FIXME" },
1108 { "vc_getXIDType", pyvserver_getXIDType, METH_VARARGS, "FIXME" },
1109 { "vc_xidopt2xid", pyvserver_xidopt2xid, METH_VARARGS, "FIXME" },
1110 { "vc_nidopt2nid", pyvserver_nidopt2nid, METH_VARARGS, "FIXME" },
1111 { "vc_tagopt2tag", pyvserver_tagopt2tag, METH_VARARGS, "FIXME" },
1112 { "vc_text2bcap", pyvserver_text2bcap, METH_VARARGS, "FIXME" },
1113 { "vc_lobcap2text", pyvserver_lobcap2text, METH_VARARGS, "FIXME" },
1114 { "vc_list2bcap", pyvserver_list2bcap, METH_VARARGS, "FIXME" },
1115 { "vc_text2ccap", pyvserver_text2ccap, METH_VARARGS, "FIXME" },
1116 { "vc_loccap2text", pyvserver_loccap2text, METH_VARARGS, "FIXME" },
1117 { "vc_list2ccap", pyvserver_list2ccap, METH_VARARGS, "FIXME" },
1118 { "vc_text2cflag", pyvserver_text2cflag, METH_VARARGS, "FIXME" },
1119 { "vc_locflag2text", pyvserver_locflag2text, METH_VARARGS, "FIXME" },
1120 { "vc_list2cflag", pyvserver_list2cflag, METH_VARARGS, "FIXME" },
1121 { "vc_text2nflag", pyvserver_text2nflag, METH_VARARGS, "FIXME" },
1122 { "vc_lonflag2text", pyvserver_lonflag2text, METH_VARARGS, "FIXME" },
1123 { "vc_list2nflag", pyvserver_list2nflag, METH_VARARGS, "FIXME" },
1124 { "vc_text2ncap", pyvserver_text2ncap, METH_VARARGS, "FIXME" },
1125 { "vc_loncap2text", pyvserver_loncap2text, METH_VARARGS, "FIXME" },
1126 { "vc_list2ncap", pyvserver_list2ncap, METH_VARARGS, "FIXME" },
1127 { NULL, NULL, 0, NULL }
1131 PyModule_AddLongLongConstant(PyObject *mod, const char *str, long long val)
1133 PyObject *o = PyLong_FromLongLong(val);
1134 if (!o || PyModule_AddObject(mod, str, o) == -1)
1135 /* This ought to be reported somehow... */
1139 PyMODINIT_FUNC init_libvserver(void)
1143 mod = Py_InitModule("_libvserver", methods);
1144 #include "_libvserver-constants.c"