]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add server parameter to vsphere plugin hosts API endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Mon, 13 Mar 2023 09:06:40 +0000 (10:06 +0100)
committerMarcin Haba <marcin.haba@bacula.pl>
Thu, 20 Apr 2023 10:00:25 +0000 (12:00 +0200)
gui/baculum/protected/API/Pages/API/PluginVSphereListHosts.php

index 85351724a3825470c270b3f5d22706385f0f332a..a57ee50282b109645310446051c84274e149a16c 100644 (file)
@@ -60,12 +60,17 @@ class PluginVSphereListHosts extends ConsoleOutputQueryPage {
                        return;
                }
 
+               $misc = $this->getModule('misc');
                $out_format = ConsoleOutputPage::OUTPUT_FORMAT_RAW;
                if ($this->Request->contains('output') && $this->isOutputFormatValid($this->Request['output'])) {
                        $out_format = $this->Request['output'];
                }
+               $server = $this->Request->contains('server') && $misc->isValidName($this->Request['server'])? $this->Request['server'] : '';
 
-               $plugin = 'vsphere: ';
+               $plugin = 'vsphere:';
+               if (!empty($server)) {
+                       $plugin .= ' server="' . $server . '"';
+               }
                $out = new \StdClass;
                $out->output = [];
                $params = ['client' => $client, 'plugin' => $plugin];
@@ -77,7 +82,7 @@ class PluginVSphereListHosts extends ConsoleOutputQueryPage {
 
                if ($out->exitcode !== 0) {
                        $out->error = PluginVSphereError::ERROR_EXECUTING_PLUGIN_QUERY_COMMAND;
-                       $out->output = PluginVSphereError::MSG_ERROR_EXECUTING_PLUGIN_QUERY_COMMAND . $out->output;
+                       $out->output = PluginVSphereError::MSG_ERROR_EXECUTING_PLUGIN_QUERY_COMMAND . implode(PHP_EOL, $out->output);
                        $this->getModule('logging')->log(
                                Logging::CATEGORY_EXECUTE,
                                $out->output . ", Error={$out->error}"
@@ -144,8 +149,8 @@ class PluginVSphereListHosts extends ConsoleOutputQueryPage {
                for ($i = 0; $i < count($output); $i++) {
                        if (preg_match('/^host=/', $output[$i]) === 1 && isset($output[$i+1])) {
                                $out[] = [
-                                       $output[$i],
-                                       $output[$i+1]
+                                       $output[$i],   // vm
+                                       $output[$i+1]  // moref
                                ];
                        }
                }