From c95ccad6dfb84f3caa1b2497071c235c90f6e3b0 Mon Sep 17 00:00:00 2001 From: Sven Slootweg Date: Wed, 9 May 2012 02:41:35 +0200 Subject: [PATCH] Destroy and Reinstall functions for Container class --- frontend/classes/class.container.php | 33 ++++++++++++++++++++++++ frontend/includes/include.exceptions.php | 3 +++ 2 files changed, 36 insertions(+) diff --git a/frontend/classes/class.container.php b/frontend/classes/class.container.php index 2d9e00d..cf06ab3 100644 --- a/frontend/classes/class.container.php +++ b/frontend/classes/class.container.php @@ -367,6 +367,39 @@ class Container extends CPHPDatabaseRecordClass } } + public function Destroy() + { + $this->Stop(); + $command = "vzctl destroy {$this->sInternalId}"; + $result = $this->sNode->ssh->RunCommand($command, false); + + if($result->returncode == 0) + { + return true; + } + else + { + throw new ContainerDestroyException("Destroying container failed: {$result->stderr}", $result->returncode, $this->sInternalId); + } + } + + public function Reinstall() + { + try + { + $this->Destroy(); + $this->Deploy(); + } + catch (ContainerDestroyException $e) + { + throw new ContainerReinstallException("Reinstalling container failed during destroying: " . $e->getMessage(), $e->getCode(), $this->sInternalId); + } + catch (ContainerDeployException $e) + { + throw new ContainerReinstallException("Reinstalling container failed during deploying: " . $e->getMessage(), $e->getCode(), $this->sInternalId); + } + } + public function Start() { $command = "vzctl start {$this->sInternalId}"; diff --git a/frontend/includes/include.exceptions.php b/frontend/includes/include.exceptions.php index d5f718f..f6a6088 100644 --- a/frontend/includes/include.exceptions.php +++ b/frontend/includes/include.exceptions.php @@ -41,6 +41,9 @@ class ContainerCreateException extends ContainerException {} class ContainerConfigureException extends ContainerException {} class ContainerStartException extends ContainerException {} class ContainerStopException extends ContainerException {} +class ContainerDestroyException extends ContainerException {} +class ContainerReinstallException extends ContainerException {} +class ContainerDeployException extends ContainerException {} class ContainerIpAddException extends ContainerException {} class ContainerIpRemoveException extends ContainerException {} class ContainerTrafficRetrieveException extends ContainerException {}