[pve-devel] [PATCH manager 1/2] startall: refactor and fix error message

Thomas Lamprecht t.lamprecht at proxmox.com
Wed Jun 20 07:51:30 CEST 2018


On 6/19/18 2:27 PM, Dominik Csapak wrote:
> for vms, it showed:
> Starting VM 100 failed: status
> 
> instead of showing the actual status
> 
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
>  PVE/API2/Nodes.pm | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm
> index 2db5e1ec..a7d34fb1 100644
> --- a/PVE/API2/Nodes.pm
> +++ b/PVE/API2/Nodes.pm
> @@ -1563,11 +1563,13 @@ __PACKAGE__->register_method ({
>  				}
>  			    }
>  			} else {
> +			    my $typeText = '';
>  			    if ($d->{type} eq 'lxc') {
> -				print STDERR "Starting CT $vmid failed: $status\n";
> +				$typeText = ' CT';
>  			    } elsif ($d->{type} eq 'qemu') {
> -				print STDERR "Starting VM $vmid failed: status\n";
> +				$typeText = ' VM';
>  			    }
> +			    print STDERR "Starting$typeText $vmid failed: $status\n";
>  			}
>  		    };
>  		    warn $@ if $@;
> 

Hmm, we already have if/else for the guests above, so how about:

----8<----
diff --git a/PVE/API2/Nodes.pm b/PVE/API2/Nodes.pm
index 2db5e1ec..8b8d0e09 100644
--- a/PVE/API2/Nodes.pm
+++ b/PVE/API2/Nodes.pm
@@ -1534,12 +1534,15 @@ __PACKAGE__->register_method ({
                        my $default_delay = 0;
                        my $upid;

+                       my $guesttype;
                        if ($d->{type} eq 'lxc') {
+                           $guesttype = 'CT';
                            return if PVE::LXC::check_running($vmid);
                            print STDERR "Starting CT $vmid\n";
                            $upid = PVE::API2::LXC::Status->vm_start({node => $nodename, vmid => $vmid });
                        } elsif ($d->{type} eq 'qemu') {
                            $default_delay = 3; # to reduce load
+                           $guesttype = 'CT';
                            return if PVE::QemuServer::check_running($vmid, 1);
                            print STDERR "Starting VM $vmid\n";
                            $upid = PVE::API2::Qemu->vm_start({node => $nodename, vmid => $vmid });
@@ -1563,11 +1566,7 @@ __PACKAGE__->register_method ({
                                }
                            }
                        } else {
-                           if ($d->{type} eq 'lxc') {
-                               print STDERR "Starting CT $vmid failed: $status\n";
-                           } elsif ($d->{type} eq 'qemu') {
-                               print STDERR "Starting VM $vmid failed: status\n";
-                           }
+                           print STDERR "Starting $guesttype $vmid failed: $status\n";
                        }
                    };
                    warn $@ if $@;



More information about the pve-devel mailing list