Finally, now that all APIs have been introduced, wire them up to virt-admin
and introduce dmn-log-info and dmn-log-define commands.
---
tools/virt-admin.c | 208 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 208 insertions(+)
diff --git a/tools/virt-admin.c b/tools/virt-admin.c
index edb8690..9389ffe 100644
--- a/tools/virt-admin.c
+++ b/tools/virt-admin.c
@@ -353,6 +353,197 @@ cmdSrvList(vshControl *ctl, const vshCmd *cmd ATTRIBUTE_UNUSED)
return ret;
}
+/* -------------------
+ * Command dmn-log-info
+ * -------------------
+ */
+static const vshCmdInfo info_dmn_log_info[] = {
+ {.name = "help",
+ .data = N_("view daemon current logging information")
+ },
+ {.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_("define 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)
{
@@ -652,12 +843,29 @@ static const vshCmdDef monitoringCmds[] = {
.info = info_srv_list,
.flags = 0
},
+ {.name = "dmn-log-info",
+ .handler = cmdDmnLogInfo,
+ .opts = opts_dmn_log_info,
+ .info = info_dmn_log_info,
+ .flags = 0
+ },
+ {.name = NULL}
+};
+
+static const vshCmdDef managementCmds[] = {
+ {.name = "dmn-log-define",
+ .handler = cmdDmnLogDefine,
+ .opts = opts_dmn_log_define,
+ .info = info_dmn_log_define,
+ .flags = 0
+ },
{.name = NULL}
};
static const vshCmdGrp cmdGroups[] = {
{"Virt-admin itself", "virt-admin", vshAdmCmds},
{"Monitoring commands", "monitor", monitoringCmds},
+ {"Management commands", "management", managementCmds},
{NULL, NULL, NULL}
};
--
2.4.3