From nobody Sun Apr 28 19:53:52 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 1496081387055326.70475567089375; Mon, 29 May 2017 11:09:47 -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 BE68261B9F; Mon, 29 May 2017 18:09:43 +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 D9D67189B5; Mon, 29 May 2017 18:09:41 +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 C2D374BB74; Mon, 29 May 2017 18:09:35 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v4TI9Xx2011023 for ; Mon, 29 May 2017 14:09:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id BD49618100; Mon, 29 May 2017 18:09:33 +0000 (UTC) Received: from mx1.redhat.com (ext-mx09.extmail.prod.ext.phx2.redhat.com [10.5.110.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AEB0517BAD; Mon, 29 May 2017 18:09:31 +0000 (UTC) Received: from mail-qk0-f194.google.com (mail-qk0-f194.google.com [209.85.220.194]) (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 796624E4CD; Mon, 29 May 2017 18:09:30 +0000 (UTC) Received: by mail-qk0-f194.google.com with SMTP id v195so2018462qka.2; Mon, 29 May 2017 11:09:30 -0700 (PDT) Received: from localhost.localdomain (athens-public-sb2-ctrl1.cpmc.columbia.edu. [156.111.111.160]) by smtp.googlemail.com with ESMTPSA id y188sm6472981qkb.49.2017.05.29.11.09.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 29 May 2017 11:09:29 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BE68261B9F Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx10.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 BE68261B9F Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Hy/O5Y6X" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 796624E4CD Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=srwx4096@gmail.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 796624E4CD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=h/ebj2LmqWr9CeOfaW1De2yGYPZVU/3EDwcMNsDmsP8=; b=Hy/O5Y6Xecl/3mBMAoDAJzZYBVeTbF6Kxt3u43PKJsZLaBsFd62W3NMTRFiDski6H1 4wefasPzQF+QwYkisTuRGLwygzFmF88gueWqEcfxx1BKb0zRwDd6jl9oUKI2N2G+hVA+ nTmwE+JT/Yi9XkRCO+Tha9iwOvbdSlmIGBuFk8LQduPSvXexeoO4KcYylm+7SYQckXUE GSGthgG7jjIq0bl1dWnhBRGiS2wXXKznV5XLu3klnWAt/EjJ7zBWSSIjkM6lbDPn1yvW pOQaA4GHsngrbRmPZgV5tFq/5xHID1igO2wRZpJsgqsxG+sGbN2m4iQVG1DyjYYtwFzZ b0Cg== 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:in-reply-to :references; bh=h/ebj2LmqWr9CeOfaW1De2yGYPZVU/3EDwcMNsDmsP8=; b=MQkk+4pKinxYGSXQnzU9j3hcRdCSOK1h5lKR4YOU0jpuXrrW5UlDHytm8gbmcGYHod lWWd0ypYKrMCbAiyO4OrkIn3n6DI/QWh66lPMyAs/5pxtLjCfCSrPtC79tnV4aPetJG/ 0M0Klpfi/UgUOzEY8LZjhbe1k56rZRndk+9u3SlXiGC8FqZUkFnoKdza7pPNcPDXgVmK N9FzES/Mo3G4kqsPpeEQBb0Mo3h6aPsPjJSZIMstjP/AVRwXS3QS6LnDPPxYYhSxOd9C EiKlqODq79gOqD5GWzMhAouWoZ7xWJquX4Ks1QKLD+NByqDSJ37HbHiCJv6+mBQWUjQu 0U6Q== X-Gm-Message-State: AODbwcBKbawM+QJ9MrcBt2yTjeUaykfrFdW1XjNdqCw4hxrR+ASuAxnL z3pylhxwvMticTAW X-Received: by 10.55.43.93 with SMTP id r90mr17131448qkh.196.1496081369665; Mon, 29 May 2017 11:09:29 -0700 (PDT) From: Daniel Liu To: libvir-list@redhat.com Date: Mon, 29 May 2017 14:08:53 -0400 Message-Id: <20170529180853.4341-1-srwx4096@gmail.com> In-Reply-To: <[libvirt] [PATCH] virsh: add --domain option for domain-to-native> References: <[libvirt] [PATCH] virsh: add --domain option for domain-to-native> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 29 May 2017 18:09:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 29 May 2017 18:09:30 +0000 (UTC) for IP:'209.85.220.194' DOMAIN:'mail-qk0-f194.google.com' HELO:'mail-qk0-f194.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.194 mail-qk0-f194.google.com 209.85.220.194 mail-qk0-f194.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.38 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-loop: libvir-list@redhat.com Cc: mkletzan@redhat.com, mprivozn@redhat.com, Daniel Liu Subject: [libvirt] [PATCH v2] 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.39]); Mon, 29 May 2017 18:09:45 +0000 (UTC) X-ZohoMail-DKIM: fail (Computed bodyhash is different from the expected one) 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 | 52 ++++++++++++++++++++++++++++++++++++++++--------= ---- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index ccb514ef9..929f9c896 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,54 @@ 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 *domain =3D NULL; + 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 || + vshCommandOptStringReq(ctl, cmd, "domain", &domain) < 0) return false; =20 - if (virFileReadAll(xmlFile, VSH_MAX_XML_FILE, &xmlData) < 0) + VSH_EXCLUSIVE_OPTIONS_VAR(domain, xml); + + if (domain) { + if (!(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; + } + + if (!xmlData) { + vshError(ctl, "%s", + _("need either domain (ID, UUID, or name) or domain XML c= onfiguration file path")); return false; + } =20 - configData =3D virConnectDomainXMLToNative(priv->conn, format, xmlData= , flags); - if (configData !=3D NULL) { - vshPrint(ctl, "%s", configData); - VIR_FREE(configData); + if (!(configData =3D virConnectDomainXMLToNative(priv->conn, format, x= mlData, flags))) { + vshError(ctl, "%s", + _("convert from domain XML to native command failed")); + goto cleanup; } else { - ret =3D false; + vshPrint(ctl, "%s", configData); + ret =3D true; } =20 + cleanup: + virshDomainFree(dom); VIR_FREE(xmlData); + VIR_FREE(configData); return ret; } =20 --=20 2.13.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list