Finally, now that all APIs have been introduced, wire them up to virt-admin and introduce dmn-log-info and dmn-log-define commands. Signed-off-by: Erik Skultety <eskultet@xxxxxxxxxx> --- tools/virt-admin.c | 204 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) diff --git a/tools/virt-admin.c b/tools/virt-admin.c index d6f7084..1ec139a 100644 --- a/tools/virt-admin.c +++ b/tools/virt-admin.c @@ -742,6 +742,198 @@ cmdClientInfo(vshControl *ctl, const vshCmd *cmd) VIR_FREE(timestr); return ret; } + +/* ------------------- + * Command dmn-log-info + * ------------------- + */ +static const vshCmdInfo info_dmn_log_info[] = { + {.name = "help", + .data = N_("view daemon's current logging settings") + }, + {.name = "desc", + .data = N_("Returns all currently active logging settings on daemon. " + "These include global logging level, logging filters and " + "logging outputs.") + }, + {.name = NULL} +}; + +static const vshCmdOptDef opts_dmn_log_info[] = { + {.name = "daemon", + .type = VSH_OT_DATA, + .flags = VSH_OFLAG_REQ, + .help = N_("name of the daemon to query information from") + }, + {.name = "outputs", + .type = VSH_OT_BOOL, + .help = N_("query logging outputs") + }, + {.name = "filters", + .type = VSH_OT_BOOL, + .help = N_("query logging filters") + }, + {.name = "level", + .type = VSH_OT_BOOL, + .help = N_("query logging level") + }, + {.name = NULL} +}; + +static bool +cmdDmnLogInfo(vshControl *ctl, const vshCmd *cmd) +{ + bool ret = false; + bool optOutputs = vshCommandOptBool(cmd, "outputs"); + bool optFilters = vshCommandOptBool(cmd, "filters"); + bool optLevel = vshCommandOptBool(cmd, "level"); + bool all = optOutputs + optFilters + optLevel == 0; + int level, nfilters, noutputs; + char *filters, *outputs; + const char *levelstr = NULL; + vshAdmControlPtr priv = ctl->privData; + + if (optLevel || all) { + if ((level = virAdmConnectGetLoggingLevel(priv->conn, 0)) < 0) + goto cleanup; + + switch ((virLogPriority) level) { + case VIR_LOG_DEBUG: + levelstr = "debug"; + break; + case VIR_LOG_INFO: + levelstr = "info"; + break; + case VIR_LOG_WARN: + levelstr = "warning"; + break; + case VIR_LOG_ERROR: + levelstr = "error"; + break; + default: + vshError(ctl, _("Remote side returned a logging level this " + "version of library does not support")); + goto cleanup; + } + } + + if (optFilters || all) { + if ((nfilters = virAdmConnectGetLoggingFilters(priv->conn, + &filters, 0)) < 0) { + vshError(ctl, _("Unable to get daemon logging filters information")); + goto cleanup; + } + } + + if (optOutputs || all) { + if ((noutputs = virAdmConnectGetLoggingOutputs(priv->conn, + &outputs, 0)) < 0) { + vshError(ctl, _("Unable to get daemon logging outputs information")); + goto cleanup; + } + } + + if (optLevel || all) { + vshPrintExtra(ctl, " %-15s", _("Logging level: ")); + vshPrint(ctl, "%s\n", levelstr); + } + + if (optFilters || all) { + vshPrintExtra(ctl, " %-15s", _("Logging filters: ")); + vshPrint(ctl, "%s\n", filters); + } + + if (optOutputs || all) { + vshPrintExtra(ctl, " %-15s", _("Logging outputs: ")); + vshPrint(ctl, "%s\n", outputs); + } + + ret = true; + cleanup: + return ret; +} + +/* ---------------------- + * Command dmn-log-define + * ---------------------- + */ +static const vshCmdInfo info_dmn_log_define[] = { + {.name = "help", + .data = N_("change daemon's logging settings") + }, + {.name = "desc", + .data = N_("Defines and installs a new set of logging settings on a daemon. " + "These include global logging level, logging filters and " + "logging outputs.") + }, + {.name = NULL} +}; + +static const vshCmdOptDef opts_dmn_log_define[] = { + {.name = "daemon", + .type = VSH_OT_DATA, + .flags = VSH_OFLAG_REQ, + .help = N_("name of the daemon the logging settings of which should be changed ") + }, + {.name = "outputs", + .type = VSH_OT_STRING, + .help = N_("comma separated list of logging outputs") + }, + {.name = "filters", + .type = VSH_OT_STRING, + .help = N_("comma separated list of logging filters") + }, + {.name = "level", + .type = VSH_OT_INT, + .help = N_("logging level") + }, + {.name = NULL} +}; + +static bool +cmdDmnLogDefine(vshControl *ctl, const vshCmd *cmd) +{ + bool ret = false; + const char *filters = NULL; + const char *outputs = NULL; + unsigned int level = 0; + bool optOutputs = vshCommandOptBool(cmd, "outputs"); + bool optFilters = vshCommandOptBool(cmd, "filters"); + bool optLevel = vshCommandOptBool(cmd, "level"); + vshAdmControlPtr priv = ctl->privData; + + if (!(optOutputs + optFilters + optLevel)) { + vshError(ctl, _("At least one of options --outputs, --filters, " + "--level is mandatory")); + goto cleanup; + } + + if (optLevel && + (vshCommandOptUInt(ctl, cmd, "level", &level) < 0 || + virAdmConnectSetLoggingLevel(priv->conn, level, 0) < 0)) { + vshError(ctl, _("Unable to change daemon logging settings")); + goto cleanup; + } + + if (optFilters && + (vshCommandOptStringReq(ctl, cmd, "filters", &filters) < 0 || + virAdmConnectSetLoggingFilters(priv->conn, filters, 0) < 0)) { + vshError(ctl, _("Unable to change daemon logging settings")); + goto cleanup; + } + + if (optOutputs && + (vshCommandOptStringReq(ctl, cmd, "outputs", &outputs) < 0 || + virAdmConnectSetLoggingOutputs(priv->conn, outputs, 0) < 0)) { + vshError(ctl, _("Unable to change daemon logging settings")); + goto cleanup; + } + + ret = true; + cleanup: + return ret; +} + static void * vshAdmConnectionHandler(vshControl *ctl) { @@ -1059,6 +1251,12 @@ static const vshCmdDef monitoringCmds[] = { .info = info_client_info, .flags = 0 }, + {.name = "dmn-log-info", + .handler = cmdDmnLogInfo, + .opts = opts_dmn_log_info, + .info = info_dmn_log_info, + .flags = 0 + }, {.name = NULL} }; @@ -1069,6 +1267,12 @@ static const vshCmdDef managementCmds[] = { .info = info_srv_threadpool_set, .flags = 0 }, + {.name = "dmn-log-define", + .handler = cmdDmnLogDefine, + .opts = opts_dmn_log_define, + .info = info_dmn_log_define, + .flags = 0 + }, {.name = NULL} }; -- 2.4.11 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list