From 5e934933eca7543388100ac8978f7dac745d33a9 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Fri, 8 Mar 2024 14:06:47 +0100 Subject: [PATCH] esxi import: deal with serial devices Signed-off-by: Wolfgang Bumiller --- src/PVE/Storage/ESXiPlugin.pm | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/PVE/Storage/ESXiPlugin.pm b/src/PVE/Storage/ESXiPlugin.pm index 31b011f..164d14f 100644 --- a/src/PVE/Storage/ESXiPlugin.pm +++ b/src/PVE/Storage/ESXiPlugin.pm @@ -775,6 +775,28 @@ sub for_each_netdev { return; } +sub for_each_serial { + my ($self, $code) = @_; + + my $found_serials = {}; + for my $key (sort keys %$self) { + next if $key !~ /^serial(\d+)\.(.+)$/; + my ($slot, $opt) = ($1, $2); + my $serial = ($found_serials->{$1} //= {}); + $serial->{$opt} = $self->{$key}; + } + + for my $id (sort { $a <=> $b } keys %$found_serials) { + my $serial = $found_serials->{$id}; + + next if ($serial->{present} // '') ne 'TRUE'; + + $code->($id, $serial); + } + + return; +} + sub firmware { my ($self) = @_; my $fw = $self->{firmware}; @@ -1031,6 +1053,15 @@ sub get_create_args { $create_args->{name} = $name if length($name); } + my $serid = 0; + $self->for_each_serial(sub { + my ($id, $serial) = @_; + # currently we only support 'socket' type serials anyway + $warn->("serial ports are currently all mapped to sockets") if $serid == 0; + $create_args->{"serial$serid"} = 'socket'; + ++$serid; + }); + return { type => 'vm', source => 'esxi',