From 14e55c650ed5bbfc4e83ac18ec50eb78755d1e98 Mon Sep 17 00:00:00 2001 From: Thomas Lamprecht Date: Tue, 12 May 2020 14:48:31 +0200 Subject: [PATCH] api: fix reload all UPID handling run_command returns the exit code, we need to parse out the UPID from the outfunc. Signed-off-by: Thomas Lamprecht --- PVE/API2/Network/SDN.pm | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/PVE/API2/Network/SDN.pm b/PVE/API2/Network/SDN.pm index 4af2b6f..3f497fc 100644 --- a/PVE/API2/Network/SDN.pm +++ b/PVE/API2/Network/SDN.pm @@ -3,16 +3,17 @@ package PVE::API2::Network::SDN; use strict; use warnings; -use PVE::SafeSyslog; -use PVE::Tools; use PVE::Cluster qw(cfs_lock_file cfs_read_file cfs_write_file); +use PVE::Exception qw(raise_param_exc); +use PVE::JSONSchema qw(get_standard_option); use PVE::RESTHandler; use PVE::RPCEnvironment; -use PVE::JSONSchema qw(get_standard_option); -use PVE::Exception qw(raise_param_exc); +use PVE::SafeSyslog; +use PVE::Tools qw(run_command); + +use PVE::API2::Network::SDN::Controllers; use PVE::API2::Network::SDN::Vnets; use PVE::API2::Network::SDN::Zones; -use PVE::API2::Network::SDN::Controllers; use base qw(PVE::RESTHandler); @@ -68,8 +69,14 @@ __PACKAGE__->register_method({ my $create_reload_network_worker = sub { my ($nodename) = @_; - #fixme: how to proxy to final node ? - my $upid = PVE::Tools::run_command(['pvesh', 'set', "/nodes/$nodename/network"]); + # FIXME: how to proxy to final node ? + my $upid; + run_command(['pvesh', 'set', "/nodes/$nodename/network"], outfunc => sub { + my $line = shift; + if ($line =~ /^["']?(UPID:[^\s"']+)["']?$/) { + $upid = $1; + } + }); #my $upid = PVE::API2::Network->reload_network_config(node => $nodename}); my $res = PVE::Tools::upid_decode($upid); @@ -101,13 +108,14 @@ __PACKAGE__->register_method ({ $rpcenv->{type} = 'priv'; # to start tasks in background PVE::Cluster::check_cfs_quorum(); my $nodelist = PVE::Cluster::get_nodelist(); - foreach my $node (@$nodelist) { - - my $pid; - eval { $pid = &$create_reload_network_worker($node); }; + for my $node (@$nodelist) { + my $pid = eval { $create_reload_network_worker->($node) }; warn $@ if $@; - next if !$pid; } + + # FIXME: use libpve-apiclient (like in cluster join) to create + # tasks and moitor the tasks. + return; }; -- 2.39.5