From: Radoslaw Smigielski <rsmigiel@redhat.com>
The '--format' option of 'domxml-from-native' command specifies the
native guest configuration format to import.
Partially-fixes: https://gitlab.com/libvirt/libvirt/-/work_items/9
Signed-off-by: Radoslaw Smigielski <rsmigiel@redhat.com>
---
tools/virsh-completer-domain.c | 36 ++++++++++++++++++++++++++++++++++
tools/virsh-completer-domain.h | 5 +++++
tools/virsh-domain.c | 1 +
3 files changed, 42 insertions(+)
diff --git a/tools/virsh-completer-domain.c b/tools/virsh-completer-domain.c
index 4c0ddb01d855..8154ba8d622c 100644
--- a/tools/virsh-completer-domain.c
+++ b/tools/virsh-completer-domain.c
@@ -1145,3 +1145,39 @@ virshDomainDisplayTypeCompleter(vshControl *ctl G_GNUC_UNUSED,
return vshCommaStringListComplete(NULL, types);
}
+
+
+char **
+virshDomainXMLNativeFormatCompleter(vshControl *ctl,
+ const vshCmd *cmd G_GNUC_UNUSED,
+ unsigned int flags)
+{
+ virshControl *priv = ctl->privData;
+ const char *hvType = NULL;
+ const char **formats = NULL;
+ static const char *xenFormats[] = {"xen-xl", "xen-xm", NULL};
+ static const char *lxcFormats[] = {"lxc-tools", NULL};
+ static const char *vmxFormats[] = {"vmware-vmx", NULL};
+ static const char *bhyveFormats[] = {"bhyve-argv", NULL};
+
+ virCheckFlags(0, NULL);
+
+ if (!priv->conn || virConnectIsAlive(priv->conn) <= 0)
+ return NULL;
+
+ if (!(hvType = virConnectGetType(priv->conn)))
+ return NULL;
+
+ if (STREQ(hvType, "Xen"))
+ formats = xenFormats;
+ else if (STREQ(hvType, "LXC"))
+ formats = lxcFormats;
+ else if (STREQ(hvType, "VMware") || STREQ(hvType, "ESX"))
+ formats = vmxFormats;
+ else if (STREQ(hvType, "BHYVE"))
+ formats = bhyveFormats;
+ else
+ return NULL;
+
+ return vshCommaStringListComplete(NULL, formats);
+}
diff --git a/tools/virsh-completer-domain.h b/tools/virsh-completer-domain.h
index 3aab7bedae20..40de90afb79f 100644
--- a/tools/virsh-completer-domain.h
+++ b/tools/virsh-completer-domain.h
@@ -209,3 +209,8 @@ char **
virshDomainDisplayTypeCompleter(vshControl *ctl,
const vshCmd *cmd,
unsigned int flags);
+
+char **
+virshDomainXMLNativeFormatCompleter(vshControl *ctl,
+ const vshCmd *cmd,
+ unsigned int flags);
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index a546532b7dd2..abe3d0b3451e 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -10916,6 +10916,7 @@ static const vshCmdOptDef opts_domxmlfromnative[] = {
.type = VSH_OT_STRING,
.positional = true,
.required = true,
+ .completer = virshDomainXMLNativeFormatCompleter,
.help = N_("source config data format")
},
{.name = "config",
--
2.54.0