mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
virsh: Implement vshTable API to net-list and net-dhcp-leases
Signed-off-by: Simon Kobyda <skobyda@redhat.com>
This commit is contained in:
parent
0396cf5336
commit
71029ef588
@ -33,6 +33,7 @@
|
|||||||
#include "virstring.h"
|
#include "virstring.h"
|
||||||
#include "virtime.h"
|
#include "virtime.h"
|
||||||
#include "conf/network_conf.h"
|
#include "conf/network_conf.h"
|
||||||
|
#include "vsh-table.h"
|
||||||
|
|
||||||
#define VIRSH_COMMON_OPT_NETWORK(_helpstr, cflags) \
|
#define VIRSH_COMMON_OPT_NETWORK(_helpstr, cflags) \
|
||||||
{.name = "network", \
|
{.name = "network", \
|
||||||
@ -677,6 +678,7 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
bool optUUID = vshCommandOptBool(cmd, "uuid");
|
bool optUUID = vshCommandOptBool(cmd, "uuid");
|
||||||
char uuid[VIR_UUID_STRING_BUFLEN];
|
char uuid[VIR_UUID_STRING_BUFLEN];
|
||||||
unsigned int flags = VIR_CONNECT_LIST_NETWORKS_ACTIVE;
|
unsigned int flags = VIR_CONNECT_LIST_NETWORKS_ACTIVE;
|
||||||
|
vshTablePtr table = NULL;
|
||||||
|
|
||||||
if (vshCommandOptBool(cmd, "inactive"))
|
if (vshCommandOptBool(cmd, "inactive"))
|
||||||
flags = VIR_CONNECT_LIST_NETWORKS_INACTIVE;
|
flags = VIR_CONNECT_LIST_NETWORKS_INACTIVE;
|
||||||
@ -705,10 +707,10 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (optTable) {
|
if (optTable) {
|
||||||
vshPrintExtra(ctl, " %-20s %-10s %-13s %s\n", _("Name"), _("State"),
|
table = vshTableNew(_("Name"), _("State"), _("Autostart"),
|
||||||
_("Autostart"), _("Persistent"));
|
_("Persistent"), NULL);
|
||||||
vshPrintExtra(ctl,
|
if (!table)
|
||||||
"----------------------------------------------------------\n");
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < list->nnets; i++) {
|
for (i = 0; i < list->nnets; i++) {
|
||||||
@ -722,11 +724,15 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
else
|
else
|
||||||
autostartStr = is_autostart ? _("yes") : _("no");
|
autostartStr = is_autostart ? _("yes") : _("no");
|
||||||
|
|
||||||
vshPrint(ctl, " %-20s %-10s %-13s %s\n",
|
if (vshTableRowAppend(table,
|
||||||
virNetworkGetName(network),
|
virNetworkGetName(network),
|
||||||
virNetworkIsActive(network) ? _("active") : _("inactive"),
|
virNetworkIsActive(network) ?
|
||||||
autostartStr,
|
_("active") : _("inactive"),
|
||||||
virNetworkIsPersistent(network) ? _("yes") : _("no"));
|
autostartStr,
|
||||||
|
virNetworkIsPersistent(network) ?
|
||||||
|
_("yes") : _("no"),
|
||||||
|
NULL) < 0)
|
||||||
|
goto cleanup;
|
||||||
} else if (optUUID) {
|
} else if (optUUID) {
|
||||||
if (virNetworkGetUUIDString(network, uuid) < 0) {
|
if (virNetworkGetUUIDString(network, uuid) < 0) {
|
||||||
vshError(ctl, "%s", _("Failed to get network's UUID"));
|
vshError(ctl, "%s", _("Failed to get network's UUID"));
|
||||||
@ -738,8 +744,12 @@ cmdNetworkList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (optTable)
|
||||||
|
vshTablePrintToStdout(table, ctl);
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
cleanup:
|
cleanup:
|
||||||
|
vshTableFree(table);
|
||||||
virshNetworkListFree(list);
|
virshNetworkListFree(list);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -1351,6 +1361,7 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *cmd)
|
|||||||
size_t i;
|
size_t i;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
virNetworkPtr network = NULL;
|
virNetworkPtr network = NULL;
|
||||||
|
vshTablePtr table = NULL;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "mac", &mac) < 0)
|
if (vshCommandOptStringReq(ctl, cmd, "mac", &mac) < 0)
|
||||||
return false;
|
return false;
|
||||||
@ -1366,15 +1377,15 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *cmd)
|
|||||||
/* Sort the list according to MAC Address/IAID */
|
/* Sort the list according to MAC Address/IAID */
|
||||||
qsort(leases, nleases, sizeof(*leases), virshNetworkDHCPLeaseSorter);
|
qsort(leases, nleases, sizeof(*leases), virshNetworkDHCPLeaseSorter);
|
||||||
|
|
||||||
vshPrintExtra(ctl, " %-20s %-18s %-9s %-25s %-15s %s\n%s%s\n",
|
table = vshTableNew(_("Expiry Time"), _("MAC address"), _("Protocol"),
|
||||||
_("Expiry Time"), _("MAC address"), _("Protocol"),
|
_("IP address"), _("Hostname"), _("Client ID or DUID"),
|
||||||
_("IP address"), _("Hostname"), _("Client ID or DUID"),
|
NULL);
|
||||||
"----------------------------------------------------------",
|
if (!table)
|
||||||
"---------------------------------------------------------");
|
goto cleanup;
|
||||||
|
|
||||||
for (i = 0; i < nleases; i++) {
|
for (i = 0; i < nleases; i++) {
|
||||||
const char *typestr = NULL;
|
const char *typestr = NULL;
|
||||||
char *cidr_format = NULL;
|
VIR_AUTOFREE(char *) cidr_format = NULL;
|
||||||
virNetworkDHCPLeasePtr lease = leases[i];
|
virNetworkDHCPLeasePtr lease = leases[i];
|
||||||
time_t expirytime_tmp = lease->expirytime;
|
time_t expirytime_tmp = lease->expirytime;
|
||||||
struct tm ts;
|
struct tm ts;
|
||||||
@ -1390,17 +1401,23 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *cmd)
|
|||||||
ignore_value(virAsprintf(&cidr_format, "%s/%d",
|
ignore_value(virAsprintf(&cidr_format, "%s/%d",
|
||||||
lease->ipaddr, lease->prefix));
|
lease->ipaddr, lease->prefix));
|
||||||
|
|
||||||
vshPrint(ctl, " %-20s %-18s %-9s %-25s %-15s %s\n",
|
if (vshTableRowAppend(table,
|
||||||
expirytime, EMPTYSTR(lease->mac),
|
expirytime,
|
||||||
EMPTYSTR(typestr), cidr_format,
|
EMPTYSTR(lease->mac),
|
||||||
EMPTYSTR(lease->hostname), EMPTYSTR(lease->clientid));
|
EMPTYSTR(typestr),
|
||||||
|
EMPTYSTR(cidr_format),
|
||||||
VIR_FREE(cidr_format);
|
EMPTYSTR(lease->hostname),
|
||||||
|
EMPTYSTR(lease->clientid),
|
||||||
|
NULL) < 0)
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vshTablePrintToStdout(table, ctl);
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
vshTableFree(table);
|
||||||
if (leases) {
|
if (leases) {
|
||||||
for (i = 0; i < nleases; i++)
|
for (i = 0; i < nleases; i++)
|
||||||
virNetworkDHCPLeaseFree(leases[i]);
|
virNetworkDHCPLeaseFree(leases[i]);
|
||||||
|
Loading…
Reference in New Issue
Block a user