[libvirt] [PATCH] virsh: domdisplay: if listen is 0.0.0.0 or [::] print address from URI

Peter Krempa pkrempa at redhat.com
Wed Jun 8 09:00:56 UTC 2016


On Mon, May 30, 2016 at 16:45:32 +0200, Pavel Hrdina wrote:
> Currently if a guest has listen address 0.0.0.0 or [::] and you run
> "virsh domdisplay $domain" you always get "spice://localhost:$port".
> 
> We want to print better address if someone is connected from a different
> computer using "virsh -c qemu+ssh://some.host/system".  This patch fixes the
> behavior of virsh to print in this case "spice://some.host:$port".
> 
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1332446
> 
> Signed-off-by: Pavel Hrdina <phrdina at redhat.com>
> ---
>  tools/virsh-domain.c | 22 +++++++++++++++++++---
>  1 file changed, 19 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
> index 8d7ff61..93c7050 100644
> --- a/tools/virsh-domain.c
> +++ b/tools/virsh-domain.c
> @@ -57,6 +57,7 @@
>  #include "virtypedparam.h"
>  #include "virxml.h"
>  #include "virsh-nodedev.h"
> +#include "viruri.h"
>  
>  /* Gnulib doesn't guarantee SA_SIGINFO support.  */
>  #ifndef SA_SIGINFO
> @@ -10617,6 +10618,23 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
>              VIR_FREE(xpath);
>          }
>  
> +        /* If listen_addr is 0.0.0.0 or [::] we should try to parse URI and set
> +         * listen_addr based on current URI. */
> +        if (listen_addr) {
> +            if (virSocketAddrParse(&addr, listen_addr, AF_UNSPEC) > 0 &&
> +                virSocketAddrIsWildcard(&addr)) {
> +
> +                virURIPtr uri = virURIParse(ctl->connname);

ctl->conname contains the string that the user passed on the
commandline. Sice we are supporting aliases present in the config file
the string may be translated to something completely different and thus
can't be used as an uri here.

You need to extract the actual virsh connection from
((virshControlPtr)(ctl->privData))->dconn and then call virConnectGetURI
to get the actual URI.




More information about the libvir-list mailing list