http://modulesgarden.com * CONTACT -> contact@modulesgarden.com * * * This software is furnished under a license and may be used and copied * only in accordance with the terms of such license and with the * inclusion of the above copyright notice. This software or any other * copies thereof may not be provided or otherwise made available to any * other person. No title to and ownership of the software is hereby * transferred. * * * ******************************************************************** */ namespace MGProvision\Proxmox\v2\models; /** * Description of Task * * @author Pawel Kopec * @version 1.0.0 */ class Task extends AbstractObject { protected $starttime; protected $pstart; protected $id; protected $exitstatus; protected $pid; protected $user; protected $node; protected $upid; protected $type; protected $status; protected $endtime; private $path; public function getStarttime() { return $this->starttime; } public function getPstart() { return $this->pstart; } public function getId() { return $this->id; } public function getExitstatus() { return $this->exitstatus; } public function getPid() { return $this->pid; } public function getUser() { return $this->user; } public function getNode() { return $this->node; } public function getUpid() { return $this->upid; } public function getType() { return $this->type; } public function getStatus() { return $this->status; } public function isRunning() { return $this->status === "running"; } public function isFalied() { return $this->exitstatus && $this->exitstatus !== "OK"; } public function isDone() { return $this->exitstatus === "OK"; } public function setStarttime($starttime) { $this->starttime = $starttime; return $this; } public function setPstart($pstart) { $this->pstart = $pstart; return $this; } public function setId($id) { $this->id = $id; return $this; } public function setExitstatus($exitstatus) { $this->exitstatus = $exitstatus; return $this; } public function setPid($pid) { $this->pid = $pid; return $this; } public function setUser($user) { $this->user = $user; return $this; } public function setNode($node) { $this->node = $node; return $this; } public function setUpid($upid) { $this->upid = $upid; return $this; } public function setType($type) { $this->type = $type; return $this; } public function setStatus($status) { $this->status = $status; return $this; } public function getEndtime() { return $this->endtime; } public function setEndtime($endtime) { $this->endtime = $endtime; return $this; } public function getStartDate() { return date('Y-m-d H:i:s', $this->starttime); } public function getEndDate() { return date('Y-m-d H:i:s', $this->endtime); } public function setPath($path) { if (!preg_match('/\/tasks\//', $path)) { throw new proxmox\ProxmoxApiException(sprintf("Task Path ('%s') is not valid", $path)); } $this->path = $path; } public function delete() { if (empty($this->path)) throw new proxmox\ProxmoxApiException('Task [path] - property is missing and it is not optional'); return $this->api()->delete($this->path); } public function description() { return ucwords(str_replace(array("vz", "qm"), array("VM {$this->getId()} - ", "CT {$this->getId()} - "), $this->getType())); } public function getAttributes(){ return [ "id" => $this->getId(), "starttime" => $this->getStarttime(), "endtime" => $this->getEndtime(), "pstart" => $this->getPstart(), "exitstatus" => $this->getExitstatus(), "pid" => $this->getPid(), "node" => $this->getNode(), "upid"=> $this->getUpid(), "type" => $this->getType(), "status" => $this->getStatus(), ]; } }