public function terminateAction($serverId)
{
$server = $this->getServer($serverId);
$this->checkPermissions($server, Acl::PERM_FARMS_SERVERS);
if (in_array($server->status, [Server::STATUS_IMPORTING, Server::STATUS_TEMPORARY])) {
throw new ApiErrorException(409, ErrorMessage::ERR_UNACCEPTABLE_STATE, sprintf("The Server can't be terminated in %s state.", $server->status));
}
if ($server->platform == SERVER_PLATFORMS::EC2 && !empty($server->properties[EC2_SERVER_PROPERTIES::IS_LOCKED])) {
throw new ApiErrorException(409, ErrorMessage::ERR_LOCKED, "Server has disableAPITermination flag and can not be terminated.");
}
$object = $this->request->getJsonBody();
$force = isset($object->force) ? ServerAdapter::convertInputValue('boolean', $object->force) : false;
if ((PlatformFactory::isOpenstack($server->platform) || PlatformFactory::isCloudstack($server->platform)) && $force) {
throw new ApiErrorException(400, ErrorMessage::ERR_INVALID_VALUE, sprintf("Force termination is not available for platform %s.", $server->platform));
}
if (!$server->terminate([Server::TERMINATE_REASON_MANUALLY_API, $this->getUser()->fullName], $force, $this->getUser())) {
throw new ApiErrorException(409, ErrorMessage::ERR_UNACCEPTABLE_STATE, sprintf("Server with id %s has already been terminated.", $serverId));
}
$this->response->setStatus(200);
return $this->result($this->adapter('server')->toData($server));
}