Better error handling when a node is unreachable

feature/node-rewrite
Sven Slootweg 12 years ago
parent 84b03d4c3c
commit c716f98db6

@ -34,8 +34,9 @@ class SshConnector extends CPHPBaseClass
{ {
try try
{ {
if($this->connected == false && $this->authenticated == false) if($this->connected == false || $this->authenticated == false)
{ {
/* TODO: Don't attempt to connect again if it failed the first time. */
$this->Connect(); $this->Connect();
} }
@ -44,8 +45,15 @@ class SshConnector extends CPHPBaseClass
catch (SshConnectException $e) catch (SshConnectException $e)
{ {
$error = $e->getMessage(); $error = $e->getMessage();
$command = implode(" ", $command);
throw new SshConnectException("Could not run command {$command}: Failed to connect: {$error}"); throw new SshConnectException("Could not run command {$command}: Failed to connect: {$error}");
} }
catch (SshAuthException $e)
{
$error = $e->getMessage();
$command = implode(" ", $command);
throw new SshConnectException("Could not run command {$command}: Failed to authenticate: {$error}");
}
} }
public function RunCommandCached($command, $throw_exception = false) public function RunCommandCached($command, $throw_exception = false)

@ -14,10 +14,11 @@
if(!isset($_CVM)) { die("Unauthorized."); } if(!isset($_CVM)) { die("Unauthorized."); }
// SshConnector-related exceptions // SshConnector-related exceptions
class SshConnectException extends Exception {} class SshException extends Exception {}
class SshAuthException extends Exception {} class SshConnectException extends SshException {}
class SshCommandException extends Exception {} class SshAuthException extends SshException {}
class SshExitException extends Exception {} class SshCommandException extends SshException {}
class SshExitException extends SshException {}
// Container-related exceptions // Container-related exceptions
class ContainerException extends Exception class ContainerException extends Exception

@ -22,6 +22,16 @@ if($sLoggedIn === true)
foreach($result->data as $row) foreach($result->data as $row)
{ {
$sContainer = new Container($row); $sContainer = new Container($row);
try
{
$sStatus = $sContainer->sStatusText;
}
catch (SshException $e)
{
$sStatus = "stopped";
}
$sContainerList[] = array( $sContainerList[] = array(
'id' => $sContainer->sId, 'id' => $sContainer->sId,
'hostname' => $sContainer->sHostname, 'hostname' => $sContainer->sHostname,
@ -32,7 +42,7 @@ if($sLoggedIn === true)
'diskspace-unit' => "GB", 'diskspace-unit' => "GB",
'guaranteed-ram' => $sContainer->sGuaranteedRam, 'guaranteed-ram' => $sContainer->sGuaranteedRam,
'guaranteed-ram-unit' => "MB", 'guaranteed-ram-unit' => "MB",
'status' => $sContainer->sStatusText, 'status' => $sStatus,
'virtualization-type' => $sContainer->sVirtualizationType 'virtualization-type' => $sContainer->sVirtualizationType
); );
} }

Loading…
Cancel
Save