mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-31 00:45:18 +00:00
cmdNetworkList: switch to FILTER
Instead of sticking to old code pattern use the one laid out by cmdList. Use FILTER() macro instead of series of boolean variables. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
87c81cd5ee
commit
0258d9ab46
@ -647,37 +647,28 @@ static const vshCmdOptDef opts_network_list[] = {
|
|||||||
{.name = NULL}
|
{.name = NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#define FILTER(NAME, FLAG) \
|
||||||
|
if (vshCommandOptBool(cmd, NAME)) \
|
||||||
|
flags |= (FLAG)
|
||||||
static bool
|
static bool
|
||||||
cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
vshNetworkListPtr list = NULL;
|
vshNetworkListPtr list = NULL;
|
||||||
size_t i;
|
size_t i;
|
||||||
bool inactive = vshCommandOptBool(cmd, "inactive");
|
|
||||||
bool all = vshCommandOptBool(cmd, "all");
|
|
||||||
bool persistent = vshCommandOptBool(cmd, "persistent");
|
|
||||||
bool transient = vshCommandOptBool(cmd, "transient");
|
|
||||||
bool autostart = vshCommandOptBool(cmd, "autostart");
|
|
||||||
bool no_autostart = vshCommandOptBool(cmd, "no-autostart");
|
|
||||||
unsigned int flags = VIR_CONNECT_LIST_NETWORKS_ACTIVE;
|
unsigned int flags = VIR_CONNECT_LIST_NETWORKS_ACTIVE;
|
||||||
|
|
||||||
if (inactive)
|
if (vshCommandOptBool(cmd, "inactive"))
|
||||||
flags = VIR_CONNECT_LIST_NETWORKS_INACTIVE;
|
flags = VIR_CONNECT_LIST_NETWORKS_INACTIVE;
|
||||||
|
|
||||||
if (all)
|
if (vshCommandOptBool(cmd, "all"))
|
||||||
flags = VIR_CONNECT_LIST_NETWORKS_ACTIVE |
|
flags = VIR_CONNECT_LIST_NETWORKS_ACTIVE |
|
||||||
VIR_CONNECT_LIST_NETWORKS_INACTIVE;
|
VIR_CONNECT_LIST_NETWORKS_INACTIVE;
|
||||||
|
|
||||||
if (persistent)
|
FILTER("persistent", VIR_CONNECT_LIST_NETWORKS_PERSISTENT);
|
||||||
flags |= VIR_CONNECT_LIST_NETWORKS_PERSISTENT;
|
FILTER("transient", VIR_CONNECT_LIST_NETWORKS_TRANSIENT);
|
||||||
|
|
||||||
if (transient)
|
FILTER("autostart", VIR_CONNECT_LIST_NETWORKS_AUTOSTART);
|
||||||
flags |= VIR_CONNECT_LIST_NETWORKS_TRANSIENT;
|
FILTER("no-autostart", VIR_CONNECT_LIST_NETWORKS_NO_AUTOSTART);
|
||||||
|
|
||||||
if (autostart)
|
|
||||||
flags |= VIR_CONNECT_LIST_NETWORKS_AUTOSTART;
|
|
||||||
|
|
||||||
if (no_autostart)
|
|
||||||
flags |= VIR_CONNECT_LIST_NETWORKS_NO_AUTOSTART;
|
|
||||||
|
|
||||||
if (!(list = vshNetworkListCollect(ctl, flags)))
|
if (!(list = vshNetworkListCollect(ctl, flags)))
|
||||||
return false;
|
return false;
|
||||||
@ -707,6 +698,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
vshNetworkListFree(list);
|
vshNetworkListFree(list);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#undef FILTER
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* "net-name" command
|
* "net-name" command
|
||||||
|
Loading…
x
Reference in New Issue
Block a user