From nobody Fri May 3 02:28:53 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; dkim=fail spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496243425117470.89396857332486; Wed, 31 May 2017 08:10:25 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id EA7303680E; Wed, 31 May 2017 15:10:22 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C2F848140C; Wed, 31 May 2017 15:10:22 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 2D5864BB7F; Wed, 31 May 2017 15:10:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4VFALX8023358 for ; Wed, 31 May 2017 11:10:21 -0400 Received: by smtp.corp.redhat.com (Postfix) id 35C9A5DC1F; Wed, 31 May 2017 15:10:21 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2C27117C3A; Wed, 31 May 2017 15:10:19 +0000 (UTC) Received: from mail-qk0-f196.google.com (mail-qk0-f196.google.com [209.85.220.196]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0B0C6C04B320; Wed, 31 May 2017 15:10:18 +0000 (UTC) Received: by mail-qk0-f196.google.com with SMTP id c206so2175679qkb.0; Wed, 31 May 2017 08:10:18 -0700 (PDT) Received: from localhost.localdomain ([156.111.111.218]) by smtp.googlemail.com with ESMTPSA id 8sm7776181qki.40.2017.05.31.08.10.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 May 2017 08:10:16 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com EA7303680E Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com EA7303680E Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ndADiHxX" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 0B0C6C04B320 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=srwx4096@gmail.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 0B0C6C04B320 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=iyMEb/q47Y05+pOlQWhaIpcWL7ga51x3J/W4gdH+Hmc=; b=ndADiHxX/uPPOrweGTLDXuwnzJp532RIoVp3FTDJb9S4azvgOZAabAYS7248mhhsPB 99h0Qr+ay/DBjQyTXiunhJ7YFBMBckJXqGJjV9nsVwGf5HYHNenZqHx1cFgpKPLFAY/T WHncKzbKRoRFsjwFXiw4BU5TD4DXccziQaqrFcgV7VC/c2KKqUi131HkukLCj9ibjIQw lTNixq5xFuBi583ILYQb/DXkvgZBm5i8Isgj9OQ35Z326e6STga5w45K60Vw4dt6Jf4a WV5loI3CYWt/kvC8zBs4DiFspaGos7kRztM9aPWbxHTfr8kr3dH7gR30Mi5GrceSCyk5 AYTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=iyMEb/q47Y05+pOlQWhaIpcWL7ga51x3J/W4gdH+Hmc=; b=h9ToaavfVA/5LvZ5dGLVViZrRMg9Hp/BNf3pFEBMZ4ULnlV+479n4jRuQeVEPyNnmO 87NQieyfJMlWHVfLuBh09RmCxqxnqTjk8WDJwTTBwhcP6xU0dD+WhZTdYZ1odkNhee2S KX+ZtjXKxtC0w5gkyDY+DC971RYOK4g4paD3abEAynLWLIXcxZFDF2Iqw2jxSXB0kIyU VWqj0/vZuPrpLHA9z6TjFWMkywWy6u7pa8ILzkveTRDuSjMlj5TwLRoKtYWGGQcOwqm+ 6R+CkyMhwvf370pknWUQ7D7Wk7ynR9WtSjBsimCB0CrgK8jNUhLIW6lI/OTUihGEK70+ 8/sw== X-Gm-Message-State: AODbwcBafgJRDLDqnPLpMZSb252ZMC9L9MTz4XTrHDLlm168AsmMDNvC Kk/z3OXkWJVgKc1u X-Received: by 10.55.143.198 with SMTP id r189mr27258200qkd.150.1496243417166; Wed, 31 May 2017 08:10:17 -0700 (PDT) From: Daniel Liu To: libvir-list@redhat.com Date: Wed, 31 May 2017 11:09:16 -0400 Message-Id: <20170531150916.98326-1-srwx4096@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 31 May 2017 15:10:18 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Wed, 31 May 2017 15:10:18 +0000 (UTC) for IP:'209.85.220.196' DOMAIN:'mail-qk0-f196.google.com' HELO:'mail-qk0-f196.google.com' FROM:'srwx4096@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.42 * (BAYES_50, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, SPF_PASS) 209.85.220.196 mail-qk0-f196.google.com 209.85.220.196 mail-qk0-f196.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: mkletzan@redhat.com, mprivozn@redhat.com, jcfaracco@gmail.com, pkrempa@redhat.com, Daniel Liu Subject: [libvirt] [PATCH v3] virsh: add [--domain DOMAIN] option to domxml-to-native DOMAIN COMMAND X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Wed, 31 May 2017 15:10:23 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" 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=3D835476 --- tools/virsh-domain.c | 53 +++++++++++++++++++++++++++++++++++++++---------= ---- tools/virsh.pod | 7 ++++--- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index ccb514ef9..db92c4478 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -9848,9 +9848,13 @@ static const vshCmdOptDef opts_domxmltonative[] =3D { .flags =3D VSH_OFLAG_REQ, .help =3D N_("target config data type format") }, + {.name =3D "domain", + .type =3D VSH_OT_DATA, + .flags =3D VSH_OFLAG_REQ_OPT, + .help =3D N_("domain name, id or uuid") + }, {.name =3D "xml", .type =3D VSH_OT_DATA, - .flags =3D VSH_OFLAG_REQ, .help =3D N_("xml data file to export from") }, {.name =3D NULL} @@ -9859,30 +9863,53 @@ static const vshCmdOptDef opts_domxmltonative[] =3D= { static bool cmdDomXMLToNative(vshControl *ctl, const vshCmd *cmd) { - bool ret =3D true; + bool ret =3D false; const char *format =3D NULL; - const char *xmlFile =3D NULL; - char *configData; - char *xmlData; + const char *xml =3D NULL; + char *xmlData =3D NULL; + char *configData =3D NULL; unsigned int flags =3D 0; virshControlPtr priv =3D ctl->privData; + virDomainPtr dom =3D NULL; =20 if (vshCommandOptStringReq(ctl, cmd, "format", &format) < 0 || - vshCommandOptStringReq(ctl, cmd, "xml", &xmlFile) < 0) + vshCommandOptStringReq(ctl, cmd, "xml", &xml) < 0) return false; =20 - if (virFileReadAll(xmlFile, VSH_MAX_XML_FILE, &xmlData) < 0) - return false; + VSH_EXCLUSIVE_OPTIONS("domain", "xml"); =20 - configData =3D virConnectDomainXMLToNative(priv->conn, format, xmlData= , flags); - if (configData !=3D NULL) { - vshPrint(ctl, "%s", configData); - VIR_FREE(configData); + if (vshCommandOptBool(cmd, "domain") && + (!(dom =3D virshCommandOptDomain(ctl, cmd, NULL)))) + return false; + + if (dom) { + xmlData =3D virDomainGetXMLDesc(dom, flags); + } else if (xml) { + if (virFileReadAll(xml, VSH_MAX_XML_FILE, &xmlData) < 0) + goto cleanup; } else { - ret =3D 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 =3D virConnectDomainXMLToNative(priv->conn, format, x= mlData, flags))) { + vshError(ctl, "%s", + _("convert from domain XML to native command failed")); + goto cleanup; + } else { + vshPrint(ctl, "%s", configData); + ret =3D true; } =20 + cleanup: + virshDomainFree(dom); VIR_FREE(xmlData); + VIR_FREE(configData); return ret; } =20 diff --git a/tools/virsh.pod b/tools/virsh.pod index aee964689..049c2f3c7 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1433,10 +1433,11 @@ the I argument must be B. For Xe= n hypervisor, the I argument may be B, B, or B. For LXC hypervisor, the I argument must be B. =20 -=3Ditem B I I +=3Ditem B I +{ I<--domain> I | [I<--xml>] I } =20 -Convert the file I in domain XML format to the native guest -configuration format named by I. For QEMU/KVM hypervisor, +Convert the file I in domain XML format or existing domain to the +native guest configuration format named by I. For QEMU/KVM hypervi= sor, the I argument must be B. For Xen hypervisor, the I argument may be B, B, or B. For LXC hypervisor, the I argument must be B. --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list