From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id C249F69D45 for ; Mon, 14 Mar 2022 16:55:48 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id B9B3B6234 for ; Mon, 14 Mar 2022 16:55:18 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id B60596226 for ; Mon, 14 Mar 2022 16:55:17 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 8D07E45934 for ; Mon, 14 Mar 2022 16:55:17 +0100 (CET) Date: Mon, 14 Mar 2022 16:55:09 +0100 From: Fabian =?iso-8859-1?q?Gr=FCnbichler?= To: Proxmox VE development discussion References: <20220309100919.31512-1-f.ebner@proxmox.com> <20220309100919.31512-12-f.ebner@proxmox.com> In-Reply-To: <<20220309100919.31512-12-f.ebner@proxmox.com> MIME-Version: 1.0 User-Agent: astroid/0.15.0 (https://github.com/astroidmail/astroid) Message-Id: <1647262751.wqasoxacxe.astroid@nora.none> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-SPAM-LEVEL: Spam detection results: 0 AWL 0.187 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: Re: [pve-devel] [PATCH v12 qemu-server 11/16] api: add endpoint for parsing .ovf files X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 14 Mar 2022 15:55:48 -0000 On March 9, 2022 11:09 am, Fabian Ebner wrote: > Co-developed-by: Fabian Gr=C3=BCnbichler > Signed-off-by: Dominic J=C3=A4ger > [split into its own patch + minor improvements/style fixes] > Signed-off-by: Fabian Ebner > --- > PVE/API2/Qemu/Makefile | 2 +- > PVE/API2/Qemu/OVF.pm | 55 ++++++++++++++++++++++++++++++++++++++++++ > PVE/QemuServer.pm | 32 ++++++++++++++++++++++++ > 3 files changed, 88 insertions(+), 1 deletion(-) > create mode 100644 PVE/API2/Qemu/OVF.pm >=20 > diff --git a/PVE/API2/Qemu/Makefile b/PVE/API2/Qemu/Makefile > index 5d4abda..bdd4762 100644 > --- a/PVE/API2/Qemu/Makefile > +++ b/PVE/API2/Qemu/Makefile > @@ -1,4 +1,4 @@ > -SOURCES=3DAgent.pm CPU.pm Machine.pm > +SOURCES=3DAgent.pm CPU.pm Machine.pm OVF.pm > =20 > .PHONY: install > install: > diff --git a/PVE/API2/Qemu/OVF.pm b/PVE/API2/Qemu/OVF.pm > new file mode 100644 > index 0000000..5fa0ef0 > --- /dev/null > +++ b/PVE/API2/Qemu/OVF.pm > @@ -0,0 +1,55 @@ > +package PVE::API2::Qemu::OVF; > + > +use strict; > +use warnings; > + > +use PVE::JSONSchema qw(get_standard_option); > +use PVE::QemuServer::OVF; > +use PVE::RESTHandler; > + > +use base qw(PVE::RESTHandler); > + > +__PACKAGE__->register_method ({ > + name =3D> 'index', > + path =3D> '', > + method =3D> 'GET', > + proxyto =3D> 'node', > + description =3D> "Read an .ovf manifest.", protected =3D> 1, else this is limited to files readable by www-data? also probably should think about how to integrate this into the=20 permission system, since being limited to root@pam is rather limiting ;) e.g., something like a new content type/subdir for importing that 'only'=20 requires Datastore.Allocate (not AllocateSpace) or a new priv? starting off like it is now is of course okay, but we probably want some=20 form of nicer import flow for the common cases (like, download OVA from=20 URL into import dir on storage foo, then import from there for example). > + parameters =3D> { > + additionalProperties =3D> 0, > + properties =3D> { > + node =3D> get_standard_option('pve-node'), > + manifest =3D> { > + description =3D> "Path to .ovf manifest.", > + type =3D> 'string', > + }, > + }, > + }, > + returns =3D> { > + description =3D> "VM config according to .ovf manifest.", > + type =3D> "object", > + }, > + returns =3D> { > + type =3D> 'object', > + additionalProperties =3D> 1, > + properties =3D> PVE::QemuServer::json_ovf_properties({}), > + }, duplicate returns key, I guess we want the combination of both here ;) > + code =3D> sub { > + my ($param) =3D @_; > + > + my $manifest =3D $param->{manifest}; > + die "check for file $manifest failed - $!\n" if !-f $manifest; > + > + my $parsed =3D PVE::QemuServer::OVF::parse_ovf($manifest); > + my $result; > + $result->{cores} =3D $parsed->{qm}->{cores}; > + $result->{name} =3D $parsed->{qm}->{name}; > + $result->{memory} =3D $parsed->{qm}->{memory}; > + my $disks =3D $parsed->{disks}; > + for my $disk (@$disks) { > + $result->{$disk->{disk_address}} =3D $disk->{backing_file}; > + } > + return $result; > + }}); > + > +1; > diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm > index 33f226e..ecf51f3 100644 > --- a/PVE/QemuServer.pm > +++ b/PVE/QemuServer.pm > @@ -2203,6 +2203,38 @@ sub json_config_properties { > return $prop; > } > =20 > +# Properties that we can read from an OVF file > +sub json_ovf_properties { > + my $prop =3D shift; not sure whether we need the $prop here instead of always starting with=20 a clean slate? is there some future extension that uses this that you=20 have in mind? > + > + for my $device (PVE::QemuServer::Drive::valid_drive_names()) { > + $prop->{$device} =3D { > + type =3D> 'string', > + format =3D> 'pve-volume-id-or-absolute-path', > + description =3D> "Disk image that gets imported to $device", > + optional =3D> 1, > + }; > + } > + > + $prop->{cores} =3D { > + type =3D> 'integer', > + description =3D> "The number of CPU cores.", > + optional =3D> 1, > + }; > + $prop->{memory} =3D { > + type =3D> 'integer', > + description =3D> "Amount of RAM for the VM in MB.", > + optional =3D> 1, > + }; > + $prop->{name} =3D { > + type =3D> 'string', > + description =3D> "Name of the VM.", > + optional =3D> 1, > + }; > + > + return $prop; > +} > + > # return copy of $confdesc_cloudinit to generate documentation > sub cloudinit_config_properties { > =20 > --=20 > 2.30.2 >=20 >=20 >=20 > _______________________________________________ > pve-devel mailing list > pve-devel@lists.proxmox.com > https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel >=20