[libvirt] [PATCHv2 2/5] virsh: Add domhostname
Daniel P. Berrange
berrange at redhat.com
Wed Jul 18 20:19:42 UTC 2012
On Sun, Jul 15, 2012 at 11:45:06PM +0200, Guido Günther wrote:
> to query the guest's hostname.
> ---
> tools/virsh.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
> tools/virsh.pod | 4 ++++
> 2 files changed, 48 insertions(+)
>
> diff --git a/tools/virsh.c b/tools/virsh.c
> index f9fe4b1..7c20202 100644
> --- a/tools/virsh.c
> +++ b/tools/virsh.c
> @@ -14133,6 +14133,49 @@ cmdTTYConsole(vshControl *ctl, const vshCmd *cmd)
> }
>
> /*
> + * "domhostname" command
> + */
> +static const vshCmdInfo info_domhostname[] = {
> + {"help", N_("print the domain's hostname")},
> + {"desc", ""},
> + {NULL, NULL}
> +};
> +
> +static const vshCmdOptDef opts_domhostname[] = {
> + {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
> + {NULL, 0, 0, NULL}
> +};
> +
> +static bool
> +cmdDomHostname(vshControl *ctl, const vshCmd *cmd)
> +{
> + char *hostname;
> + virDomainPtr dom;
> + bool ret = false;
> +
> + if (!vshConnectionUsability(ctl, ctl->conn))
> + return false;
> +
> + if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
> + return false;
> +
> + hostname = virDomainGetHostname(dom, 0);
> + if (hostname == NULL) {
> + vshError(ctl, "%s", _("failed to get hostname"));
> + goto error;
> + }
> +
> + vshPrint(ctl, "%s\n", hostname);
> + ret = true;
> +
> +error:
> + VIR_FREE(hostname);
> + virDomainFree(dom);
> + return ret;
> +}
> +
> +
> +/*
> * "attach-device" command
> */
> static const vshCmdInfo info_attach_device[] = {
> @@ -18171,6 +18214,7 @@ static const vshCmdDef domManagementCmds[] = {
> {"detach-interface", cmdDetachInterface, opts_detach_interface,
> info_detach_interface, 0},
> {"domdisplay", cmdDomDisplay, opts_domdisplay, info_domdisplay, 0},
> + {"domhostname", cmdDomHostname, opts_domhostname, info_domhostname, 0},
> {"domid", cmdDomid, opts_domid, info_domid, 0},
> {"domif-setlink", cmdDomIfSetLink, opts_domif_setlink, info_domif_setlink, 0},
> {"domiftune", cmdDomIftune, opts_domiftune, info_domiftune, 0},
> diff --git a/tools/virsh.pod b/tools/virsh.pod
> index 4bddf15..dc318ef 100644
> --- a/tools/virsh.pod
> +++ b/tools/virsh.pod
> @@ -826,6 +826,10 @@ Output a URI which can be used to connect to the graphical display of the
> domain via VNC, SPICE or RDP. If I<--include-password> is specified, the
> SPICE channel password will be included in the URI.
>
> +=item B<domhostname> I<domain-id>
> +
> +Returns the hostname of a domain.
> +
> =item B<dominfo> I<domain-id>
>
> Returns basic information about the domain.
ACK
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|
More information about the libvir-list
mailing list