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 {}