[libvirt] [PATCH] virsh: cmdConsole: make --domain optional

Ján Tomko posted 1 patch 5 years ago
Test syntax-check passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/6981cc5ba7df8157442f1bbba30559525794d467.1554145474.git.jtomko@redhat.com
tools/virsh-domain.c | 25 ++++++++++++++++++++++++-
1 file changed, 24 insertions(+), 1 deletion(-)
[libvirt] [PATCH] virsh: cmdConsole: make --domain optional
Posted by Ján Tomko 5 years ago
In the absence of a domain parameter, console the user instead.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
---
 tools/virsh-domain.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index afcd0a5f8d..de41f6312d 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -49,6 +49,7 @@
 #include "virsh-console.h"
 #include "virsh-domain-monitor.h"
 #include "virerror.h"
+#include "virrandom.h"
 #include "virtime.h"
 #include "virtypedparam.h"
 #include "virxml.h"
@@ -2972,7 +2973,7 @@ static const vshCmdInfo info_console[] = {
 };
 
 static const vshCmdOptDef opts_console[] = {
-    VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE),
+    VIRSH_COMMON_OPT_DOMAIN_OT_STRING_FULL(0, VIR_CONNECT_LIST_DOMAINS_ACTIVE),
     {.name = "devname", /* sc_prohibit_devname */
      .type = VSH_OT_STRING,
      .help = N_("character device name")
@@ -3023,6 +3024,23 @@ cmdRunConsole(vshControl *ctl, virDomainPtr dom,
     return ret;
 }
 
+static const char *
+constellation_phrases[] = {
+    "Everything is going to be all right.",
+    "Things are going to work out in the end.",
+    "Imagine pleasant nonsense", /* https://www.instagram.com/p/BuRfmkrBigI/ */
+    "Ursa Major",
+    "There, there.",
+};
+
+static void
+cmdConsoleUser(vshControl *ctl)
+{
+    uint32_t die = virRandomInt(ARRAY_CARDINALITY(constellation_phrases));
+
+    vshPrintExtra(ctl, "%s", constellation_phrases[die]);
+}
+
 static bool
 cmdConsole(vshControl *ctl, const vshCmd *cmd)
 {
@@ -3033,6 +3051,11 @@ cmdConsole(vshControl *ctl, const vshCmd *cmd)
     unsigned int flags = 0;
     const char *name = NULL;
 
+    if (!vshCommandOptBool(cmd, "domain")) {
+        cmdConsoleUser(ctl);
+        return true;
+    }
+
     if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
         return false;
 
-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] virsh: cmdConsole: make --domain optional
Posted by Eric Blake 5 years ago
On 4/1/19 2:04 PM, Ján Tomko wrote:
> In the absence of a domain parameter, console the user instead.
> 
> Signed-off-by: Ján Tomko <jtomko@redhat.com>
> ---
>  tools/virsh-domain.c | 25 ++++++++++++++++++++++++-
>  1 file changed, 24 insertions(+), 1 deletion(-)

Missing doc updates to virsh.pod. How is a user going to know they can
be consoled?


> +static const char *
> +constellation_phrases[] = {

s/constellation/consolation/ ?

> +    "Everything is going to be all right.",
> +    "Things are going to work out in the end.",
> +    "Imagine pleasant nonsense", /* https://www.instagram.com/p/BuRfmkrBigI/ */
> +    "Ursa Major",

except that you did mix in a constellation phrase.  Hmm.  Now I'm going
to have to run this command to resolve the confusion that has arisen in
my mind...

> +    "There, there.",
> +};
> +


-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list