[pve-devel] [PATCH common 1/1] RESTEnvironment: add helper for other env-types

Stoiko Ivanov s.ivanov at proxmox.com
Tue Nov 27 17:46:04 CET 2018


Fix #1922.
In some cases we want most of the settings done like for a standard CLI
environment, without setting the type 'cli'.

This is needed in cases where we don't want to receive the log-output
of fork_worker, which prints it to stdout if run via a 'cli' environment without
the background argument.

For #1922 this is needed when calling pvesh via ssh with --output_format json in
case a call gets proxied to another node.

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
 src/PVE/RESTEnvironment.pm | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/PVE/RESTEnvironment.pm b/src/PVE/RESTEnvironment.pm
index aca18bc..47a527a 100644
--- a/src/PVE/RESTEnvironment.pm
+++ b/src/PVE/RESTEnvironment.pm
@@ -141,14 +141,20 @@ sub init {
 # convenience function for command line tools
 sub setup_default_cli_env {
     my ($class, $username) = @_;
+    $class->setup_default_env($username, 'cli');
+}
+
+sub setup_default_env {
+    my ($class, $username, $type) = @_;
 
     $class = ref($class) || $class;
 
     $username //= 'root at pam';
+    $type //= 'cli';
 
     PVE::INotify::inotify_init();
 
-    my $rpcenv = $class->init('cli');
+    my $rpcenv = $class->init($type);
     $rpcenv->init_request();
     $rpcenv->set_language($ENV{LANG});
     $rpcenv->set_user($username);
-- 
2.11.0





More information about the pve-devel mailing list