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; use MGProvision\Proxmox\v2 as proxmox; /** * Description of Snapshot * * @author Pawel Kopec * @version 1.0.0 */ class Snapshot extends AbstractObject { private $path; protected $name; protected $description; protected $snaptime; protected $parent; protected $vmstate; public function getName() { return $this->name; } public function getDescription() { return $this->description; } public function getSnaptime() { return $this->snaptime; } public function getParent() { return $this->parent; } public function setName($name) { $this->name = $name; return $this; } public function setDescription($description) { $this->description = $description; return $this; } public function setSnaptime($snaptime) { $this->snaptime = $snaptime; return $this; } public function setParent($parent) { $this->parent = $parent; return $this; } public function getVmstate() { return $this->vmstate; } public function setVmstate($vmstate) { $this->vmstate = $vmstate; return $this; } public function setPath($path) { if (!preg_match('/\/snapshot/', $path)) { throw new proxmox\ProxmoxApiException(sprintf("Snapshot Path ('%s') is not valid", $path)); } $this->path = $path; return $this; } public function create() { if (empty($this->path)) throw new proxmox\ProxmoxApiException('Snapshot [path] - property is missing and it is not optional'); $request = array( "snapname" => $this->getName(), "description" => $this->getDescription(), ); if(!is_null($this->vmstate)){ $request['vmstate'] =$this->getVmstate(); } return $this->api()->post($this->path, $request); } public function update() { if (empty($this->path)) throw new proxmox\ProxmoxApiException('Snapshot [path] - property is missing and it is not optional'); return $this->api()->put($this->path . "/config", array("description" => $this->getDescription())); } public function rollback() { if (empty($this->path)) throw new proxmox\ProxmoxApiException('Snapshot [path] - property is missing and it is not optional'); return $this->api()->post($this->path . '/rollback'); } public function delete() { if (empty($this->path)) throw new proxmox\ProxmoxApiException('Snapshot [path] - property is missing and it is not optional'); return $this->api()->delete($this->path); } public function getAttributes() { return array( "name" => $this->getName(), "date" => date("Y-m-d H:i:s", $this->snaptime), "description" => $this->getDescription(), "snaptime" => $this->getSnaptime(), "parent" => $this->getParent(), "vmstate" => $this->getVmstate(), ); } }