public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Subject: Re: [pve-devel] [PATCH v12 qemu-server 11/16] api: add endpoint for parsing .ovf files
Date: Mon, 14 Mar 2022 16:55:09 +0100	[thread overview]
Message-ID: <1647262751.wqasoxacxe.astroid@nora.none> (raw)
In-Reply-To: <<20220309100919.31512-12-f.ebner@proxmox.com>

On March 9, 2022 11:09 am, Fabian Ebner wrote:
> Co-developed-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
> Signed-off-by: Dominic Jäger <d.jaeger@proxmox.com>
> [split into its own patch + minor improvements/style fixes]
> Signed-off-by: Fabian Ebner <f.ebner@proxmox.com>
> ---
>  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
> 
> 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=Agent.pm CPU.pm Machine.pm
> +SOURCES=Agent.pm CPU.pm Machine.pm OVF.pm
>  
>  .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 => 'index',
> +    path => '',
> +    method => 'GET',
> +    proxyto => 'node',
> +    description => "Read an .ovf manifest.",

protected => 1,

else this is limited to files readable by www-data?

also probably should think about how to integrate this into the 
permission system, since being limited to root@pam is rather limiting ;)

e.g., something like a new content type/subdir for importing that 'only' 
requires Datastore.Allocate (not AllocateSpace) or a new priv?

starting off like it is now is of course okay, but we probably want some 
form of nicer import flow for the common cases (like, download OVA from 
URL into import dir on storage foo, then import from there for example).

> +    parameters => {
> +	additionalProperties => 0,
> +	properties => {
> +	    node => get_standard_option('pve-node'),
> +	    manifest => {
> +		description => "Path to .ovf manifest.",
> +		type => 'string',
> +	    },
> +	},
> +    },
> +    returns => {
> +	description => "VM config according to .ovf manifest.",
> +	type => "object",
> +    },
> +    returns => {
> +	type => 'object',
> +	additionalProperties => 1,
> +	properties => PVE::QemuServer::json_ovf_properties({}),
> +    },

duplicate returns key, I guess we want the combination of both here ;)

