提交 0f814c0f 编写于 作者: J Julio Faracco 提交者: Michal Privoznik

virsh: Expose virDomainGetHostnameFlags

Our virsh already has 'domhostname' command. Add '--source'
argument to it so that users can chose between 'lease' and
'agent' sources. Also, implement completer for the argument.
Signed-off-by: NJulio Faracco <jcfaracco@gmail.com>
Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
Reviewed-by: NErik Skultety <eskultet@redhat.com>
上级 1becd935
...@@ -1797,10 +1797,15 @@ domhostname ...@@ -1797,10 +1797,15 @@ domhostname
.. code-block:: .. code-block::
domhostname domain domhostname domain [--source lease|agent]
Returns the hostname of a domain, if the hypervisor makes it available. Returns the hostname of a domain, if the hypervisor makes it available.
The *--source* argument specifies what data source to use for the
hostnames, currently 'lease' to read DHCP leases or 'agent' to query
the guest OS via an agent. If unspecified, driver returns the default
method available (some drivers support only one type of source).
domid domid
----- -----
......
...@@ -316,3 +316,22 @@ virshDomainInterfaceAddrSourceCompleter(vshControl *ctl G_GNUC_UNUSED, ...@@ -316,3 +316,22 @@ virshDomainInterfaceAddrSourceCompleter(vshControl *ctl G_GNUC_UNUSED,
return ret; return ret;
} }
char **
virshDomainHostnameSourceCompleter(vshControl *ctl G_GNUC_UNUSED,
const vshCmd *cmd G_GNUC_UNUSED,
unsigned int flags)
{
char **ret = NULL;
size_t i;
virCheckFlags(0, NULL);
ret = g_new0(typeof(*ret), VIRSH_DOMAIN_HOSTNAME_SOURCE_LAST + 1);
for (i = 0; i < VIRSH_DOMAIN_HOSTNAME_SOURCE_LAST; i++)
ret[i] = g_strdup(virshDomainHostnameSourceTypeToString(i));
return ret;
}
...@@ -58,3 +58,7 @@ char ** ...@@ -58,3 +58,7 @@ char **
virshDomainInterfaceAddrSourceCompleter(vshControl *ctl, virshDomainInterfaceAddrSourceCompleter(vshControl *ctl,
const vshCmd *cmd, const vshCmd *cmd,
unsigned int flags); unsigned int flags);
char ** virshDomainHostnameSourceCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);
...@@ -11742,20 +11742,55 @@ static const vshCmdInfo info_domhostname[] = { ...@@ -11742,20 +11742,55 @@ static const vshCmdInfo info_domhostname[] = {
static const vshCmdOptDef opts_domhostname[] = { static const vshCmdOptDef opts_domhostname[] = {
VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE), VIRSH_COMMON_OPT_DOMAIN_FULL(VIR_CONNECT_LIST_DOMAINS_ACTIVE),
{.name = "source",
.type = VSH_OT_STRING,
.flags = VSH_OFLAG_NONE,
.completer = virshDomainHostnameSourceCompleter,
.help = N_("address source: 'lease' or 'agent'")},
{.name = NULL} {.name = NULL}
}; };
VIR_ENUM_IMPL(virshDomainHostnameSource,
VIRSH_DOMAIN_HOSTNAME_SOURCE_LAST,
"agent",
"lease");
static bool static bool
cmdDomHostname(vshControl *ctl, const vshCmd *cmd) cmdDomHostname(vshControl *ctl, const vshCmd *cmd)
{ {
char *hostname; char *hostname;
virDomainPtr dom; virDomainPtr dom;
bool ret = false; bool ret = false;
const char *sourcestr = NULL;
int flags = 0; /* Use default value. Drivers can have its own default. */
if (!(dom = virshCommandOptDomain(ctl, cmd, NULL))) if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
return false; return false;
hostname = virDomainGetHostname(dom, 0); if (vshCommandOptStringReq(ctl, cmd, "source", &sourcestr) < 0)
goto error;
if (sourcestr) {
int source = virshDomainHostnameSourceTypeFromString(sourcestr);
if (source < 0) {
vshError(ctl, _("Unknown data source '%s'"), sourcestr);
goto error;
}
switch ((virshDomainHostnameSource) source) {
case VIRSH_DOMAIN_HOSTNAME_SOURCE_AGENT:
flags |= VIR_DOMAIN_GET_HOSTNAME_AGENT;
break;
case VIRSH_DOMAIN_HOSTNAME_SOURCE_LEASE:
flags |= VIR_DOMAIN_GET_HOSTNAME_LEASE;
break;
case VIRSH_DOMAIN_HOSTNAME_SOURCE_LAST:
break;
}
}
hostname = virDomainGetHostname(dom, flags);
if (hostname == NULL) { if (hostname == NULL) {
vshError(ctl, "%s", _("failed to get hostname")); vshError(ctl, "%s", _("failed to get hostname"));
goto error; goto error;
......
...@@ -30,4 +30,12 @@ typedef struct virshDomainEventCallback virshDomainEventCallback; ...@@ -30,4 +30,12 @@ typedef struct virshDomainEventCallback virshDomainEventCallback;
extern virshDomainEventCallback virshDomainEventCallbacks[]; extern virshDomainEventCallback virshDomainEventCallbacks[];
typedef enum {
VIRSH_DOMAIN_HOSTNAME_SOURCE_AGENT,
VIRSH_DOMAIN_HOSTNAME_SOURCE_LEASE,
VIRSH_DOMAIN_HOSTNAME_SOURCE_LAST
} virshDomainHostnameSource;
VIR_ENUM_DECL(virshDomainHostnameSource);
extern const vshCmdDef domManagementCmds[]; extern const vshCmdDef domManagementCmds[];
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册