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
{
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();
}
@ -44,8 +45,15 @@ class SshConnector extends CPHPBaseClass
catch (SshConnectException $e)
{
$error = $e->getMessage();
$command = implode(" ", $command);
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)

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

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

Loading…
Cancel
Save