2 * Copyright (C) 2014 Martin Willi
3 * Copyright (C) 2014 revosec AG
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 CALLBACK(list_pool
, int,
23 linked_list_t
*list
, vici_res_t
*res
, char *name
)
25 char pool
[64], leases
[32];
27 snprintf(pool
, sizeof(pool
), "%s:", name
);
28 snprintf(leases
, sizeof(leases
), "%s / %s / %s",
29 vici_find_str(res
, "", "%s.online", name
),
30 vici_find_str(res
, "", "%s.offline", name
),
31 vici_find_str(res
, "", "%s.size", name
));
33 printf("%-20s %-30s %16s\n",
34 name
, vici_find_str(res
, "", "%s.base", name
), leases
);
39 static int list_pools(vici_conn_t
*conn
)
49 switch (command_getopt(&arg
))
52 return command_usage(NULL
);
59 return command_usage("invalid --list-pools option");
64 req
= vici_begin("get-pools");
65 res
= vici_submit(req
, conn
);
68 fprintf(stderr
, "get-pools request failed: %s\n", strerror(errno
));
73 vici_dump(res
, "get-pools reply", stdout
);
77 ret
= vici_parse_cb(res
, list_pool
, NULL
, NULL
, NULL
);
84 * Register the command.
86 static void __attribute__ ((constructor
))reg()
88 command_register((command_t
) {
89 list_pools
, 'A', "list-pools", "list loaded pool configurations",
92 {"help", 'h', 0, "show usage information"},
93 {"raw", 'r', 0, "dump raw response message"},