root il y a 4 ans
Parent
commit
3f368767f1
2 fichiers modifiés avec 41 ajouts et 62 suppressions
  1. 31 43
      v2/models/Snapshot.php
  2. 10 19
      v2/repository/SnapshotRepository.php

+ 31 - 43
v2/models/Snapshot.php

@@ -28,8 +28,7 @@ use MGProvision\Proxmox\v2 as proxmox;
  * @author Pawel Kopec <pawelk@modulesgarden.com>
  * @version 1.0.0
  */
-class Snapshot extends AbstractObject
-{
+class Snapshot extends AbstractObject {
     private $path;
     protected $name;
     protected $description;
@@ -37,78 +36,71 @@ class Snapshot extends AbstractObject
     protected $parent;
     protected $vmstate;
 
-    public function getName()
-    {
+    public function getName(){
         return $this->name;
     }
 
-    public function getDescription()
-    {
+    public function getDescription() {
         return $this->description;
     }
 
-    public function getSnaptime()
-    {
+    public function getSnaptime() {
         return $this->snaptime;
     }
 
-    public function getParent()
-    {
+    public function getParent() {
         return $this->parent;
     }
 
-    public function setName($name)
-    {
+    public function setName($name) {
         $this->name = $name;
         return $this;
     }
 
-    public function setDescription($description)
-    {
+    public function setDescription($description) {
         $this->description = $description;
         return $this;
     }
 
-    public function setSnaptime($snaptime)
-    {
+    public function setSnaptime($snaptime) {
         $this->snaptime = $snaptime;
         return $this;
     }
 
-    public function setParent($parent)
-    {
+    public function setParent($parent)  {
         $this->parent = $parent;
         return $this;
     }
 
-    public function getVmstate()
-    {
+    public function getVmstate() {
         return $this->vmstate;
     }
 
-    public function setVmstate($vmstate)
-    {
+    public function setVmstate($vmstate) {
         $this->vmstate = $vmstate;
         return $this;
     }
 
-    public function setPath($path)
-    {
+    public function setPath($path) {
 
-        if (!preg_match('/\/snapshot/', $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 getPath() {
+	return $this->path;
+    }
+    
 
-    public function create()
-    {
+    public function create()  {
 
-        if (empty($this->path))
+        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(),
@@ -119,32 +111,28 @@ class Snapshot extends AbstractObject
         return $this->api()->post($this->path, $request);
     }
 
-    public function update()
-    {
-
-        if (empty($this->path))
+    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))
+    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))
+    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()
-    {
+    public function getAttributes()  {
 
         return array(
             "name"        => $this->getName(),

+ 10 - 19
v2/repository/SnapshotRepository.php

@@ -48,8 +48,7 @@ class SnapshotRepository extends AbstractRepository
      * 
      * @param VmModel[] $vservers
      */
-    public function findByVmModel($vservers)
-    {
+    public function findByVmModel($vservers) {
 
         $nodes = array();
         foreach ($vservers as $vserver)
@@ -64,16 +63,14 @@ class SnapshotRepository extends AbstractRepository
         return $this;
     }
 
-    public function reset()
-    {
+    public function reset()  {
         parent::reset();
         $this->ignoreCurrent = false;
         $this->paths         = array();
         return $this;
     }
 
-    public function ignoreCurrent($ignoreCurrent)
-    {
+    public function ignoreCurrent($ignoreCurrent) {
         $this->ignoreCurrent = (boolean) $ignoreCurrent;
         return $this;
     }
@@ -81,8 +78,7 @@ class SnapshotRepository extends AbstractRepository
     /**
      * @return proxmox\models\SnapshotKvm
      */
-    public function getCurrent()
-    {
+    public function getCurrent()  {
         return $this->current;
     }
 
@@ -90,26 +86,20 @@ class SnapshotRepository extends AbstractRepository
      * @return proxmox\models\SnapshotKvm[]
      * @throws proxmox\ProxmoxApiException
      */
-    public function fetch()
-    {
+    public function fetch() {
 
-        if (!empty($this->fetch))
-        {
+        if (!empty($this->fetch)) {
             return $this->fetch;
         }
 
-        foreach ($this->paths as $path)
-        {
-
+        foreach ($this->paths as $path)   {
             $temp = $this->api()->get($path);
 
-            foreach ($temp as $snap)
-            {
+            foreach ($temp as $snap)   {
                 $entityObj     = new Snapshot();
                 $entityObj->setAttributes($snap);
                 $entityObj->setPath(sprintf("{$path}/%s", $snap['name']));
-                if ($this->ignoreCurrent && $snap['name'] == "current")
-                {
+                if ($this->ignoreCurrent && $snap['name'] == "current")  {
                     $this->current = $entityObj;
                     continue;
                 }
@@ -118,6 +108,7 @@ class SnapshotRepository extends AbstractRepository
         }
         return $this->fetch;
     }
+    
 
     public function sortBySnaptime(){
         $keys = [];