> +    code => sub {
> +	my ($param) = @_;
> +
> +	my $manifest = $param->{manifest};
> +	die "check for file $manifest failed - $!\n" if !-f $manifest;
> +
> +	my $parsed = PVE::QemuServer::OVF::parse_ovf($manifest);
> +	my $result;
> +	$result->{cores} = $parsed->{qm}->{cores};
> +	$result->{name} =  $parsed->{qm}->{name};
> +	$result->{memory} = $parsed->{qm}->{memory};
> +	my $disks = $parsed->{disks};
> +	for my $disk (@$disks) {
> +	    $result->{$disk->{disk_address}} = $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;
>  }
>  
> +# Properties that we can read from an OVF file
> +sub json_ovf_properties {
> +    my $prop = shift;

not sure whether we need the $prop here instead of always starting with 
a clean slate? is there some future extension that uses this that you 
have in mind?

> +
> +    for my $device (PVE::QemuServer::Drive::valid_drive_names()) {
> +	$prop->{$device} = {
> +	    type => 'string',
> +	    format => 'pve-volume-id-or-absolute-path',
> +	    description => "Disk image that gets imported to $device",
> +	    optional => 1,
> +	};
> +    }
> +
> +    $prop->{cores} = {
> +	type => 'integer',
> +	description => "The number of CPU cores.",
> +	optional => 1,
> +    };
> +    $prop->{memory} = {
> +	type => 'integer',
> +	description => "Amount of RAM for the VM in MB.",
> +	optional => 1,
> +    };
> +    $prop->{name} = {
> +	type => 'string',
> +	description => "Name of the VM.",
> +	optional => 1,
> +    };
> +
> +    return $prop;
> +}
> +
>  # return copy of $confdesc_cloudinit to generate documentation
>  sub cloudinit_config_properties {
>  
> -- 
> 2.30.2
> 
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 




  parent reply	other threads:[~2022-03-14 15:55 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-09 10:09 [pve-devel] [PATCH-SERIES v12 qemu-server/manager] API for disk import and OVF Fabian Ebner
2022-03-09 10:09 ` [pve-devel] [PATCH v12 qemu-server 01/16] device unplug: verify that unplugging scsi disk completed Fabian Ebner
2022-03-09 10:09 ` [pve-devel] [PATCH v12 qemu-server 02/16] api: create disks: always activate/update size when attaching existing volume Fabian Ebner
2022-03-09 10:09 ` [pve-devel] [PATCH v12 qemu-server 03/16] api: update: pass correct config when creating disks Fabian Ebner
2022-03-09 10:09 ` [pve-devel] [PATCH v12 qemu-server 04/16] clone disk: remove check for min QEMU version 2.7 Fabian Ebner
2022-03-09 10:09 ` [pve-devel] [PATCH v12 qemu-server 05/16] clone disk: group source and target parameters Fabian Ebner
2022-03-09 10:09 ` [pve-devel] [PATCH v12 qemu-server 06/16] clone disk: pass in efi vars size rather than config Fabian Ebner
2022-03-09 10:09 ` [pve-devel] [PATCH v12 qemu-server 07/16] clone disk: allow cloning from an unused or unreferenced disk Fabian Ebner
     [not found]   ` <<20220309100919.31512-8-f.ebner@proxmox.com>
2022-03-14 15:55     ` Fabian Grünbichler
2022-03-17 10:35       ` Fabian Ebner
2022-03-09 10:09 ` [pve-devel] [PATCH v12 qemu-server 08/16] efivars size: allow overriding efidisk parameter Fabian Ebner
2022-03-09 10:09 ` [pve-devel] [PATCH v12 qemu-server 09/16] schema: add pve-volume-id-or-absolute-path Fabian Ebner
2022-03-09 10:09 ` [pve-devel] [PATCH v12 qemu-server 10/16] parse ovf: untaint path when calling file_size_info Fabian Ebner
2022-03-09 10:09 ` [pve-devel] [PATCH v12 qemu-server 11/16] api: add endpoint for parsing .ovf files Fabian Ebner
     [not found]   ` <<20220309100919.31512-12-f.ebner@proxmox.com>
2022-03-14 15:55     ` Fabian Grünbichler [this message]
2022-03-15 13:00       ` Fabian Ebner
2022-03-09 10:09 ` [pve-devel] [PATCH v12 qemu-server 12/16] image convert: allow block device as source Fabian Ebner
2022-03-09 10:09 ` [pve-devel] [PATCH v12 qemu-server 13/16] api: factor out check/cleanup for drive params Fabian Ebner
2022-03-09 10:09 ` [pve-devel] [PATCH v12 qemu-server 14/16] schema: drive: use separate schema when disk allocation is possible Fabian Ebner
2022-03-09 10:09 ` [pve-devel] [PATCH v12 qemu-server 15/16] api: support VM disk import Fabian Ebner
     [not found]   ` <<20220309100919.31512-16-f.ebner@proxmox.com>
2022-03-14 15:54     ` Fabian Grünbichler
2022-03-16  9:29       ` Fabian Ebner
2022-03-09 10:09 ` [pve-devel] [PATCH v12 qemu-server 16/16] api: update vm: print drive string for newly allocated/imported drives Fabian Ebner
2022-03-09 10:09 ` [pve-devel] [PATCH v12 manager 1/1] api: nodes: add readovf endpoint Fabian Ebner
2022-03-14 15:57 ` [pve-devel] partially-applied: [PATCH-SERIES v12 qemu-server/manager] API for disk import and OVF Fabian Grünbichler
2022-03-16 10:00   ` Fabian Ebner
2022-03-16 10:29     ` Fabian Grünbichler
2022-03-16 11:25       ` Fabian Ebner
2022-03-16 11:58         ` Fabian Grünbichler

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1647262751.wqasoxacxe.astroid@nora.none \
    --to=f.gruenbichler@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal