Commit changes to handle flushing output to browser.
git-svn-id: https://svn.code.sf.net/p/xcat/code/xcat-core/trunk@9288 8638fb3e-16cb-4fca-ae20-7b5d299a9bcd
This commit is contained in:
parent
5274fe7947
commit
d8c5a3c51d
@ -326,7 +326,16 @@ function createStatusBar(barId) {
|
||||
*/
|
||||
function createInfoBar(msg) {
|
||||
var infoBar = $('<div class="ui-state-highlight ui-corner-all"></div>');
|
||||
var msg = $('<p><span class="ui-icon ui-icon-info"></span>' + msg + '</p>');
|
||||
var icon = $('<span class="ui-icon ui-icon-info"></span>').css({
|
||||
'display': 'inline-block',
|
||||
'margin': '10px 5px'
|
||||
});
|
||||
var msg = $('<p>' + msg + '</p>').css({
|
||||
'display': 'inline-block',
|
||||
'width': '95%'
|
||||
});
|
||||
|
||||
infoBar.append(icon);
|
||||
infoBar.append(msg);
|
||||
return infoBar;
|
||||
}
|
||||
@ -563,3 +572,29 @@ function openDialog(type, msg) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an iframe to hold the output of an xCAT command
|
||||
*
|
||||
* @param src
|
||||
* The URL of the document to show in the iframe
|
||||
* @return Info box containing the iframe
|
||||
*/
|
||||
function createIFrame(src) {
|
||||
// Put an iframe inside an info box
|
||||
var infoBar = $('<div class="ui-state-highlight ui-corner-all"></div>');
|
||||
var icon = $('<span class="ui-icon ui-icon-info"></span>').css({
|
||||
'display': 'inline-block',
|
||||
'margin': '10px 5px'
|
||||
});
|
||||
var iframe = $('<iframe></iframe>').attr('src', src).css({
|
||||
'display': 'inline-block',
|
||||
'border': '0px',
|
||||
'margin': '10px 0px',
|
||||
'width': '95%'
|
||||
});
|
||||
|
||||
infoBar.append(icon);
|
||||
infoBar.append(iframe);
|
||||
return infoBar;
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ require_once "$TOPDIR/lib/jsonwrapper.php";
|
||||
* @param $cmd The xCAT command
|
||||
* $tgt The target node or group
|
||||
* $args The xCAT command arguments, separated by semicolons
|
||||
* $opts The xCAT command options, separated by semicolons
|
||||
* @return The xCAT response. Replies are in the form of JSON
|
||||
*/
|
||||
if (isset($_GET["cmd"])) {
|
||||
@ -19,7 +20,7 @@ if (isset($_GET["cmd"])) {
|
||||
$cmd = $_GET["cmd"];
|
||||
$tgt = $_GET["tgt"];
|
||||
$args = $_GET["args"];
|
||||
|
||||
|
||||
// Special messages put here
|
||||
// This gets sent back to the AJAX request as is.
|
||||
$msg = $_GET["msg"];
|
||||
@ -34,22 +35,41 @@ if (isset($_GET["cmd"])) {
|
||||
$msg = NULL;
|
||||
}
|
||||
|
||||
// If no $args is given, set $arr to NULL
|
||||
if (!$args) {
|
||||
$arr = array();
|
||||
} else {
|
||||
// If no $args are given, set $args_array to NULL
|
||||
$args_array = array();
|
||||
if ($args) {
|
||||
// If $args contains multiple arguments, split it into an array
|
||||
if (strpos($args,";")) {
|
||||
// Split the arguments into an array
|
||||
$arr = array();
|
||||
$arr = explode(";", $args);
|
||||
$args_array = array();
|
||||
$args_array = explode(";", $args);
|
||||
} else {
|
||||
$arr = array($args);
|
||||
$args_array = array($args);
|
||||
}
|
||||
}
|
||||
|
||||
// If no $opts are given, set $opts_array to NULL
|
||||
$opts_array = array();
|
||||
if (isset($_GET["opts"])) {
|
||||
$opts = $_GET["opts"];
|
||||
|
||||
// If $args contains multiple arguments, split it into an array
|
||||
if (strpos($opts,";")) {
|
||||
// Split the arguments into an array
|
||||
$opts_array = array();
|
||||
$opts_array = explode(";", $opts);
|
||||
} else {
|
||||
$opts_array = array($opts);
|
||||
}
|
||||
}
|
||||
|
||||
// Submit request and get response
|
||||
$xml = docmd($cmd, $tgt, $arr);
|
||||
$xml = docmd($cmd, $tgt, $args_array, $opts_array);
|
||||
// If the output is flushed, do not return output in JSON
|
||||
if (in_array("flush", $opts_array)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$rsp = array();
|
||||
|
||||
// webrun pping and gangliastatus output needs special handling
|
||||
|
@ -12,19 +12,20 @@ error_reporting(E_ALL);
|
||||
ini_set('display_errors', true);
|
||||
|
||||
/**
|
||||
* Description: Run a command using the xCAT client/server protocol
|
||||
* Run a command using the xCAT client/server protocol
|
||||
*
|
||||
* @param $cmd The xCAT command
|
||||
* $nr Node range or group
|
||||
* $args Command arguments
|
||||
* @param $cmd The xCAT command
|
||||
* $nr Node range or group
|
||||
* $args_array Command arguments
|
||||
* $opts_array Command options
|
||||
* @return A tree of SimpleXML objects.
|
||||
* See perl-xCAT/xCAT/Client.pm for the format
|
||||
*/
|
||||
function docmd($cmd, $nr, $args){
|
||||
function docmd($cmd, $nr, $args_array, $opts_array){
|
||||
// If we are not logged in,
|
||||
// do not try to communicate with xcatd
|
||||
if (!is_logged()) {
|
||||
echo "<p>docmd: Not logged in - cannot run command</p>";
|
||||
echo "<p>You are not logged in! Failed to run command.</p>";
|
||||
return simplexml_load_string('<xcat></xcat>', 'SimpleXMLElement', LIBXML_NOCDATA);
|
||||
}
|
||||
|
||||
@ -33,8 +34,8 @@ function docmd($cmd, $nr, $args){
|
||||
$request = simplexml_load_string('<xcatrequest></xcatrequest>');
|
||||
$request->addChild('command', $cmd);
|
||||
if(!empty($nr)) { $request->addChild('noderange', $nr); }
|
||||
if (!empty($args)) {
|
||||
foreach ($args as $a) {
|
||||
if (!empty($args_array)) {
|
||||
foreach ($args_array as $a) {
|
||||
$request->addChild('arg',$a);
|
||||
}
|
||||
}
|
||||
@ -44,23 +45,37 @@ function docmd($cmd, $nr, $args){
|
||||
$usernode->addChild('username',$_SESSION["username"]);
|
||||
$usernode->addChild('password',getpassword());
|
||||
|
||||
$xml = submit_request($request,0);
|
||||
$xml = submit_request($request, 0, $opts_array);
|
||||
return $xml;
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by docmd()
|
||||
* Used by docmd() to submit request to xCAT
|
||||
*
|
||||
* @param $req Tree of SimpleXML objects
|
||||
* @param $req Tree of SimpleXML objects
|
||||
* @param $opts_array Request options
|
||||
* @return A tree of SimpleXML objects
|
||||
*/
|
||||
function submit_request($req, $skipVerify){
|
||||
function submit_request($req, $skipVerify, $opts_array){
|
||||
$xcathost = "localhost";
|
||||
$port = "3001";
|
||||
$rsp = FALSE;
|
||||
$response = '';
|
||||
$cleanexit = 0;
|
||||
|
||||
// Determine whether to flush output or not
|
||||
$flush = false;
|
||||
if (in_array("flush", $opts_array)) {
|
||||
$flush = true;
|
||||
}
|
||||
|
||||
// Determine how to handle the flush output
|
||||
// You can specify a function name, in place of TBD, to handle the flush output
|
||||
$flush_format = "";
|
||||
if (in_array("flush-format=TBD", $opts_array)) {
|
||||
$flush_format = "TBD";
|
||||
}
|
||||
|
||||
// Open syslog, include the process ID and also send
|
||||
// the log to standard error, and use a user defined
|
||||
// logging mechanism
|
||||
@ -84,7 +99,15 @@ function submit_request($req, $skipVerify){
|
||||
$str = fread($fp, 8192);
|
||||
if ($str) {
|
||||
$response .= preg_replace('/>\n\s*</', '><', $str);
|
||||
// syslog(LOG_INFO, "($nr) Reading partial response: $response");
|
||||
|
||||
// Flush output to browser
|
||||
if ($flush) {
|
||||
// Strip HTML tags from output
|
||||
if ($tmp = trim(strip_tags($str))) {
|
||||
echo $tmp . '<br/>';
|
||||
flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Look for serverdone response
|
||||
|
Loading…
Reference in New Issue
Block a user