From d382ec9e8f6a21a7c531fcda2464af8568484750 Mon Sep 17 00:00:00 2001 From: Ken Moore Date: Tue, 14 Feb 2017 09:41:26 -0500 Subject: [PATCH] Validate/Fix the sysadm/iocage "activatepool" and "deactivatepoll" API calls. No change to the API, just cleaned it up to work with the newer python version of iocage. --- src/server/library/sysadm-iocage.cpp | 52 ++++++---------------------- 1 file changed, 11 insertions(+), 41 deletions(-) diff --git a/src/server/library/sysadm-iocage.cpp b/src/server/library/sysadm-iocage.cpp index 97ec8b0..e839634 100644 --- a/src/server/library/sysadm-iocage.cpp +++ b/src/server/library/sysadm-iocage.cpp @@ -1,6 +1,6 @@ //=========================================== // PC-BSD source code -// Copyright (c) 2015, PC-BSD Software/iXsystems +// Copyright (c) 2015-2017, PC-BSD Software/iXsystems // Available under the 3-clause BSD license // See the LICENSE file for full details //=========================================== @@ -10,8 +10,6 @@ using namespace sysadm; -//PLEASE: Keep the functions in the same order as listed in pcbsd-general.h - // Execute a process in a jail on the box QJsonObject Iocage::execJail(QJsonObject jsin) { QJsonObject retObject; @@ -345,19 +343,15 @@ QJsonObject Iocage::deactivatePool(QJsonObject jsin) { // Get the key values QString pool = jsin.value("pool").toString(); - QStringList output = General::RunCommand("iocage deactivate " + pool).split("\n"); + bool success = false; + QStringList output = General::RunCommand(success, "iocage deactivate " + pool).split("\n"); QJsonObject vals; - for ( int i = 0; i < output.size(); i++) - { - if ( ! output.at(i).isEmpty()) - break; - - // When a pool deactivation is successful, iocage doesn't return anything, - // so we have to fudge the output a bit. + if (success){ retObject.insert("success", "pool " + pool + " deactivated."); + }else{ + retObject.insert("error", output.join("\n")); } - return retObject; } @@ -368,37 +362,13 @@ QJsonObject Iocage::activatePool(QJsonObject jsin) { // Get the key values QString pool = jsin.value("pool").toString(); - QStringList output = General::RunCommand("iocage activate " + pool).split("\n"); - QJsonObject vals; - - for ( int i = 0; i < output.size(); i++) - { - // Otherwise we get null output before the actual active pool - if ( i > 0 ) - break; - - // When a pool activation is successful, iocage doesn't return anything, - // so we have to fudge the output a bit. - if ( output.at(i).isEmpty()) - { + bool success = false; + QStringList output = General::RunCommand(success, "iocage activate " + pool).split("\n"); + if(success){ retObject.insert("success", "pool " + pool + " activated."); - break; - } else { - QString key = output.at(i).simplified().section(":", 0, 0); - QString value = output.at(i).simplified().section(":", 1, 1); - - vals.insert(key, value); - - // This means no pool exists, give them the error. - if ( output.at(i).indexOf("ERROR:") != -1 ) { - retObject.insert("error", output.at(i)); - break; - - retObject.insert("currently active", vals); - } - } + } else { + retObject.insert("error", output.join("\n")); } - return retObject; }