Snapshot.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. private $path;
  29. protected $name;
  30. protected $description;
  31. protected $snaptime;
  32. protected $parent;
  33. protected $vmstate;
  34. public function getName(){
  35. return $this->name;
  36. }
  37. public function getDescription() {
  38. return $this->description;
  39. }
  40. public function getSnaptime() {
  41. return $this->snaptime;
  42. }
  43. public function getParent() {
  44. return $this->parent;
  45. }
  46. public function setName($name) {
  47. $this->name = $name;
  48. return $this;
  49. }
  50. public function setDescription($description) {
  51. $this->description = $description;
  52. return $this;
  53. }
  54. public function setSnaptime($snaptime) {
  55. $this->snaptime = $snaptime;
  56. return $this;
  57. }
  58. public function setParent($parent) {
  59. $this->parent = $parent;
  60. return $this;
  61. }
  62. public function getVmstate() {
  63. return $this->vmstate;
  64. }
  65. public function setVmstate($vmstate) {
  66. $this->vmstate = $vmstate;
  67. return $this;
  68. }
  69. public function setPath($path) {
  70. if (!preg_match('/\/snapshot/', $path)) {
  71. throw new proxmox\ProxmoxApiException(sprintf("Snapshot Path ('%s') is not valid", $path));
  72. }
  73. $this->path = $path;
  74. return $this;
  75. }
  76. public function getPath() {
  77. return $this->path;
  78. }
  79. public function create() {
  80. if (empty($this->path)) {
  81. throw new proxmox\ProxmoxApiException('Snapshot [path] - property is missing and it is not optional');
  82. }
  83. $request = array(
  84. "snapname" => $this->getName(),
  85. "description" => $this->getDescription(),
  86. );
  87. if(!is_null($this->vmstate)){
  88. $request['vmstate'] =$this->getVmstate();
  89. }
  90. return $this->api()->post($this->path, $request);
  91. }
  92. public function update() {
  93. if (empty($this->path)) {
  94. throw new proxmox\ProxmoxApiException('Snapshot [path] - property is missing and it is not optional');
  95. }
  96. return $this->api()->put($this->path . "/config", array("description" => $this->getDescription()));
  97. }
  98. public function rollback() {
  99. if (empty($this->path)) {
  100. throw new proxmox\ProxmoxApiException('Snapshot [path] - property is missing and it is not optional');
  101. }
  102. return $this->api()->post($this->path . '/rollback');
  103. }
  104. public function delete() {
  105. if (empty($this->path)) {
  106. throw new proxmox\ProxmoxApiException('Snapshot [path] - property is missing and it is not optional');
  107. }
  108. return $this->api()->delete($this->path);
  109. }
  110. public function getAttributes() {
  111. return array(
  112. "name" => $this->getName(),
  113. "date" => date("Y-m-d H:i:s", $this->snaptime),
  114. "description" => $this->getDescription(),
  115. "snaptime" => $this->getSnaptime(),
  116. "parent" => $this->getParent(),
  117. "vmstate" => $this->getVmstate(),
  118. );
  119. }
  120. }