Snapshot.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <?php
  2. /* * ********************************************************************
  3. * proxmoxCloud product developed. (2017-01-20)
  4. * *
  5. *
  6. * CREATED BY MODULESGARDEN -> http://modulesgarden.com
  7. * CONTACT -> contact@modulesgarden.com
  8. *
  9. *
  10. * This software is furnished under a license and may be used and copied
  11. * only in accordance with the terms of such license and with the
  12. * inclusion of the above copyright notice. This software or any other
  13. * copies thereof may not be provided or otherwise made available to any
  14. * other person. No title to and ownership of the software is hereby
  15. * transferred.
  16. *
  17. *
  18. * ******************************************************************** */
  19. namespace MGProvision\Proxmox\v2\models;
  20. use MGProvision\Proxmox\v2 as proxmox;
  21. /**
  22. * Description of Snapshot
  23. *
  24. * @author Pawel Kopec <pawelk@modulesgarden.com>
  25. * @version 1.0.0
  26. */
  27. class Snapshot extends AbstractObject
  28. {
  29. private $path;
  30. protected $name;
  31. protected $description;
  32. protected $snaptime;
  33. protected $parent;
  34. protected $vmstate;
  35. public function getName()
  36. {
  37. return $this->name;
  38. }
  39. public function getDescription()
  40. {
  41. return $this->description;
  42. }
  43. public function getSnaptime()
  44. {
  45. return $this->snaptime;
  46. }
  47. public function getParent()
  48. {
  49. return $this->parent;
  50. }
  51. public function setName($name)
  52. {
  53. $this->name = $name;
  54. return $this;
  55. }
  56. public function setDescription($description)
  57. {
  58. $this->description = $description;
  59. return $this;
  60. }
  61. public function setSnaptime($snaptime)
  62. {
  63. $this->snaptime = $snaptime;
  64. return $this;
  65. }
  66. public function setParent($parent)
  67. {
  68. $this->parent = $parent;
  69. return $this;
  70. }
  71. public function getVmstate()
  72. {
  73. return $this->vmstate;
  74. }
  75. public function setVmstate($vmstate)
  76. {
  77. $this->vmstate = $vmstate;
  78. return $this;
  79. }
  80. public function setPath($path)
  81. {
  82. if (!preg_match('/\/snapshot/', $path))
  83. {
  84. throw new proxmox\ProxmoxApiException(sprintf("Snapshot Path ('%s') is not valid", $path));
  85. }
  86. $this->path = $path;
  87. return $this;
  88. }
  89. public function create()
  90. {
  91. if (empty($this->path))
  92. throw new proxmox\ProxmoxApiException('Snapshot [path] - property is missing and it is not optional');
  93. $request = array(
  94. "snapname" => $this->getName(),
  95. "description" => $this->getDescription(),
  96. );
  97. if(!is_null($this->vmstate)){
  98. $request['vmstate'] =$this->getVmstate();
  99. }
  100. return $this->api()->post($this->path, $request);
  101. }
  102. public function update()
  103. {
  104. if (empty($this->path))
  105. throw new proxmox\ProxmoxApiException('Snapshot [path] - property is missing and it is not optional');
  106. return $this->api()->put($this->path . "/config", array("description" => $this->getDescription()));
  107. }
  108. public function rollback()
  109. {
  110. if (empty($this->path))
  111. throw new proxmox\ProxmoxApiException('Snapshot [path] - property is missing and it is not optional');
  112. return $this->api()->post($this->path . '/rollback');
  113. }
  114. public function delete()
  115. {
  116. if (empty($this->path))
  117. throw new proxmox\ProxmoxApiException('Snapshot [path] - property is missing and it is not optional');
  118. return $this->api()->delete($this->path);
  119. }
  120. public function getAttributes()
  121. {
  122. return array(
  123. "name" => $this->getName(),
  124. "date" => date("Y-m-d H:i:s", $this->snaptime),
  125. "description" => $this->getDescription(),
  126. "snaptime" => $this->getSnaptime(),
  127. "parent" => $this->getParent(),
  128. "vmstate" => $this->getVmstate(),
  129. );
  130. }
  131. }