From nobody Sat Apr 27 08:55:05 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.zohomail.com; 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 1504264872969607.8878450488085; Fri, 1 Sep 2017 04:21:12 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C144E68CE; Fri, 1 Sep 2017 11:21:10 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3E6517F5F5; Fri, 1 Sep 2017 11:21:09 +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 0799A1800C89; Fri, 1 Sep 2017 11:21:06 +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 v81B6wGG005268 for ; Fri, 1 Sep 2017 07:06:58 -0400 Received: by smtp.corp.redhat.com (Postfix) id 4D6E47C8BA; Fri, 1 Sep 2017 11:06:58 +0000 (UTC) Received: from moo.home.annexia.org (ovpn-117-64.ams2.redhat.com [10.36.117.64]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E7C1B3E97; Fri, 1 Sep 2017 11:06:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com C144E68CE Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=libvir-list-bounces@redhat.com From: "Richard W.M. Jones" To: libvir-list@redhat.com Date: Fri, 1 Sep 2017 12:06:52 +0100 Message-Id: <20170901110652.18880-2-rjones@redhat.com> In-Reply-To: <20170901110652.18880-1-rjones@redhat.com> References: <20170901110652.18880-1-rjones@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Cc: mprivozn@redhat.com Subject: [libvirt] [PATCH v2] vmx: Expose VMware Managed Object Reference (moref) in XML. 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.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 01 Sep 2017 11:21:11 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If you use the VDDK library to access virtual machines remotely, you really need to know the Managed Object Reference ("moref") of the VM. This must be passed each time you connect to the API. For example nbdkit's VDDK plugin requires a moref to be passed to mount up a VM's disk remotely: nbdkit vddk user=3Droot password=3D+/tmp/rootpw \ server=3Desxi.example.com thumbprint=3Dxx:xx:xx:... \ vm=3Dmoref=3D2 \ file=3D"[datastore1] Fedora/Fedora.vmdk" Getting the moref is a huge pain. To get some idea of what it is, why it is needed, and how much trouble it is to get it, see: https://blogs.vmware.com/vsphere/2012/02/uniquely-identifying-virtual-machi= nes-in-vsphere-and-vcloud-part-1-overview.html https://blogs.vmware.com/vsphere/2012/02/uniquely-identifying-virtual-machi= nes-in-vsphere-and-vcloud-part-2-technical.html However the moref is available conveniently in the internals of the libvirt VMX driver. This patch exposes it as a custom XML element using the same "vmware:" namespace which was previously used for the datacenterpath (see libvirt commit 636a99058758a044). It appears in the XML like this: Fedora ... ha-datacenter 2 Note that the moref can appear as either a simple ID (for esx:// connections) or as a "vm-" (for vpx:// connections). It should be treated by users as an opaque string. --- src/esx/esx_driver.c | 7 +++++++ src/esx/esx_vi.c | 13 +++++++++++++ src/esx/esx_vi.h | 4 ++++ src/vmx/vmx.c | 43 +++++++++++++++++++++++++++++++++---------- src/vmx/vmx.h | 2 ++ 5 files changed, 59 insertions(+), 10 deletions(-) diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c index 1f4f2c7a7..0cce0a41a 100644 --- a/src/esx/esx_driver.c +++ b/src/esx/esx_driver.c @@ -2645,6 +2645,7 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int= flags) esxVI_ObjectContent *virtualMachine =3D NULL; esxVI_VirtualMachinePowerState powerState; int id; + char *moref =3D NULL; char *vmPathName =3D NULL; char *datastoreName =3D NULL; char *directoryName =3D NULL; @@ -2670,6 +2671,7 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int= flags) esxVI_LookupVirtualMachineByUuid(priv->primary, domain->uuid, propertyNameList, &virtualMachine, esxVI_Occurrence_RequiredItem) < = 0 || + esxVI_GetVirtualMachineMORef(virtualMachine, &moref) < 0 || esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0= || esxVI_GetVirtualMachineIdentity(virtualMachine, &id, NULL, NULL) <= 0 || esxVI_GetStringValue(virtualMachine, "config.files.vmPathName", @@ -2715,6 +2717,7 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int= flags) ctx.formatFileName =3D NULL; ctx.autodetectSCSIControllerModel =3D NULL; ctx.datacenterPath =3D priv->primary->datacenterPath; + ctx.moref =3D moref; =20 def =3D virVMXParseConfig(&ctx, priv->xmlopt, priv->caps, vmx); =20 @@ -2732,6 +2735,7 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int= flags) =20 esxVI_String_Free(&propertyNameList); esxVI_ObjectContent_Free(&virtualMachine); + VIR_FREE(moref); VIR_FREE(datastoreName); VIR_FREE(directoryName); VIR_FREE(directoryAndFileName); @@ -2774,6 +2778,7 @@ esxConnectDomainXMLFromNative(virConnectPtr conn, con= st char *nativeFormat, ctx.formatFileName =3D NULL; ctx.autodetectSCSIControllerModel =3D NULL; ctx.datacenterPath =3D NULL; + ctx.moref =3D NULL; =20 def =3D virVMXParseConfig(&ctx, priv->xmlopt, priv->caps, nativeConfig= ); =20 @@ -2830,6 +2835,7 @@ esxConnectDomainXMLToNative(virConnectPtr conn, const= char *nativeFormat, ctx.formatFileName =3D esxFormatVMXFileName; ctx.autodetectSCSIControllerModel =3D esxAutodetectSCSIControllerModel; ctx.datacenterPath =3D NULL; + ctx.moref =3D NULL; =20 vmx =3D virVMXFormatConfig(&ctx, priv->xmlopt, def, virtualHW_version); =20 @@ -3077,6 +3083,7 @@ esxDomainDefineXMLFlags(virConnectPtr conn, const cha= r *xml, unsigned int flags) ctx.formatFileName =3D esxFormatVMXFileName; ctx.autodetectSCSIControllerModel =3D esxAutodetectSCSIControllerModel; ctx.datacenterPath =3D NULL; + ctx.moref =3D NULL; =20 vmx =3D virVMXFormatConfig(&ctx, priv->xmlopt, def, virtualHW_version); =20 diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c index 8586e3ff0..6d59bae9d 100644 --- a/src/esx/esx_vi.c +++ b/src/esx/esx_vi.c @@ -2390,6 +2390,19 @@ esxVI_GetVirtualMachineQuestionInfo } =20 =20 +int +esxVI_GetVirtualMachineMORef(esxVI_ObjectContent *virtualMachine, + char **moref) +{ + for (; virtualMachine !=3D NULL; virtualMachine =3D virtualMachine->_n= ext) { + if (virtualMachine->obj && + STREQ(virtualMachine->obj->type, "VirtualMachine") && + virtualMachine->obj->value) { + return VIR_STRDUP(*moref, virtualMachine->obj->value); + } + } + return -1; +} =20 int esxVI_GetBoolean(esxVI_ObjectContent *objectContent, const char *propertyN= ame, diff --git a/src/esx/esx_vi.h b/src/esx/esx_vi.h index 7c53f3781..47d518dd1 100644 --- a/src/esx/esx_vi.h +++ b/src/esx/esx_vi.h @@ -334,6 +334,10 @@ int esxVI_GetVirtualMachineQuestionInfo (esxVI_ObjectContent *virtualMachine, esxVI_VirtualMachineQuestionInfo **questionInfo); =20 +int esxVI_GetVirtualMachineMORef + (esxVI_ObjectContent *virtualMachine, + char **moref); + int esxVI_GetBoolean(esxVI_ObjectContent *objectContent, const char *propertyName, esxVI_Boolean *value, esxVI_Occurrence occurrence); diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c index d1d8184c5..8aae635c1 100644 --- a/src/vmx/vmx.c +++ b/src/vmx/vmx.c @@ -553,23 +553,41 @@ static virDomainDefParserConfig virVMXDomainDefParser= Config =3D { VIR_DOMAIN_DEF_FEATURE_NAME_SLASH), }; =20 +struct virVMXDomainDefNamespaceData { + char *datacenterPath; + char *moref; +}; + static void virVMXDomainDefNamespaceFree(void *nsdata) { - VIR_FREE(nsdata); + struct virVMXDomainDefNamespaceData *data =3D nsdata; + + if (data) { + VIR_FREE(data->datacenterPath); + VIR_FREE(data->moref); + } + VIR_FREE(data); } =20 static int virVMXDomainDefNamespaceFormatXML(virBufferPtr buf, void *nsdata) { - const char *datacenterPath =3D nsdata; + struct virVMXDomainDefNamespaceData *data =3D nsdata; =20 - if (!datacenterPath) + if (!data) return 0; =20 - virBufferAddLit(buf, ""); - virBufferEscapeString(buf, "%s", datacenterPath); - virBufferAddLit(buf, "\n"); + if (data->datacenterPath) { + virBufferAddLit(buf, ""); + virBufferEscapeString(buf, "%s", data->datacenterPath); + virBufferAddLit(buf, "\n"); + } + if (data->moref) { + virBufferAddLit(buf, ""); + virBufferEscapeString(buf, "%s", data->moref); + virBufferAddLit(buf, "\n"); + } =20 return 0; } @@ -1304,7 +1322,6 @@ virVMXParseConfig(virVMXContext *ctx, bool hgfs_disabled =3D true; long long sharedFolder_maxNum =3D 0; int cpumasklen; - char *namespaceData; =20 if (ctx->parseFileName =3D=3D NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -1802,12 +1819,18 @@ virVMXParseConfig(virVMXContext *ctx, } =20 /* ctx:datacenterPath -> def:namespaceData */ - if (ctx->datacenterPath) { - if (VIR_STRDUP(namespaceData, ctx->datacenterPath) < 0) + if (ctx->datacenterPath || ctx->moref) { + struct virVMXDomainDefNamespaceData *nsdata =3D NULL; + + if (VIR_ALLOC(nsdata) < 0 || + VIR_STRDUP(nsdata->datacenterPath, ctx->datacenterPath) < 0 || + VIR_STRDUP(nsdata->moref, ctx->moref) < 0) { + virVMXDomainDefNamespaceFree(nsdata); goto cleanup; + } =20 def->ns =3D *virDomainXMLOptionGetNamespace(xmlopt); - def->namespaceData =3D namespaceData; + def->namespaceData =3D nsdata; } =20 if (virDomainDefPostParse(def, caps, VIR_DOMAIN_DEF_PARSE_ABI_UPDATE, diff --git a/src/vmx/vmx.h b/src/vmx/vmx.h index 08b627765..6b3d880d6 100644 --- a/src/vmx/vmx.h +++ b/src/vmx/vmx.h @@ -45,6 +45,7 @@ typedef int (*virVMXAutodetectSCSIControllerModel)(virDom= ainDiskDefPtr def, * formatFileName is only used by virVMXFormatConfig. * autodetectSCSIControllerModel is optionally used by virVMXFormatConfig. * datacenterPath is only used by virVMXFormatConfig. + * moref is only used by virVMXFormatConfig. */ struct _virVMXContext { void *opaque; @@ -52,6 +53,7 @@ struct _virVMXContext { virVMXFormatFileName formatFileName; virVMXAutodetectSCSIControllerModel autodetectSCSIControllerModel; const char *datacenterPath; /* including folders */ + const char *moref; }; =20 =20 --=20 2.13.2 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list