public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* Re: [pve-devel] [PATCH qemu-server] api: cloud-init support for mtu and userdata
@ 2020-07-13 15:06 Julien Escario
  0 siblings, 0 replies; 9+ messages in thread
From: Julien Escario @ 2020-07-13 15:06 UTC (permalink / raw)
  To: pve-devel

Hello,
First, sorry, I'm taking the thread from the archive, don't have much
history.

To the question :
"Any reason why snippets [0] are not enough for custom userdata?"

Yes, there's one : in the generated, there's a few vm-specific options,
like "fqdn:" and "hostname:" parameters. Having them auto-generated in
PVE is really nice and remove the need to have a snippet file per VM.

With snippets, one can only REPLACE generated user-data. So, the fqdn
and hostname parameters are completely gone which leads to the need of
one snippet file per VM.

Having the ability to EXTEND the generated user-data is really needed.
So we can add only vm-agnostic parameters like sshkeys, packages and so
on ...

On another approach, I wrote a (really) small patch adding the
vendor-data custom file [1] but I'm not a developer and submitting a
proper usable patch is out of my capacity.

vendor-data never supersede user-data [2] so no other change should be
required.

cloud-init support in Proxmox is almost complete, please consider
integrating one of the 2 solutions inside your code base so we could
full automate VM deployment using the API and 'plug' the VM into a
config management system like puppet, ansible, chef, whatever.

Thanks a lot !

1 :
https://forum.proxmox.com/threads/combining-custom-cloud-init-with-auto-generated.59008/page-2
2 : https://cloudinit.readthedocs.io/en/latest/topics/vendordata.html



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [pve-devel] [PATCH qemu-server] api: cloud-init support for mtu and userdata
  2020-09-04 15:21 proxmox
  2020-09-07  7:33 ` Alexandre DERUMIER
@ 2020-09-09 14:05 ` Mira Limbeck
  1 sibling, 0 replies; 9+ messages in thread
From: Mira Limbeck @ 2020-09-09 14:05 UTC (permalink / raw)
  To: pve-devel

Hi,

On 9/4/20 5:21 PM, proxmox wrote:
> Hello
>
>
>
> I didn't know this patch mail got approved, so sorry for the (very) late response.
>
>
>
> My intention for not going with snippets was the fact that they could not be created via the API and one would have to manually create a file on the target machine for cloud-init userdata.

There is currently a bug report open for this: 
https://bugzilla.proxmox.com/show_bug.cgi?id=2208

This together with backup and migration of snippets could be useful.

>
>
>
> One possible use case was to spin up a kubernetes cluster on proxmox only via API.
>
>
>
> I wanted to have something similar to the hetzner cloud API where the full userdata can be submitted for VM provisioning:
> https://docs.hetzner.cloud/#servers-create-a-server
>
>
>
> So going further here you want me to submit the MTU patches separately?
The MTU patches separately would be great.
>
>
>
> Should I integrate userdata into the cicustom field? I thought this would make things more complex in favor of parsing out the base64 stuff. So I would still go with an extra field.

After some discussions we think that putting the userdata in the config 
file is not the right approach. As the cluster filesystem is limited to 
32M and a single VM config file is limited to 512K you can easily run 
into the limit with a small number of VMs. We would most likely have to 
limit the userdata per config to a very small amount (1K?). But with 
those limits it is difficult to get everything in.

>
> Thoughts?
> _______________________________________________
> pve-devel mailing list
> pve-devel@lists.proxmox.com
> https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
>
>




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [pve-devel] [PATCH qemu-server] api: cloud-init support for mtu and userdata
  2020-09-09 13:02     ` Alexandre DERUMIER
@ 2020-09-09 13:46       ` Alexandre DERUMIER
  0 siblings, 0 replies; 9+ messages in thread
From: Alexandre DERUMIER @ 2020-09-09 13:46 UTC (permalink / raw)
  To: Proxmox VE development discussion

it has been added to kernel in 2016

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=v5.8.7&id=14de9d114a82a564b94388c95af79a701dc93134

