diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c index 0ca53e4..1c3ec37 100644 --- a/tools/virsh-domain-monitor.c +++ b/tools/virsh-domain-monitor.c @@ -1769,6 +1769,14 @@ static const vshCmdOptDef opts_list[] = { .type = VSH_OT_BOOL, .help = N_("show domain title") }, + {.name = "description", + .type = VSH_OT_BOOL, + .help = N_("show domain description") + }, + {.name = "details", + .type = VSH_OT_BOOL, + .help = N_("show domain details") + }, {.name = NULL} }; @@ -1780,6 +1788,8 @@ cmdList(vshControl *ctl, const vshCmd *cmd) { bool managed = vshCommandOptBool(cmd, "managed-save"); bool optTitle = vshCommandOptBool(cmd, "title"); + bool optDescription = vshCommandOptBool(cmd, "description"); + bool optDetails = vshCommandOptBool(cmd, "details"); bool optTable = vshCommandOptBool(cmd, "table"); bool optUUID = vshCommandOptBool(cmd, "uuid"); bool optName = vshCommandOptBool(cmd, "name"); @@ -1822,6 +1832,9 @@ cmdList(vshControl *ctl, const vshCmd *cmd) VSH_EXCLUSIVE_OPTIONS("table", "name"); VSH_EXCLUSIVE_OPTIONS("table", "uuid"); + VSH_EXCLUSIVE_OPTIONS("description", "title"); + VSH_EXCLUSIVE_OPTIONS("details", "title"); + VSH_EXCLUSIVE_OPTIONS("details", "description"); if (!optUUID && !optName) optTable = true; @@ -1831,9 +1844,19 @@ cmdList(vshControl *ctl, const vshCmd *cmd) /* print table header in legacy mode */ if (optTable) { - if (optTitle) + if (optTitle || optDescription) vshPrintExtra(ctl, " %-5s %-30s %-10s %-20s\n%s\n", - _("Id"), _("Name"), _("State"), _("Title"), + _("Id"), _("Name"), _("State"), + optTitle ? _("Title") : _("Description"), + "-----------------------------------------" + "-----------------------------------------"); + else if (optDetails) + vshPrintExtra(ctl, " %-5s %-30s %-10s %-13s %-13s %5s %9s %9s %s\n%s\n", + _("Id"), _("Name"), _("State"), + _("Autostart"), _("Persistent"), + _("vCPU"), _("Memory"), _("Snapshots"), + _("Time"), + "-----------------------------------------" "-----------------------------------------" "-----------------------------------------"); else @@ -1862,8 +1885,8 @@ cmdList(vshControl *ctl, const vshCmd *cmd) virDomainHasManagedSaveImage(dom, 0) > 0) state = -2; - if (optTitle) { - if (!(title = virshGetDomainDescription(ctl, dom, true, 0))) + if (optTitle || optDescription) { + if (!(title = virshGetDomainDescription(ctl, dom, optTitle, 0))) goto cleanup; vshPrint(ctl, " %-5s %-30s %-10s %-20s\n", id_buf, @@ -1873,6 +1896,60 @@ cmdList(vshControl *ctl, const vshCmd *cmd) title); VIR_FREE(title); + } else if (optDetails) { + int autostart; + int persistent; + int vcpu = -1; + int memory = -1; + int nsnap; + long long seconds = 0; + unsigned int nseconds = 0; + + virDomainInfo info; + + if (virDomainGetAutostart(dom, &autostart) < 0) { + autostart = -1; + } + persistent = virDomainIsPersistent(dom); + + if (virDomainGetInfo(dom, &info) == 0) { + vcpu = info.nrVirtCpu; + memory = info.memory / 1024; + } + + nsnap = virDomainSnapshotNum(dom, 0); + + char timestr[100]; + if (state == VIR_DOMAIN_RUNNING) { + if (virDomainGetTime(dom, &seconds, &nseconds, 0) < 0) { + strcpy(timestr, _("unknown")); + } else { + time_t cur_time = seconds; + struct tm time_info; + + if (!gmtime_r(&cur_time, &time_info)) { + vshError(ctl, _("Unable to format time")); + goto cleanup; + } + strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", &time_info); + } + } else { + strcpy(timestr, ""); + } + + vshPrint(ctl, " %-5s %-30s %-10s %-13s %-13s %5d %9d %9d %s\n", id_buf, + virDomainGetName(dom), + state == -2 ? _("saved") + : virshDomainStateToString(state), + autostart == 1 ? _("yes") : + autostart == 0 ? _("no") : _("unknown"), + persistent == 1 ? _("yes") : + persistent == 0 ? _("no") : _("unknown"), + vcpu, memory, + nsnap, + timestr + ); + } else { vshPrint(ctl, " %-5s %-30s %s\n", id_buf, virDomainGetName(dom),