Status display and some actual functionality

feature/node-rewrite
Sven Slootweg 13 years ago
parent 6648f50603
commit df7751ce80

@ -63,6 +63,12 @@ class Container extends CPHPDatabaseRecordClass
case "sBandwidthUsed":
return $this->GetBandwidthUsed();
break;
case "sStatus":
return (int)$this->GetStatus();
break;
case "sStatusText":
return $this->GetStatusText();
break;
default:
return null;
break;
@ -74,6 +80,47 @@ class Container extends CPHPDatabaseRecordClass
return ($this->sOutgoingTrafficUsed + $this->IncomingTrafficUsed) / (1024 * 1024);
}
public function GetStatus()
{
$command = "vzctl status {$this->sInternalId}";
$result = $this->sNode->ssh->RunCommandCached($command, false);
if($result->returncode == 0)
{
$values = split_whitespace($result->stdout);
if($values[4] == "running")
{
return CVM_STATUS_STARTED;
}
else
{
return CVM_STATUS_STOPPED;
}
}
}
public function GetStatusText()
{
if($this->GetStatus() == CVM_STATUS_STARTED)
{
return "running";
}
elseif($this->GetStatus() == CVM_STATUS_STOPPED)
{
return "stopped";
}
elseif($this->GetStatus() == CVM_STATUS_SUSPENDED)
{
return "suspended";
}
else
{
return "unknown";
}
}
public function Deploy($conf = array())
{
$sRootPassword = random_string(20);

@ -255,8 +255,61 @@ table.vpsinfo td
font-weight: bold;
}
.suspended
.suspended, .unknown
{
color: #5B5F6B;
font-weight: bold;
}
/* CPHPErrorHandler styles */
.errorhandler
{
margin: 10px 0px;
padding: 8px 10px;
padding-left: 46px;
background-position: 8px 6px;
background-repeat: no-repeat;
min-height: 24px;
}
.errorhandler .error-title
{
font-weight: bold;
font-size: 120%;
}
.errorhandler.error-error
{
background-color: #FCCBC9;
border: 1px solid red;
background-image: url(../images/errorhandler_error.png);
}
.errorhandler.error-info
{
background-color: #C9F6FC;
border: 1px solid blue;
background-image: url(../images/errorhandler_info.png);
}
.errorhandler.error-warning
{
background-color: #FBFCC9;
border: 1px solid #C5BA00;
background-image: url(../images/errorhandler_warning.png);
}
.errorhandler.error-success
{
background-color: #DEFCC9;
border: 1px solid #4CC500;
background-image: url(../images/errorhandler_success.png);
}
.errorhandler ul
{
margin: 0px;
padding-left: 24px;
}

@ -7,8 +7,81 @@ $settings['master_pubkey'] = "/etc/cvm/key.pub";
$settings['salt'] = "kAU0qM";
$sContainer = new Container(1);
$sError = "";
if($_GET['action'] == "start")
{
if($sContainer->GetStatus() != CVM_STATUS_STARTED)
{
try
{
$sContainer->Start();
$err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_SUCCESS, "Container started", "Your container was successfully started.");
$sError .= $err->Render();
}
catch(ContainerStartException $e)
{
$err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Container failed to start", "Your container could not be started. If this error persists, please file a support ticket.");
$sError .= $err->Render();
}
}
else
{
$err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Container can't be started", "Your container cannot be started because it is already running.");
$sError .= $err->Render();
}
}
elseif($_GET['action'] == "stop")
{
if($sContainer->GetStatus() != CVM_STATUS_STOPPED)
{
try
{
$sContainer->Stop();
$err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_SUCCESS, "Container stopped", "Your container was successfully stopped.");
$sError .= $err->Render();
}
catch(ContainerStartException $e)
{
$err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Container failed to stop", "Your container could not be stopped. If this error persists, please file a support ticket.");
$sError .= $err->Render();
}
}
else
{
$err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Container can't be stopped", "Your container cannot be stopped because it is not running.");
$sError .= $err->Render();
}
}
elseif($_GET['action'] == "restart")
{
try
{
try
{
$sContainer->Stop();
}
catch(ContainerStopException $e)
{
// we can make this silently fail, as the only important thing is that it starts again
}
$sContainer->Start();
$err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_SUCCESS, "Container restarted", "Your container was successfully restarted.");
$sError .= $err->Render();
}
catch(ContainerStartException $e)
{
$err = new CPHPErrorHandler(CPHP_ERRORHANDLER_TYPE_ERROR, "Container failed to start", "Your container could not be started. If this error persists, please file a support ticket.");
$sError .= $err->Render();
}
}
echo(Templater::InlineRender("main", $locale->strings, array(
'error' => $sError,
'server-location' => $sContainer->sNode->sPhysicalLocation,
'operating-system' => $sContainer->sTemplate->sName,
'guaranteed-ram' => "{$sContainer->sGuaranteedRam}MB",

@ -23,6 +23,9 @@
<a class="button" id="button_alerts" href="#">Alerts</a>
<a class="button" id="button_api" href="#">API</a>
</div>
<%?error>
<h1>Overview</h1>
<!-- <h2>Consolidated traffic example</h2> -->
@ -72,7 +75,7 @@
<table class="vpsinfo">
<tr>
<th>Status</th>
<td><span class="online">Running</span> <span class="offline">Stopped</span> <span class="suspended">Suspended</span> </td>
<td><%?status></td>
</tr>
<tr>
<th>Server location</th>

Loading…
Cancel
Save