----- Mail original -----
De: "aderumier" <aderumier@odiso.com>
À: "Proxmox VE development discussion" <pve-devel@lists.proxmox.com>
Envoyé: Mercredi 9 Septembre 2020 15:02:33
Objet: Re: [pve-devel] [PATCH qemu-server] api: cloud-init support for mtu and userdata

>>But this does not change the MTU inside the VM right? 

yes, it change the mtu inside the vm! 

(at least on recent kernel, don't remember when this had been added) 

----- Mail original ----- 
De: "proxmox" <proxmox@giftfish.de> 
À: "Proxmox VE development discussion" <pve-devel@lists.proxmox.com> 
Envoyé: Mercredi 9 Septembre 2020 11:06:13 
Objet: Re: [pve-devel] [PATCH qemu-server] api: cloud-init support for mtu and userdata 

But this does not change the MTU inside the VM right? 



-----Ursprüngliche Nachricht----- 
Von: Alexandre DERUMIER <aderumier@odiso.com> 
Gesendet: Montag 7 September 2020 09:34 
An: Proxmox VE development discussion <pve-devel@lists.proxmox.com> 
Betreff: Re: [pve-devel] [PATCH qemu-server] api: cloud-init support for mtu and userdata 


Hi, 

not related to cloudinit, but for virtio-net nic, it's already possible to add "mtu=xxx" option to netX:..... 

It's not yet available in gui, but you should be able to do it with "qm set <vmid> --net0 ...,mtu=xxxx" 



----- Mail original ----- 
De: "proxmox" <proxmox@giftfish.de> 
À: "Proxmox VE development discussion" <pve-devel@lists.proxmox.com> 
Envoyé: Vendredi 4 Septembre 2020 17:21:24 
Objet: Re: [pve-devel] [PATCH qemu-server] api: cloud-init support for mtu and userdata 

Hello 



I didn't know this patch mail got approved, so sorry for the (very) late response. 



My intention for not going with snippets was the fact that they could not be created via the API and one would have to manually create a file on the target machine for cloud-init userdata. 



One possible use case was to spin up a kubernetes cluster on proxmox only via API. 



I wanted to have something similar to the hetzner cloud API where the full userdata can be submitted for VM provisioning: 
https://docs.hetzner.cloud/#servers-create-a-server 



So going further here you want me to submit the MTU patches separately? 



Should I integrate userdata into the cicustom field? I thought this would make things more complex in favor of parsing out the base64 stuff. So I would still go with an extra field. 

Thoughts? 
_______________________________________________ 
pve-devel mailing list 
pve-devel@lists.proxmox.com 
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel 


_______________________________________________ 
pve-devel mailing list 
pve-devel@lists.proxmox.com 
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel 
_______________________________________________ 
pve-devel mailing list 
pve-devel@lists.proxmox.com 
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel 


_______________________________________________ 
pve-devel mailing list 
pve-devel@lists.proxmox.com 
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel 




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [pve-devel] [PATCH qemu-server] api: cloud-init support for mtu and userdata
  2020-09-09  9:06   ` proxmox
@ 2020-09-09 13:02     ` Alexandre DERUMIER
  2020-09-09 13:46       ` Alexandre DERUMIER
  0 siblings, 1 reply; 9+ messages in thread
From: Alexandre DERUMIER @ 2020-09-09 13:02 UTC (permalink / raw)
  To: Proxmox VE development discussion

>>But this does not change the MTU inside the VM right?

yes, it change the mtu inside the vm!

(at least on recent kernel, don't remember when this had been added)

----- Mail original -----
De: "proxmox" <proxmox@giftfish.de>
À: "Proxmox VE development discussion" <pve-devel@lists.proxmox.com>
Envoyé: Mercredi 9 Septembre 2020 11:06:13
Objet: Re: [pve-devel] [PATCH qemu-server] api: cloud-init support for mtu and userdata

But this does not change the MTU inside the VM right? 



-----Ursprüngliche Nachricht----- 
Von: Alexandre DERUMIER <aderumier@odiso.com> 
Gesendet: Montag 7 September 2020 09:34 
An: Proxmox VE development discussion <pve-devel@lists.proxmox.com> 
Betreff: Re: [pve-devel] [PATCH qemu-server] api: cloud-init support for mtu and userdata 


Hi, 

not related to cloudinit, but for virtio-net nic, it's already possible to add "mtu=xxx" option to netX:..... 

It's not yet available in gui, but you should be able to do it with "qm set <vmid> --net0 ...,mtu=xxxx" 



----- Mail original ----- 
De: "proxmox" <proxmox@giftfish.de> 
À: "Proxmox VE development discussion" <pve-devel@lists.proxmox.com> 
Envoyé: Vendredi 4 Septembre 2020 17:21:24 
Objet: Re: [pve-devel] [PATCH qemu-server] api: cloud-init support for mtu and userdata 

Hello 



I didn't know this patch mail got approved, so sorry for the (very) late response. 



My intention for not going with snippets was the fact that they could not be created via the API and one would have to manually create a file on the target machine for cloud-init userdata. 



One possible use case was to spin up a kubernetes cluster on proxmox only via API. 



I wanted to have something similar to the hetzner cloud API where the full userdata can be submitted for VM provisioning: 
https://docs.hetzner.cloud/#servers-create-a-server 



So going further here you want me to submit the MTU patches separately? 



Should I integrate userdata into the cicustom field? I thought this would make things more complex in favor of parsing out the base64 stuff. So I would still go with an extra field. 

Thoughts? 
_______________________________________________ 
pve-devel mailing list 
pve-devel@lists.proxmox.com 
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel 


_______________________________________________ 
pve-devel mailing list 
pve-devel@lists.proxmox.com 
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel 
_______________________________________________ 
pve-devel mailing list 
pve-devel@lists.proxmox.com 
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel 




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [pve-devel] [PATCH qemu-server] api: cloud-init support for mtu and userdata
  2020-09-07  7:33 ` Alexandre DERUMIER
@ 2020-09-09  9:06   ` proxmox
  2020-09-09 13:02     ` Alexandre DERUMIER
  0 siblings, 1 reply; 9+ messages in thread
From: proxmox @ 2020-09-09  9:06 UTC (permalink / raw)
  To: Proxmox VE development discussion

But this does not change the MTU inside the VM right?



-----Ursprüngliche Nachricht-----
Von: Alexandre DERUMIER <aderumier@odiso.com>
Gesendet: Montag 7 September 2020 09:34
An: Proxmox VE development discussion <pve-devel@lists.proxmox.com>
Betreff: Re: [pve-devel] [PATCH qemu-server] api: cloud-init support for mtu and userdata


Hi,

not related to cloudinit, but for virtio-net nic, it's already possible to add "mtu=xxx" option to netX:.....

It's not yet available in gui, but you should be able to do it with "qm set <vmid>  --net0  ...,mtu=xxxx"



----- Mail original -----
De: "proxmox" <proxmox@giftfish.de>
À: "Proxmox VE development discussion" <pve-devel@lists.proxmox.com>
Envoyé: Vendredi 4 Septembre 2020 17:21:24
Objet: Re: [pve-devel] [PATCH qemu-server] api: cloud-init support for mtu and userdata

Hello 



I didn't know this patch mail got approved, so sorry for the (very) late response. 



My intention for not going with snippets was the fact that they could not be created via the API and one would have to manually create a file on the target machine for cloud-init userdata. 



One possible use case was to spin up a kubernetes cluster on proxmox only via API. 



I wanted to have something similar to the hetzner cloud API where the full userdata can be submitted for VM provisioning: 
https://docs.hetzner.cloud/#servers-create-a-server 



So going further here you want me to submit the MTU patches separately? 



Should I integrate userdata into the cicustom field? I thought this would make things more complex in favor of parsing out the base64 stuff. So I would still go with an extra field. 

Thoughts? 
_______________________________________________ 
pve-devel mailing list 
pve-devel@lists.proxmox.com 
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel 


_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [pve-devel] [PATCH qemu-server] api: cloud-init support for mtu and userdata
  2020-09-04 15:21 proxmox
@ 2020-09-07  7:33 ` Alexandre DERUMIER
  2020-09-09  9:06   ` proxmox
  2020-09-09 14:05 ` Mira Limbeck
  1 sibling, 1 reply; 9+ messages in thread
From: Alexandre DERUMIER @ 2020-09-07  7:33 UTC (permalink / raw)
  To: Proxmox VE development discussion

Hi,

not related to cloudinit, but for virtio-net nic, it's already possible to add "mtu=xxx" option to netX:.....

It's not yet available in gui, but you should be able to do it with "qm set <vmid>  --net0  ...,mtu=xxxx"



----- Mail original -----
De: "proxmox" <proxmox@giftfish.de>
À: "Proxmox VE development discussion" <pve-devel@lists.proxmox.com>
Envoyé: Vendredi 4 Septembre 2020 17:21:24
Objet: Re: [pve-devel] [PATCH qemu-server] api: cloud-init support for mtu and userdata

Hello 



I didn't know this patch mail got approved, so sorry for the (very) late response. 



My intention for not going with snippets was the fact that they could not be created via the API and one would have to manually create a file on the target machine for cloud-init userdata. 



One possible use case was to spin up a kubernetes cluster on proxmox only via API. 



I wanted to have something similar to the hetzner cloud API where the full userdata can be submitted for VM provisioning: 
https://docs.hetzner.cloud/#servers-create-a-server 



So going further here you want me to submit the MTU patches separately? 



Should I integrate userdata into the cicustom field? I thought this would make things more complex in favor of parsing out the base64 stuff. So I would still go with an extra field. 

Thoughts? 
_______________________________________________ 
pve-devel mailing list 
pve-devel@lists.proxmox.com 
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel 




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [pve-devel] [PATCH qemu-server] api: cloud-init support for mtu and userdata
@ 2020-09-04 15:21 proxmox
  2020-09-07  7:33 ` Alexandre DERUMIER
  2020-09-09 14:05 ` Mira Limbeck
  0 siblings, 2 replies; 9+ messages in thread
From: proxmox @ 2020-09-04 15:21 UTC (permalink / raw)
  To: pve-devel

Hello



I didn't know this patch mail got approved, so sorry for the (very) late response.



My intention for not going with snippets was the fact that they could not be created via the API and one would have to manually create a file on the target machine for cloud-init userdata.



One possible use case was to spin up a kubernetes cluster on proxmox only via API.



I wanted to have something similar to the hetzner cloud API where the full userdata can be submitted for VM provisioning:
https://docs.hetzner.cloud/#servers-create-a-server



So going further here you want me to submit the MTU patches separately?



Should I integrate userdata into the cicustom field? I thought this would make things more complex in favor of parsing out the base64 stuff. So I would still go with an extra field.

Thoughts?


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [pve-devel] [PATCH qemu-server] api: cloud-init support for mtu and userdata
  2020-07-02 16:08 ` [pve-devel] [PATCH qemu-server] api: cloud-init support for mtu " Marius Schellenberger
@ 2020-07-13 12:51   ` Mira Limbeck
  0 siblings, 0 replies; 9+ messages in thread
From: Mira Limbeck @ 2020-07-13 12:51 UTC (permalink / raw)
  To: pve-devel

The MTU part of the patch looks good and works fine here. It would be 
great if you could send that as a separate patch when you send a v2 of 
the patch series.


Any reason why snippets [0] are not enough for custom userdata?


Also we don't want any further cloudinit options in the global config 
scope. Instead we use cicustom for new cloudinit options. There you 
should be able to extend the user part to support custom userdata as a 
urlencoded base64 string instead of only as a volume id (snippet). This 
can be done by registering a new format 
(PVE::JSONSchema::register_format) for it with a validator function that 
accepts both a pve-volume-id as well as the userdata string and then 
using this format in cicustom_fmt.


[0] https://pve.proxmox.com/pve-docs/pve-admin-guide.html#qm_cloud_init 
(10.8.3 Custom Cloud-Init Configuration)

On 7/2/20 6:08 PM, Marius Schellenberger wrote:
> Extended the PVE API to configure cloud-init userdata and network
> interface MTU.
>
> Signed-off-by: Marius Schellenberger <proxmox@giftfish.de>
> ---
>   PVE/API2/Qemu.pm            |  1 +
>   PVE/QemuServer.pm           | 18 +++++++++++++++++-
>   PVE/QemuServer/Cloudinit.pm | 31 +++++++++++++++++++++++++++++--
>   3 files changed, 47 insertions(+), 3 deletions(-)
>
> diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
> index b33359d..02507de 100644
> --- a/PVE/API2/Qemu.pm
> +++ b/PVE/API2/Qemu.pm
> @@ -324,6 +324,7 @@ my $cloudinitoptions = {
>       cipassword => 1,
>       citype => 1,
>       ciuser => 1,
> +    ciuserdata => 1,
>       nameserver => 1,
>       searchdomain => 1,
>       sshkeys => 1,
> diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
> index 6872e06..ef4342d 100644
> --- a/PVE/QemuServer.pm
> +++ b/PVE/QemuServer.pm
> @@ -727,6 +727,12 @@ my $confdesc_cloudinit = {
>   	description => 'cloud-init: Specify custom files to replace the automatically generated ones at start.',
>   	format => 'pve-qm-cicustom',
>       },
> +    ciuserdata => {
> +        optional => 1,
> +        type => 'string',
> +        format => 'urlencoded',
> +        description => 'cloud-init: Specify custom user-data as urlencoded base64 string to replace the automatically generated one at start. When set, the following options have no effect: `ciuser`, `cipassword`, `sshkeys`',
> +    },
>       searchdomain => {
>   	optional => 1,
>   	type => 'string',
> @@ -932,6 +938,12 @@ my $ipconfig_fmt = {
>   	optional => 1,
>   	requires => 'ip6',
>       },
> +    mtu => {
> +	type => 'string',
> +	format_description => 'MTU',
> +	description => 'MTU value for interface.',
> +	optional => 1,
> +    },
>   };
>   PVE::JSONSchema::register_format('pve-qm-ipconfig', $ipconfig_fmt);
>   my $ipconfigdesc = {
> @@ -1701,7 +1713,7 @@ sub parse_net {
>       return $res;
>   }
>   
> -# ipconfigX ip=cidr,gw=ip,ip6=cidr,gw6=ip
> +# ipconfigX ip=cidr,gw=ip,ip6=cidr,gw6=ip,mtu=mtu
>   sub parse_ipconfig {
>       my ($data) = @_;
>   
> @@ -1711,6 +1723,10 @@ sub parse_ipconfig {
>   	return undef;
>       }
>   
> +    if ($res->{mtu} && !$res->{ip} && !$res->{ip6}) {
> +	warn 'mtu specified without specifying an IP or IPv6 address';
> +	return undef;
> +    }
>       if ($res->{gw} && !$res->{ip}) {
>   	warn 'gateway specified without specifying an IP address';
>   	return undef;
> diff --git a/PVE/QemuServer/Cloudinit.pm b/PVE/QemuServer/Cloudinit.pm
> index 439de99..a47e0ce 100644
> --- a/PVE/QemuServer/Cloudinit.pm
> +++ b/PVE/QemuServer/Cloudinit.pm
> @@ -6,6 +6,7 @@ use warnings;
>   use File::Path;
>   use Digest::SHA;
>   use URI::Escape;
> +use MIME::Base64 qw(decode_base64);
>   
>   use PVE::Tools qw(run_command file_set_contents);
>   use PVE::Storage;
> @@ -111,6 +112,11 @@ sub get_dns_conf {
>   sub cloudinit_userdata {
>       my ($conf, $vmid) = @_;
>   
> +    my $userdata = $conf->{ciuserdata};
> +    if (defined($userdata) && $userdata ne "") {
> +        return decode_base64(uri_unescape($userdata));
> +    }
> +
>       my ($hostname, $fqdn) = get_hostname_fqdn($conf, $vmid);
>   
>       my $content = "#cloud-config\n";
> @@ -176,7 +182,9 @@ sub configdrive2_network {
>   	(my $id = $iface) =~ s/^net//;
>   	next if !$conf->{"ipconfig$id"};
>   	my $net = PVE::QemuServer::parse_ipconfig($conf->{"ipconfig$id"});
> +	next if !defined($net);
>   	$id = "eth$id";
> +	my $mtu = $net->{mtu};
>   
>   	$content .="auto $id\n";
>   	if ($net->{ip}) {
> @@ -189,6 +197,9 @@ sub configdrive2_network {
>   		$content .= "        netmask $mask\n";
>   		$content .= "        gateway $net->{gw}\n" if $net->{gw};
>   	    }
> +	    if (defined($mtu) && $mtu ne "") {
> +		$content .= "        mtu $mtu\n";
> +	    }
>   	}
>   	if ($net->{ip6}) {
>   	    if ($net->{ip6} =~ /^(auto|dhcp)$/) {
> @@ -200,6 +211,9 @@ sub configdrive2_network {
>   		$content .= "        netmask $mask\n";
>   		$content .= "        gateway $net->{gw6}\n" if $net->{gw6};
>   	    }
> +	    if (defined($mtu) && $mtu ne "") {
> +		$content .= "        mtu $mtu\n";
> +	    }
>   	}
>       }
>   
> @@ -261,6 +275,7 @@ sub nocloud_network_v2 {
>   
>   	my $net = PVE::QemuServer::parse_net($conf->{$iface});
>   	my $ipconfig = PVE::QemuServer::parse_ipconfig($conf->{"ipconfig$id"});
> +	next if !defined($ipconfig);
>   
>   	my $mac = $net->{macaddr}
>   	    or die "network interface '$iface' has no mac address\n";
> @@ -295,6 +310,10 @@ sub nocloud_network_v2 {
>   	if (defined(my $gw = $ipconfig->{gw6})) {
>   	    $content .= "${i}gateway6: '$gw'\n";
>   	}
> +	my $mtu = $ipconfig->{mtu};
> +	if (defined($mtu) && $mtu ne "") {
> +	    $content .= "${i}mtu: $mtu\n";
> +	}
>   
>   	next if $dns_done;
>   	$dns_done = 1;
> @@ -332,14 +351,22 @@ sub nocloud_network {
>   
>   	my $net = PVE::QemuServer::parse_net($conf->{$iface});
>   	my $ipconfig = PVE::QemuServer::parse_ipconfig($conf->{"ipconfig$id"});
> +	next if !defined($ipconfig);
>   
>   	my $mac = lc($net->{macaddr})
>   	    or die "network interface '$iface' has no mac address\n";
>   
> +	my $mtu = $ipconfig->{mtu};
> +
>   	$content .= "${i}- type: physical\n"
>   	          . "${i}  name: eth$id\n"
> -	          . "${i}  mac_address: '$mac'\n"
> -	          . "${i}  subnets:\n";
> +	          . "${i}  mac_address: '$mac'\n";
> +
> +	if (defined($mtu) && $mtu ne "") {
> +	    $content .= "${i}  mtu: $mtu\n";
> +	}
> +
> +	$content .= "${i}  subnets:\n";
>   	$i .= '  ';
>   	if (defined(my $ip = $ipconfig->{ip})) {
>   	    if ($ip eq 'dhcp') {




^ permalink raw reply	[flat|nested] 9+ messages in thread

* [pve-devel] [PATCH qemu-server] api: cloud-init support for mtu and userdata
  2020-07-02 16:08 [pve-devel] Extend cloud-init API with MTU " Marius Schellenberger
@ 2020-07-02 16:08 ` Marius Schellenberger
  2020-07-13 12:51   ` Mira Limbeck
  0 siblings, 1 reply; 9+ messages in thread
From: Marius Schellenberger @ 2020-07-02 16:08 UTC (permalink / raw)
  To: pve-devel; +Cc: Marius Schellenberger

Extended the PVE API to configure cloud-init userdata and network
interface MTU.

Signed-off-by: Marius Schellenberger <proxmox@giftfish.de>
---
 PVE/API2/Qemu.pm            |  1 +
 PVE/QemuServer.pm           | 18 +++++++++++++++++-
 PVE/QemuServer/Cloudinit.pm | 31 +++++++++++++++++++++++++++++--
 3 files changed, 47 insertions(+), 3 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index b33359d..02507de 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -324,6 +324,7 @@ my $cloudinitoptions = {
     cipassword => 1,
     citype => 1,
     ciuser => 1,
+    ciuserdata => 1,
     nameserver => 1,
     searchdomain => 1,
     sshkeys => 1,
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 6872e06..ef4342d 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -727,6 +727,12 @@ my $confdesc_cloudinit = {
 	description => 'cloud-init: Specify custom files to replace the automatically generated ones at start.',
 	format => 'pve-qm-cicustom',
     },
+    ciuserdata => {
+        optional => 1,
+        type => 'string',
+        format => 'urlencoded',
+        description => 'cloud-init: Specify custom user-data as urlencoded base64 string to replace the automatically generated one at start. When set, the following options have no effect: `ciuser`, `cipassword`, `sshkeys`',
+    },
     searchdomain => {
 	optional => 1,
 	type => 'string',
@@ -932,6 +938,12 @@ my $ipconfig_fmt = {
 	optional => 1,
 	requires => 'ip6',
     },
+    mtu => {
+	type => 'string',
+	format_description => 'MTU',
+	description => 'MTU value for interface.',
+	optional => 1,
+    },
 };
 PVE::JSONSchema::register_format('pve-qm-ipconfig', $ipconfig_fmt);
 my $ipconfigdesc = {
@@ -1701,7 +1713,7 @@ sub parse_net {
     return $res;
 }
 
-# ipconfigX ip=cidr,gw=ip,ip6=cidr,gw6=ip
+# ipconfigX ip=cidr,gw=ip,ip6=cidr,gw6=ip,mtu=mtu
 sub parse_ipconfig {
     my ($data) = @_;
 
@@ -1711,6 +1723,10 @@ sub parse_ipconfig {
 	return undef;
     }
 
+    if ($res->{mtu} && !$res->{ip} && !$res->{ip6}) {
+	warn 'mtu specified without specifying an IP or IPv6 address';
+	return undef;
+    }
     if ($res->{gw} && !$res->{ip}) {
 	warn 'gateway specified without specifying an IP address';
 	return undef;
diff --git a/PVE/QemuServer/Cloudinit.pm b/PVE/QemuServer/Cloudinit.pm
index 439de99..a47e0ce 100644
--- a/PVE/QemuServer/Cloudinit.pm
+++ b/PVE/QemuServer/Cloudinit.pm
@@ -6,6 +6,7 @@ use warnings;
 use File::Path;
 use Digest::SHA;
 use URI::Escape;
+use MIME::Base64 qw(decode_base64);
 
 use PVE::Tools qw(run_command file_set_contents);
 use PVE::Storage;
@@ -111,6 +112,11 @@ sub get_dns_conf {
 sub cloudinit_userdata {
     my ($conf, $vmid) = @_;
 
+    my $userdata = $conf->{ciuserdata};
+    if (defined($userdata) && $userdata ne "") {
+        return decode_base64(uri_unescape($userdata));
+    }
+
     my ($hostname, $fqdn) = get_hostname_fqdn($conf, $vmid);
 
     my $content = "#cloud-config\n";
@@ -176,7 +182,9 @@ sub configdrive2_network {
 	(my $id = $iface) =~ s/^net//;
 	next if !$conf->{"ipconfig$id"};
 	my $net = PVE::QemuServer::parse_ipconfig($conf->{"ipconfig$id"});
+	next if !defined($net);
 	$id = "eth$id";
+	my $mtu = $net->{mtu};
 
 	$content .="auto $id\n";
 	if ($net->{ip}) {
@@ -189,6 +197,9 @@ sub configdrive2_network {
 		$content .= "        netmask $mask\n";
 		$content .= "        gateway $net->{gw}\n" if $net->{gw};
 	    }
+	    if (defined($mtu) && $mtu ne "") {
+		$content .= "        mtu $mtu\n";
+	    }
 	}
 	if ($net->{ip6}) {
 	    if ($net->{ip6} =~ /^(auto|dhcp)$/) {
@@ -200,6 +211,9 @@ sub configdrive2_network {
 		$content .= "        netmask $mask\n";
 		$content .= "        gateway $net->{gw6}\n" if $net->{gw6};
 	    }
+	    if (defined($mtu) && $mtu ne "") {
+		$content .= "        mtu $mtu\n";
+	    }
 	}
     }
 
@@ -261,6 +275,7 @@ sub nocloud_network_v2 {
 
 	my $net = PVE::QemuServer::parse_net($conf->{$iface});
 	my $ipconfig = PVE::QemuServer::parse_ipconfig($conf->{"ipconfig$id"});
+	next if !defined($ipconfig);
 
 	my $mac = $net->{macaddr}
 	    or die "network interface '$iface' has no mac address\n";
@@ -295,6 +310,10 @@ sub nocloud_network_v2 {
 	if (defined(my $gw = $ipconfig->{gw6})) {
 	    $content .= "${i}gateway6: '$gw'\n";
 	}
+	my $mtu = $ipconfig->{mtu};
+	if (defined($mtu) && $mtu ne "") {
+	    $content .= "${i}mtu: $mtu\n";
+	}
 
 	next if $dns_done;
 	$dns_done = 1;
@@ -332,14 +351,22 @@ sub nocloud_network {
 
 	my $net = PVE::QemuServer::parse_net($conf->{$iface});
 	my $ipconfig = PVE::QemuServer::parse_ipconfig($conf->{"ipconfig$id"});
+	next if !defined($ipconfig);
 
 	my $mac = lc($net->{macaddr})
 	    or die "network interface '$iface' has no mac address\n";
 
+	my $mtu = $ipconfig->{mtu};
+
 	$content .= "${i}- type: physical\n"
 	          . "${i}  name: eth$id\n"
-	          . "${i}  mac_address: '$mac'\n"
-	          . "${i}  subnets:\n";
+	          . "${i}  mac_address: '$mac'\n";
+
+	if (defined($mtu) && $mtu ne "") {
+	    $content .= "${i}  mtu: $mtu\n";
+	}
+
+	$content .= "${i}  subnets:\n";
 	$i .= '  ';
 	if (defined(my $ip = $ipconfig->{ip})) {
 	    if ($ip eq 'dhcp') {
-- 
2.27.0



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-09-09 14:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-13 15:06 [pve-devel] [PATCH qemu-server] api: cloud-init support for mtu and userdata Julien Escario
  -- strict thread matches above, loose matches on Subject: below --
2020-09-04 15:21 proxmox
2020-09-07  7:33 ` Alexandre DERUMIER
2020-09-09  9:06   ` proxmox
2020-09-09 13:02     ` Alexandre DERUMIER
2020-09-09 13:46       ` Alexandre DERUMIER
2020-09-09 14:05 ` Mira Limbeck
2020-07-02 16:08 [pve-devel] Extend cloud-init API with MTU " Marius Schellenberger
2020-07-02 16:08 ` [pve-devel] [PATCH qemu-server] api: cloud-init support for mtu " Marius Schellenberger
2020-07-13 12:51   ` Mira Limbeck

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