Allow to show only specific images in listing

nbd-vmsplice
Vitaliy Filippov 2021-11-13 23:23:39 +03:00
parent 71a0c1a7b9
commit a346f84c69
2 changed files with 14 additions and 6 deletions

View File

@ -85,14 +85,14 @@ void cli_tool_t::help()
"(c) Vitaliy Filippov, 2019+ (VNPL-1.1)\n"
"\n"
"USAGE:\n"
"%s ls [-l] [--del] [-p <id|name>] [-w]\n"
" List images.\n"
"%s ls [-l] [-p POOL] [--sort FIELD] [-r] [-n N] [<name> ...]\n"
" List images (only specified if <name> passed).\n"
" -p|--pool POOL Filter images by pool ID or name\n"
" -l|--long Also report allocated size and I/O statistics\n"
" --del Also include delete operation statistics\n"
" --sort <field> Sort by specified field (name, size, used_size, <read|write|delete>_<iops|bps|lat|queue>)\n"
" --sort FIELD Sort by specified field (name, size, used_size, <read|write|delete>_<iops|bps|lat|queue>)\n"
" -r|--reverse Sort in descending order\n"
" --top <n> Only list top <n> items\n"
" -n|--count N Only list first N items\n"
"\n"
"%s create -s|--size <size> [-p|--pool <id|name>] [--parent <parent_name>[@<snapshot>]] <name>\n"
" Create an image. You may use K/M/G/T suffixes for <size>. If --parent is specified,\n"

View File

@ -26,6 +26,7 @@ struct image_lister_t
pool_id_t list_pool_id = 0;
std::string list_pool_name;
std::string sort_field;
std::set<std::string> only_names;
bool reverse = false;
int max_count = 0;
bool show_stats = false, show_delete = false;
@ -212,7 +213,10 @@ resume_1:
json11::Json::array list;
for (auto & kv: stats)
{
list.push_back(kv.second);
if (!only_names.size() || only_names.find(kv.second["name"].string_value()) != only_names.end())
{
list.push_back(kv.second);
}
}
if (sort_field == "name" || sort_field == "pool_name")
{
@ -500,7 +504,11 @@ std::function<bool(void)> cli_tool_t::start_ls(json11::Json cfg)
lister->show_delete = cfg["del"].bool_value();
lister->sort_field = cfg["sort"].string_value();
lister->reverse = cfg["reverse"].bool_value();
lister->max_count = cfg["top"].uint64_value();
lister->max_count = cfg["count"].uint64_value();
for (int i = 0; i < cmd.size(); i++)
{
lister->only_names.insert(cmd[i].string_value());
}
return [lister]()
{
lister->loop();