From nobody Mon Apr 29 08:23:50 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 1496416054848919.6288237136719; Fri, 2 Jun 2017 08:07:34 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C2C9AC049D59; Fri, 2 Jun 2017 15:07:30 +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 99D4917DE7; Fri, 2 Jun 2017 15:07:30 +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 31AF94BB74; Fri, 2 Jun 2017 15:07:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v52F54kj002124 for ; Fri, 2 Jun 2017 11:05:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6995D82460; Fri, 2 Jun 2017 15:05:04 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5D65E82473; Fri, 2 Jun 2017 15:04:59 +0000 (UTC) Received: from mail-qt0-f196.google.com (mail-qt0-f196.google.com [209.85.216.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 30F863DBDF; Fri, 2 Jun 2017 15:04:57 +0000 (UTC) Received: by mail-qt0-f196.google.com with SMTP id w1so5475964qtg.0; Fri, 02 Jun 2017 08:04:57 -0700 (PDT) Received: from pc ([156.111.218.80]) by smtp.gmail.com with ESMTPSA id v1sm14702633qtg.45.2017.06.02.08.04.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 02 Jun 2017 08:04:54 -0700 (PDT) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C2C9AC049D59 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx07.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 C2C9AC049D59 Authentication-Results: mx1.redhat.com; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nuNBnUA8" DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 30F863DBDF Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ext-mx06.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=srwx4096@gmail.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 30F863DBDF DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=SKMYMUVH1EZuFCOyhptN4l6GUK2XeKMxhDhkHc0UFmQ=; b=nuNBnUA8hnecGQuBlWCCI/sm9yXPu4xxPNC5idaMWIcJiruAvXqdOpRPiZzt38OGt0 0HP9ez7CrPyqu1AbEKPo/0qtfkFjSVvqUuYn+sIEyuvvEZW0Ad4cDXWuxVtaKI9yPL7P hNaFqzp/PqRp9kQYlG8HNsmX6LERFOBpkl54wPAoMjjjP3R90E9OsosjbmnY02P+VRmo ptYIzyu+vylvpLDAcT5mj5EVe9yQIFKrFow1CA90vLw/3VZeXpb9GX+b2lhS8t9Ezgx+ jtUCbfZ0Mkw9iGHC4kqCxnDg4PyOCfZnel7YKaiTEsWoO9C3rWsF7WAP/N1EivA7HIgS ovjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=SKMYMUVH1EZuFCOyhptN4l6GUK2XeKMxhDhkHc0UFmQ=; b=odAY0Mo4NK4VoTPbTgx4QpKV1NoiapXClHUsvMAnLnYj5e48ZOpsvXSSR8+FOidLWL Ojfjl5inX3MO0JJoOq4ZXOvEBKWdSQwwCbj91OXReOg269O+rJrMhmcAwMv8dwGNfQ9l GeI81GnUdJW2AijzTBYPFV0imfCEBQnKNh7ZkXEjGWtphIyv19YXDIZvvC6EydJ1xjN0 Q+6qUoAvjzP5M/LAI1Cbny2W6cAJeIGTTcJuQz3/5dt0vBUEBWHDPTu9oeZabPGWTJA2 gpOTFL6RP3pIKMpVAlADtyPsUzmzsrW/36WWy6FllslZ1NxZ9aFqnhBqt3XeTGGMsqDW 6/pA== X-Gm-Message-State: AKS2vOyNFfsWM/ZaqDmPAAUrdKi7POdTJ3Hw1kuJQsm/qvy6PqdRPPVS nxXGrc1kPTz/9wy9 X-Received: by 10.200.42.107 with SMTP id l40mr9808647qtl.32.1496415894806; Fri, 02 Jun 2017 08:04:54 -0700 (PDT) Date: Fri, 2 Jun 2017 11:04:52 -0400 From: Daniel Liu To: libvir-list@redhat.com Message-ID: <20170602150452.GA99047@pc> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.8.2 (2017-04-18) X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 02 Jun 2017 15:04:57 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 02 Jun 2017 15:04:57 +0000 (UTC) for IP:'209.85.216.196' DOMAIN:'mail-qt0-f196.google.com' HELO:'mail-qt0-f196.google.com' FROM:'srwx4096@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.92 (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, SPF_PASS) 209.85.216.196 mail-qt0-f196.google.com 209.85.216.196 mail-qt0-f196.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Cc: mkletzan@redhat.com, mprivozn@redhat.com, srwx4096@gmail.com Subject: [libvirt] [PATCH v4] 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: , 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.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Fri, 02 Jun 2017 15:07:31 +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 Signed-off-by: Daniel Liu --- tools/virsh-domain.c | 51 ++++++++++++++++++++++++++++++++++++++----------= --- tools/virsh.pod | 7 ++++--- 2 files changed, 42 insertions(+), 16 deletions(-) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index ccb514ef9..3496359c5 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,51 @@ 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; } =20 + if (!(configData =3D virConnectDomainXMLToNative(priv->conn, format, x= mlData, flags))) { + goto cleanup; + } else { + vshPrint(ctl, "%s", configData); + ret =3D true; + } + + 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