mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
virsh: add [--domain DOMAIN] option to domxml-to-native DOMAIN COMMAND
The option allows someone to run domain-to-native on already existing domain without the need of supplying their XML. It is basically wrapper around 'virsh dumpxml | virsh domxml-to-native /dev/stdin'. Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=835476 Signed-off-by: Daniel Liu <srwx4096@gmail.com> Reviewed-by: Martin Kletzander <mkletzan@redhat.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
This commit is contained in:
parent
5431055d2b
commit
41eb92783e
@ -9856,9 +9856,13 @@ static const vshCmdOptDef opts_domxmltonative[] = {
|
|||||||
.flags = VSH_OFLAG_REQ,
|
.flags = VSH_OFLAG_REQ,
|
||||||
.help = N_("target config data type format")
|
.help = N_("target config data type format")
|
||||||
},
|
},
|
||||||
|
{.name = "domain",
|
||||||
|
.type = VSH_OT_DATA,
|
||||||
|
.flags = VSH_OFLAG_REQ_OPT,
|
||||||
|
.help = N_("domain name, id or uuid")
|
||||||
|
},
|
||||||
{.name = "xml",
|
{.name = "xml",
|
||||||
.type = VSH_OT_DATA,
|
.type = VSH_OT_DATA,
|
||||||
.flags = VSH_OFLAG_REQ,
|
|
||||||
.help = N_("xml data file to export from")
|
.help = N_("xml data file to export from")
|
||||||
},
|
},
|
||||||
{.name = NULL}
|
{.name = NULL}
|
||||||
@ -9867,30 +9871,51 @@ static const vshCmdOptDef opts_domxmltonative[] = {
|
|||||||
static bool
|
static bool
|
||||||
cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd)
|
cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd)
|
||||||
{
|
{
|
||||||
bool ret = true;
|
bool ret = false;
|
||||||
const char *format = NULL;
|
const char *format = NULL;
|
||||||
const char *xmlFile = NULL;
|
const char *xmlFile = NULL;
|
||||||
char *configData;
|
char *configData = NULL;
|
||||||
char *xmlData;
|
char *xmlData = NULL;
|
||||||
unsigned int flags = 0;
|
unsigned int flags = 0;
|
||||||
virshControlPtr priv = ctl->privData;
|
virshControlPtr priv = ctl->privData;
|
||||||
|
virDomainPtr dom = NULL;
|
||||||
|
|
||||||
if (vshCommandOptStringReq(ctl, cmd, "format", &format) < 0 ||
|
if (vshCommandOptStringReq(ctl, cmd, "format", &format) < 0 ||
|
||||||
vshCommandOptStringReq(ctl, cmd, "xml", &xmlFile) < 0)
|
vshCommandOptStringReq(ctl, cmd, "xml", &xmlFile) < 0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (virFileReadAll(xmlFile, VSH_MAX_XML_FILE, &xmlData) < 0)
|
VSH_EXCLUSIVE_OPTIONS("domain", "xml");
|
||||||
return false;
|
|
||||||
|
|
||||||
configData = virConnectDomainXMLToNative(priv->conn, format, xmlData, flags);
|
if (vshCommandOptBool(cmd, "domain") &&
|
||||||
if (configData != NULL) {
|
(!(dom = virshCommandOptDomain(ctl, cmd, NULL))))
|
||||||
vshPrint(ctl, "%s", configData);
|
return false;
|
||||||
VIR_FREE(configData);
|
|
||||||
|
if (dom) {
|
||||||
|
xmlData = virDomainGetXMLDesc(dom, flags);
|
||||||
|
} else if (xmlFile) {
|
||||||
|
if (virFileReadAll(xmlFile, VSH_MAX_XML_FILE, &xmlData) < 0)
|
||||||
|
goto cleanup;
|
||||||
} else {
|
} else {
|
||||||
ret = false;
|
vshError(ctl, "%s", _("need either domain or domain XML"));
|
||||||
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!xmlData) {
|
||||||
|
vshError(ctl, "%s", _("failed to retrieve XML"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(configData = virConnectDomainXMLToNative(priv->conn, format, xmlData, flags))) {
|
||||||
|
goto cleanup;
|
||||||
|
} else {
|
||||||
|
vshPrint(ctl, "%s", configData);
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
virshDomainFree(dom);
|
||||||
VIR_FREE(xmlData);
|
VIR_FREE(xmlData);
|
||||||
|
VIR_FREE(configData);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1440,13 +1440,19 @@ the I<format> argument must be B<qemu-argv>. For Xen hypervisor, the
|
|||||||
I<format> argument may be B<xen-xm>, B<xen-xl>, or B<xen-sxpr>. For
|
I<format> argument may be B<xen-xm>, B<xen-xl>, or B<xen-sxpr>. For
|
||||||
LXC hypervisor, the I<format> argument must be B<lxc-tools>.
|
LXC hypervisor, the I<format> argument must be B<lxc-tools>.
|
||||||
|
|
||||||
=item B<domxml-to-native> I<format> I<xml>
|
=item B<domxml-to-native> I<format>
|
||||||
|
{ [I<--xml>] I<xml> | I<--domain> I<domain-name-or-id-or-uuid> }
|
||||||
|
|
||||||
Convert the file I<xml> in domain XML format to the native guest
|
Convert the file I<xml> into domain XML format or convert an existing
|
||||||
configuration format named by I<format>. For QEMU/KVM hypervisor,
|
I<--domain> to the native guest configuration format named by I<format>.
|
||||||
the I<format> argument must be B<qemu-argv>. For Xen hypervisor, the
|
The I<xml> and I<--domain> arguments are mutually exclusive.
|
||||||
I<format> argument may be B<xen-xm>, B<xen-xl>, or B<xen-sxpr>. For
|
|
||||||
LXC hypervisor, the I<format> argument must be B<lxc-tools>.
|
For the QEMU/KVM hypervisor, the I<format> argument must be B<qemu-argv>.
|
||||||
|
|
||||||
|
For the Xen hypervisor, the I<format> argument may be B<xen-xm>, B<xen-xl>,
|
||||||
|
or B<xen-sxpr>.
|
||||||
|
|
||||||
|
For the LXC hypervisor, the I<format> argument must be B<lxc-tools>.
|
||||||
|
|
||||||
=item B<dump> I<domain> I<corefilepath> [I<--bypass-cache>]
|
=item B<dump> I<domain> I<corefilepath> [I<--bypass-cache>]
|
||||||
{ [I<--live>] | [I<--crash>] | [I<--reset>] } [I<--verbose>] [I<--memory-only>]
|
{ [I<--live>] | [I<--crash>] | [I<--reset>] } [I<--verbose>] [I<--memory-only>]
|
||||||
|
Loading…
Reference in New Issue
Block a user