Snapshot.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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 getPath() {
  90. return $this->path;
  91. }
  92. public function create()
  93. {
  94. if (empty($this->path))
  95. throw new proxmox\ProxmoxApiException('Snapshot [path] - property is missing and it is not optional');
  96. $request = array(
  97. "snapname" => $this->getName(),
  98. "description" => $this->getDescription(),
  99. );
  100. if(!is_null($this->vmstate)){
  101. $request['vmstate'] =$this->getVmstate();
  102. }
  103. return $this->api()->post($this->path, $request);
  104. }
  105. public function update()
  106. {
  107. if (empty($this->path))
  108. throw new proxmox\ProxmoxApiException('Snapshot [path] - property is missing and it is not optional');
  109. return $this->api()->put($this->path . "/config", array("description" => $this->getDescription()));
  110. }
  111. public function rollback()
  112. {
  113. if (empty($this->path))
  114. throw new proxmox\ProxmoxApiException('Snapshot [path] - property is missing and it is not optional');
  115. return $this->api()->post($this->path . '/rollback');
  116. }
  117. public function delete()
  118. {
  119. if (empty($this->path))
  120. throw new proxmox\ProxmoxApiException('Snapshot [path] - property is missing and it is not optional');
  121. return $this->api()->delete($this->path);
  122. }
  123. public function getAttributes()
  124. {
  125. return array(
  126. "name" => $this->getName(),
  127. "date" => date("Y-m-d H:i:s", $this->snaptime),
  128. "description" => $this->getDescription(),
  129. "snaptime" => $this->getSnaptime(),
  130. "parent" => $this->getParent(),
  131. "vmstate" => $this->getVmstate(),
  132. );
  133. }
  134. }