From 33fb4ef499963322bd974be2db671db6b80c5b97 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Wed, 19 Jun 2013 22:13:47 +0200 Subject: [PATCH] Add Vps::Terminate function --- frontend/classes/vps.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/frontend/classes/vps.php b/frontend/classes/vps.php index d842255..b0955b3 100644 --- a/frontend/classes/vps.php +++ b/frontend/classes/vps.php @@ -43,6 +43,9 @@ class Vps extends CPHPDatabaseRecordClass 'OutgoingTrafficLimit' => "OutgoingTrafficLimit", 'TotalTrafficLimit' => "TotalTrafficLimit" ), + 'timestamp' => array( + "TerminationDate" => "TerminationDate" + ), 'node' => array( 'Node' => "NodeId" ), @@ -575,6 +578,28 @@ class Vps extends CPHPDatabaseRecordClass } } + public function Terminate() + { + if($this->sStatus != CVM_STATUS_TERMINATED) + { + try + { + $this->Stop(); + $this->uStatus = CVM_STATUS_TERMINATED; + $this->uTerminationDate = time(); + $this->InsertIntoDatabase(); + } + catch (VpsStopException $e) + { + throw new VpsTerminateException("Termination failed as the VPS could not be stopped.", 1, $this->sInternalId, $e); + } + } + else + { + throw new VpsTerminateException("The VPS is already terminated.", 1, $this->sInternalId); + } + } + public function AddIp($ip) { $command = array("sudo", "vzctl", "set", $this->sInternalId, "--ipadd", $ip, "--save");